swift/bin/swift-config
Monty Taylor 5a785aa5ee Add missing copyright license headers
We're working on adding enforcement that things have appropriate
copyright license headers. In anticipation of that, fix the files that don't
have them.

Change-Id: Ie0a9fd5eece5b6671ff4389b07b69ca29be7d017
2013-08-07 17:50:32 -03:00

71 lines
2.4 KiB
Python
Executable File

#!/usr/bin/env python
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import optparse
import os
import sys
from swift.common.manager import Server
from swift.common.utils import readconf
from swift.common.wsgi import appconfig
parser = optparse.OptionParser('%prog [options] SERVER')
parser.add_option('-c', '--config-num', metavar="N", type="int",
dest="number", default=0,
help="parse config for the Nth server only")
parser.add_option('-s', '--section', help="only display matching sections")
parser.add_option('-w', '--wsgi', action='store_true',
help="use wsgi/paste parser instead of readconf")
def main():
options, args = parser.parse_args()
options = dict(vars(options))
if not args:
return 'ERROR: specify type of server or conf_path'
conf_files = []
for arg in args:
if os.path.exists(arg):
conf_files.append(arg)
else:
conf_files += Server(arg).conf_files(**options)
for conf_file in conf_files:
print '# %s' % conf_file
if options['wsgi']:
app_config = appconfig(conf_file)
context = app_config.context
conf = dict([(c.name, c.config()) for c in getattr(
context, 'filter_contexts', [])])
conf[context.name] = app_config
else:
conf = readconf(conf_file)
flat_vars = {}
for k, v in conf.items():
if options['section'] and k != options['section']:
continue
if not isinstance(v, dict):
flat_vars[k] = v
continue
print '[%s]' % k
for opt, value in v.items():
print '%s = %s' % (opt, value)
print
for k, v in flat_vars.items():
print '# %s = %s' % (k, v)
print
if __name__ == "__main__":
sys.exit(main())