main: Start unifying command handling
- Removes show_deps and show_config from commands module. These are now handled directly in the main() method pending subcommands. - Unifies show_config with general main() config handling. - Sets default verbosity level to zero. - Reduce verbosity when --show-config or --show-deps is called. - Update console logging to consider verbosity < 0 quiet/
This commit is contained in:
parent
51b778fcd6
commit
f49973304c
@ -21,7 +21,7 @@ from mopidy import commands, ext
|
||||
from mopidy.audio import Audio
|
||||
from mopidy import config as config_lib
|
||||
from mopidy.core import Core
|
||||
from mopidy.utils import log, path, process
|
||||
from mopidy.utils import deps, log, path, process
|
||||
|
||||
logger = logging.getLogger('mopidy.main')
|
||||
|
||||
@ -33,10 +33,8 @@ def main():
|
||||
parser = commands.build_parser()
|
||||
args = parser.parse_args(args=mopidy_args)
|
||||
|
||||
if args.show_config:
|
||||
commands.show_config(args)
|
||||
if args.show_deps:
|
||||
commands.show_deps()
|
||||
if args.show_deps or args.show_config:
|
||||
args.verbosity_level -= 1
|
||||
|
||||
bootstrap_logging(args)
|
||||
|
||||
@ -45,20 +43,40 @@ def main():
|
||||
check_old_locations()
|
||||
|
||||
installed_extensions = ext.load_extensions()
|
||||
|
||||
config, config_errors = config_lib.load(
|
||||
args.config_files, installed_extensions, args.config_overrides)
|
||||
|
||||
# Filter out disabled extensions and remove any config errors for them.
|
||||
enabled_extensions = []
|
||||
for extension in installed_extensions:
|
||||
enabled = config[extension.ext_name]['enabled']
|
||||
if ext.validate_extension(extension) and enabled:
|
||||
if not ext.validate_extension(extension):
|
||||
config[extension.ext_name] = {b'enabled': False}
|
||||
config_errors[extension.ext_name] = {
|
||||
b'enabled': b'extension disabled by self check.'}
|
||||
elif not config[extension.ext_name]['enabled']:
|
||||
config[extension.ext_name] = {b'enabled': False}
|
||||
config_errors[extension.ext_name] = {
|
||||
b'enabled': b'extension disabled by user config.'}
|
||||
else:
|
||||
enabled_extensions.append(extension)
|
||||
elif extension.ext_name in config_errors:
|
||||
del config_errors[extension.ext_name]
|
||||
|
||||
log_extension_info(installed_extensions, enabled_extensions)
|
||||
|
||||
# TODO: move to 'mopidy config' and 'mopidy deps'
|
||||
if args.show_config:
|
||||
logger.info('Dumping sanitized user config and exiting.')
|
||||
print config_lib.format(
|
||||
config, installed_extensions, config_errors)
|
||||
sys.exit(0)
|
||||
if args.show_deps:
|
||||
logger.info('Dumping debug info about dependencies and exiting.')
|
||||
print deps.format_dependency_list()
|
||||
sys.exit(0)
|
||||
|
||||
# Remove errors for extensions that are not enabled:
|
||||
for extension in installed_extensions:
|
||||
if extension not in enabled_extensions:
|
||||
config_errors.pop(extension.ext_name, None)
|
||||
|
||||
check_config_errors(config_errors)
|
||||
|
||||
# Read-only config from here on, please.
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from mopidy import config as config_lib, ext
|
||||
from mopidy.utils import deps, versioning
|
||||
from mopidy.utils import versioning
|
||||
|
||||
|
||||
def config_files_type(value):
|
||||
@ -23,6 +21,7 @@ def config_override_type(value):
|
||||
|
||||
def build_parser():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.set_defaults(verbosity_level=0)
|
||||
parser.add_argument(
|
||||
'--version', action='version',
|
||||
version='Mopidy %s' % versioning.get_version())
|
||||
@ -57,30 +56,3 @@ def build_parser():
|
||||
help='`section/key=value` values to override config options')
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
def show_config(args):
|
||||
"""Prints the effective config and exits."""
|
||||
extensions = ext.load_extensions()
|
||||
config, errors = config_lib.load(
|
||||
args.config_files, extensions, args.config_overrides)
|
||||
|
||||
# Clear out any config for disabled extensions.
|
||||
for extension in extensions:
|
||||
if not ext.validate_extension(extension):
|
||||
config[extension.ext_name] = {b'enabled': False}
|
||||
errors[extension.ext_name] = {
|
||||
b'enabled': b'extension disabled itself.'}
|
||||
elif not config[extension.ext_name]['enabled']:
|
||||
config[extension.ext_name] = {b'enabled': False}
|
||||
errors[extension.ext_name] = {
|
||||
b'enabled': b'extension disabled by config.'}
|
||||
|
||||
print config_lib.format(config, extensions, errors)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def show_deps():
|
||||
"""Prints a list of all dependencies and exits."""
|
||||
print deps.format_dependency_list()
|
||||
sys.exit(0)
|
||||
|
||||
@ -34,7 +34,7 @@ def setup_root_logger():
|
||||
|
||||
|
||||
def setup_console_logging(config, verbosity_level):
|
||||
if verbosity_level == -1:
|
||||
if verbosity_level < 0:
|
||||
log_level = logging.WARNING
|
||||
log_format = config['logging']['console_format']
|
||||
elif verbosity_level >= 1:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user