config: Add config based list_settings_callback
This commit is contained in:
parent
29a4ff040e
commit
77cdb5b065
@ -113,7 +113,7 @@ def parse_options():
|
||||
parser.add_option(
|
||||
b'--list-settings',
|
||||
action='callback',
|
||||
callback=settings_utils.list_settings_optparse_callback,
|
||||
callback=list_settings_callback,
|
||||
help='list current settings')
|
||||
parser.add_option(
|
||||
b'--list-deps',
|
||||
@ -126,6 +126,25 @@ def parse_options():
|
||||
return parser.parse_args(args=mopidy_args)[0]
|
||||
|
||||
|
||||
def list_settings_callback(options, opt, value, parser):
|
||||
extensions = load_extensions()
|
||||
raw_config = load_config(options, extensions)
|
||||
extensions = filter_enabled_extensions(raw_config, extensions)
|
||||
config = validate_config(raw_config, extensions)
|
||||
|
||||
# TODO: this code is duplicated, figure out a way to reuse it?
|
||||
sections_and_schemas = config_schemas.items()
|
||||
for extension in extensions:
|
||||
sections_and_schemas.append(
|
||||
(extension.ext_name, extension.get_config_schema()))
|
||||
|
||||
output = ['# Settings for disabled extensions are not shown.']
|
||||
for section_name, schema in sections_and_schemas:
|
||||
output.append(schema.format(section_name, config.get(section_name, {})))
|
||||
print '\n\n'.join(output)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def check_old_folders():
|
||||
# TODO: add old settings and pre extension storage locations?
|
||||
old_settings_folder = os.path.expanduser('~/.mopidy')
|
||||
|
||||
@ -157,7 +157,7 @@ class List(ConfigValue):
|
||||
return tuple([v for v in values if v])
|
||||
|
||||
def serialize(self, value):
|
||||
return '\n '.join(v.encode('utf-8') for v in value)
|
||||
return '\n ' + '\n '.join(v.encode('utf-8') for v in value)
|
||||
|
||||
|
||||
class LogLevel(ConfigValue):
|
||||
@ -270,10 +270,6 @@ class ExtensionConfigSchema(ConfigSchema):
|
||||
super(ExtensionConfigSchema, self).__init__()
|
||||
self['enabled'] = Boolean()
|
||||
|
||||
def format(self, name, values):
|
||||
return super(ExtensionConfigSchema, self).format(
|
||||
'ext.%s' % name, values)
|
||||
|
||||
|
||||
class LogLevelConfigSchema(object):
|
||||
"""Special cased schema for handling a config section with loglevels.
|
||||
|
||||
@ -376,10 +376,6 @@ class ExtensionConfigSchemaTest(unittest.TestCase):
|
||||
schema = config.ExtensionConfigSchema()
|
||||
self.assertIsInstance(schema['enabled'], config.Boolean)
|
||||
|
||||
def test_section_name_is_prefixed(self):
|
||||
schema = config.ExtensionConfigSchema()
|
||||
self.assertEqual('[ext.foo]', schema.format('foo', {}))
|
||||
|
||||
|
||||
class LogLevelConfigSchemaTest(unittest.TestCase):
|
||||
def test_conversion(self):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user