예제 #1
0
파일: commands.py 프로젝트: HaBaLeS/mopidy
 def __init__(self):
     super(RootCommand, self).__init__()
     self.set(base_verbosity_level=0)
     self.add_argument(
         '-h', '--help',
         action='help', help='Show this message and exit')
     self.add_argument(
         '--version', action='version',
         version='Mopidy %s' % versioning.get_version())
     self.add_argument(
         '-q', '--quiet',
         action='store_const', const=-1, dest='verbosity_level',
         help='less output (warning level)')
     self.add_argument(
         '-v', '--verbose',
         action='count', dest='verbosity_level', default=0,
         help='more output (repeat up to 3 times for even more)')
     self.add_argument(
         '--save-debug-log',
         action='store_true', dest='save_debug_log',
         help='save debug log to "./mopidy.log"')
     self.add_argument(
         '--config',
         action='store', dest='config_files', type=config_files_type,
         default=DEFAULT_CONFIG, metavar='FILES',
         help='config files to use, colon seperated, later files override')
     self.add_argument(
         '-o', '--option',
         action='append', dest='config_overrides',
         type=config_override_type, metavar='OPTIONS',
         help='`section/key=value` values to override config options')
예제 #2
0
def format_initial(extensions_data):
    config_dir = os.path.dirname(__file__)
    defaults = [read(os.path.join(config_dir, 'default.conf'))]
    defaults.extend(d.extension.get_default_config() for d in extensions_data)
    raw_config = _load([], defaults, [])

    schemas = _schemas[:]
    schemas.extend(d.extension.get_config_schema() for d in extensions_data)

    config, errors = _validate(raw_config, schemas)

    versions = ['Mopidy %s' % versioning.get_version()]
    extensions_data = sorted(extensions_data,
                             key=lambda d: d.extension.dist_name)
    for data in extensions_data:
        versions.append('%s %s' %
                        (data.extension.dist_name, data.extension.version))

    header = _INITIAL_HELP.strip() % {'versions': '\n#   '.join(versions)}
    formatted_config = _format(config=config,
                               comments={},
                               schemas=schemas,
                               display=False,
                               disable=True).decode('utf-8')
    return header + '\n\n' + formatted_config
예제 #3
0
 def __init__(self):
     super(RootCommand, self).__init__()
     self.set(base_verbosity_level=0)
     self.add_argument('-h',
                       '--help',
                       action='help',
                       help='Show this message and exit')
     self.add_argument('--version',
                       action='version',
                       version='Mopidy %s' % versioning.get_version())
     self.add_argument('-q',
                       '--quiet',
                       action='store_const',
                       const=-1,
                       dest='verbosity_level',
                       help='less output (warning level)')
     self.add_argument(
         '-v',
         '--verbose',
         action='count',
         dest='verbosity_level',
         default=0,
         help='more output (repeat up to 3 times for even more)')
     self.add_argument('--save-debug-log',
                       action='store_true',
                       dest='save_debug_log',
                       help='save debug log to "./mopidy.log"')
     self.add_argument(
         '--config',
         action='store',
         dest='config_files',
         type=config_files_type,
         default=DEFAULT_CONFIG,
         metavar='FILES',
         help='config files to use, colon seperated, later files override')
     self.add_argument(
         '-o',
         '--option',
         action='append',
         dest='config_overrides',
         type=config_override_type,
         metavar='OPTIONS',
         help='`section/key=value` values to override config options')
예제 #4
0
파일: __init__.py 프로젝트: HaBaLeS/mopidy
def format_initial(extensions_data):
    config_dir = os.path.dirname(__file__)
    defaults = [read(os.path.join(config_dir, "default.conf"))]
    defaults.extend(d.extension.get_default_config() for d in extensions_data)
    raw_config = _load([], defaults, [])

    schemas = _schemas[:]
    schemas.extend(d.extension.get_config_schema() for d in extensions_data)

    config, errors = _validate(raw_config, schemas)

    versions = ["Mopidy %s" % versioning.get_version()]
    extensions_data = sorted(extensions_data, key=lambda d: d.extension.dist_name)
    for data in extensions_data:
        versions.append("%s %s" % (data.extension.dist_name, data.extension.version))

    header = _INITIAL_HELP.strip() % {"versions": "\n#   ".join(versions)}
    formatted_config = _format(config=config, comments={}, schemas=schemas, display=False, disable=True).decode("utf-8")
    return header + "\n\n" + formatted_config
예제 #5
0
 def test_version(self):
     self.assertEqual(self.core.version, versioning.get_version())
예제 #6
0
def main():
    log.bootstrap_delayed_logging()
    logger.info("Starting Mopidy %s", versioning.get_version())

    signal.signal(signal.SIGTERM, process.sigterm_handler)
    # Windows does not have signal.SIGUSR1
    if hasattr(signal, "SIGUSR1"):
        signal.signal(signal.SIGUSR1, pykka.debug.log_thread_tracebacks)

    try:
        registry = ext.Registry()

        root_cmd = commands.RootCommand()
        config_cmd = commands.ConfigCommand()
        deps_cmd = commands.DepsCommand()

        root_cmd.set(extension=None, registry=registry)
        root_cmd.add_child("config", config_cmd)
        root_cmd.add_child("deps", deps_cmd)

        extensions_data = ext.load_extensions()

        for data in extensions_data:
            if data.command:  # TODO: check isinstance?
                data.command.set(extension=data.extension)
                root_cmd.add_child(data.extension.ext_name, data.command)

        args = root_cmd.parse(sys.argv[1:])

        config, config_errors = config_lib.load(
            args.config_files,
            [d.config_schema for d in extensions_data],
            [d.config_defaults for d in extensions_data],
            args.config_overrides,
        )

        create_core_dirs(config)
        create_initial_config_file(args, extensions_data)

        verbosity_level = args.base_verbosity_level
        if args.verbosity_level:
            verbosity_level += args.verbosity_level

        log.setup_logging(config, verbosity_level, args.save_debug_log)

        extensions = {"validate": [], "config": [], "disabled": [], "enabled": []}
        for data in extensions_data:
            extension = data.extension

            # TODO: factor out all of this to a helper that can be tested
            if not ext.validate_extension_data(data):
                config[extension.ext_name] = {"enabled": False}
                config_errors[extension.ext_name] = {"enabled": "extension disabled by self check."}
                extensions["validate"].append(extension)
            elif not config[extension.ext_name]["enabled"]:
                config[extension.ext_name] = {"enabled": False}
                config_errors[extension.ext_name] = {"enabled": "extension disabled by user config."}
                extensions["disabled"].append(extension)
            elif config_errors.get(extension.ext_name):
                config[extension.ext_name]["enabled"] = False
                config_errors[extension.ext_name]["enabled"] = "extension disabled due to config errors."
                extensions["config"].append(extension)
            else:
                extensions["enabled"].append(extension)

        log_extension_info([d.extension for d in extensions_data], extensions["enabled"])

        # Config and deps commands are simply special cased for now.
        if args.command == config_cmd:
            schemas = [d.config_schema for d in extensions_data]
            return args.command.run(config, config_errors, schemas)
        elif args.command == deps_cmd:
            return args.command.run()

        check_config_errors(config, config_errors, extensions)

        if not extensions["enabled"]:
            logger.error("No extension enabled, exiting...")
            sys.exit(1)

        # Read-only config from here on, please.
        proxied_config = config_lib.Proxy(config)

        if args.extension and args.extension not in extensions["enabled"]:
            logger.error("Unable to run command provided by disabled extension %s", args.extension.ext_name)
            return 1

        for extension in extensions["enabled"]:
            try:
                extension.setup(registry)
            except Exception:
                # TODO: would be nice a transactional registry. But sadly this
                # is a bit tricky since our current API is giving out a mutable
                # list. We might however be able to replace this with a
                # collections.Sequence to provide a RO view.
                logger.exception(
                    "Extension %s failed during setup, this might" " have left the registry in a bad state.",
                    extension.ext_name,
                )

        # Anything that wants to exit after this point must use
        # mopidy.internal.process.exit_process as actors can have been started.
        try:
            return args.command.run(args, proxied_config)
        except NotImplementedError:
            print(root_cmd.format_help())
            return 1

    except KeyboardInterrupt:
        pass
    except Exception as ex:
        logger.exception(ex)
        raise
예제 #7
0
 def test_version(self):
     self.assertEqual(self.core.version, versioning.get_version())
예제 #8
0
파일: conf.py 프로젝트: tmaone/mopidy
extensions = [
    "sphinx.ext.autodoc",
    "sphinx.ext.extlinks",
    "sphinx.ext.graphviz",
    "sphinx.ext.intersphinx",
    "sphinx.ext.viewcode",
]

templates_path = ["_templates"]
source_suffix = ".rst"
master_doc = "index"

project = "Mopidy"
copyright = "2009-2019, Stein Magnus Jodal and contributors"

release = get_version()
version = ".".join(release.split(".")[:2])

# To make the build reproducible, avoid using today's date in the manpages
today = "2019"

exclude_trees = ["_build"]

pygments_style = "sphinx"

modindex_common_prefix = ["mopidy."]

# -- Options for HTML output --------------------------------------------------

html_theme = "sphinx_rtd_theme"
html_static_path = ["_static"]
예제 #9
0
 def get_version(self):
     """Get version of the Mopidy core API"""
     return versioning.get_version()
예제 #10
0
파일: conf.py 프로젝트: mopidy/mopidy
    'sphinx.ext.autodoc',
    'sphinx.ext.extlinks',
    'sphinx.ext.graphviz',
    'sphinx.ext.intersphinx',
    'sphinx.ext.viewcode',
]

templates_path = ['_templates']
source_suffix = '.rst'
master_doc = 'index'

project = 'Mopidy'
copyright = '2009-2018, Stein Magnus Jodal and contributors'

from mopidy.internal.versioning import get_version
release = get_version()
version = '.'.join(release.split('.')[:2])

# To make the build reproducible, avoid using today's date in the manpages
today = '2018'

exclude_trees = ['_build']

pygments_style = 'sphinx'

modindex_common_prefix = ['mopidy.']


# -- Options for HTML output --------------------------------------------------

html_theme = 'sphinx_rtd_theme'
예제 #11
0
def main():
    log.bootstrap_delayed_logging()
    logger.info('Starting Mopidy %s', versioning.get_version())

    signal.signal(signal.SIGTERM, process.exit_handler)
    # Windows does not have signal.SIGUSR1
    if hasattr(signal, 'SIGUSR1'):
        signal.signal(signal.SIGUSR1, pykka.debug.log_thread_tracebacks)

    try:
        registry = ext.Registry()

        root_cmd = commands.RootCommand()
        config_cmd = commands.ConfigCommand()
        deps_cmd = commands.DepsCommand()

        root_cmd.set(extension=None, registry=registry)
        root_cmd.add_child('config', config_cmd)
        root_cmd.add_child('deps', deps_cmd)

        extensions_data = ext.load_extensions()

        for data in extensions_data:
            if data.command:  # TODO: check isinstance?
                data.command.set(extension=data.extension)
                root_cmd.add_child(data.extension.ext_name, data.command)

        args = root_cmd.parse(mopidy_args)

        create_file_structures_and_config(args, extensions_data)
        check_old_locations()

        config, config_errors = config_lib.load(
            args.config_files, [d.config_schema for d in extensions_data],
            [d.config_defaults
             for d in extensions_data], args.config_overrides)

        verbosity_level = args.base_verbosity_level
        if args.verbosity_level:
            verbosity_level += args.verbosity_level

        log.setup_logging(config, verbosity_level, args.save_debug_log)

        extensions = {
            'validate': [],
            'config': [],
            'disabled': [],
            'enabled': []
        }
        for data in extensions_data:
            extension = data.extension

            # TODO: factor out all of this to a helper that can be tested
            if not ext.validate_extension_data(data):
                config[extension.ext_name] = {'enabled': False}
                config_errors[extension.ext_name] = {
                    'enabled': 'extension disabled by self check.'
                }
                extensions['validate'].append(extension)
            elif not config[extension.ext_name]['enabled']:
                config[extension.ext_name] = {'enabled': False}
                config_errors[extension.ext_name] = {
                    'enabled': 'extension disabled by user config.'
                }
                extensions['disabled'].append(extension)
            elif config_errors.get(extension.ext_name):
                config[extension.ext_name]['enabled'] = False
                config_errors[extension.ext_name]['enabled'] = (
                    'extension disabled due to config errors.')
                extensions['config'].append(extension)
            else:
                extensions['enabled'].append(extension)

        log_extension_info([d.extension for d in extensions_data],
                           extensions['enabled'])

        # Config and deps commands are simply special cased for now.
        if args.command == config_cmd:
            schemas = [d.config_schema for d in extensions_data]
            return args.command.run(config, config_errors, schemas)
        elif args.command == deps_cmd:
            return args.command.run()

        check_config_errors(config, config_errors, extensions)

        if not extensions['enabled']:
            logger.error('No extension enabled, exiting...')
            sys.exit(1)

        # Read-only config from here on, please.
        proxied_config = config_lib.Proxy(config)

        if args.extension and args.extension not in extensions['enabled']:
            logger.error(
                'Unable to run command provided by disabled extension %s',
                args.extension.ext_name)
            return 1

        for extension in extensions['enabled']:
            try:
                extension.setup(registry)
            except Exception:
                # TODO: would be nice a transactional registry. But sadly this
                # is a bit tricky since our current API is giving out a mutable
                # list. We might however be able to replace this with a
                # collections.Sequence to provide a RO view.
                logger.exception(
                    'Extension %s failed during setup, this might'
                    ' have left the registry in a bad state.',
                    extension.ext_name)

        # Anything that wants to exit after this point must use
        # mopidy.internal.process.exit_process as actors can have been started.
        try:
            return args.command.run(args, proxied_config)
        except NotImplementedError:
            print(root_cmd.format_help())
            return 1

    except KeyboardInterrupt:
        pass
    except Exception as ex:
        logger.exception(ex)
        raise
예제 #12
0
파일: actor.py 프로젝트: bencevans/mopidy
 def get_version(self):
     """Get version of the Mopidy core API"""
     return versioning.get_version()
예제 #13
0
 def test_version(self):
     assert self.core.get_version() == versioning.get_version()