def _configure(options): """Amend the global configuration object with command line options. """ # Add any additional config files specified with --config. This # special handling lets specified plugins get loaded before we # finish parsing the command line. if getattr(options, 'config', None) is not None: config_path = options.config del options.config config.set_file(config_path) config.set_args(options) # Configure the logger. if config['verbose'].get(bool): log.setLevel(logging.DEBUG) else: log.setLevel(logging.INFO) config_path = config.user_config_path() if os.path.isfile(config_path): log.debug('user configuration: {0}'.format( util.displayable_path(config_path))) else: log.debug('no user configuration found at {0}'.format( util.displayable_path(config_path))) log.debug(u'data directory: {0}' .format(util.displayable_path(config.config_dir()))) return config
def _configure(args): """Parse the command line, load configuration files (including loading any indicated plugins), and return the invoked subcomand, the subcommand options, and the subcommand arguments. """ # Temporary: Migrate from 1.0-style configuration. from beets.ui import migrate migrate.automigrate() # Get the default subcommands. from beets.ui.commands import default_commands # Construct the root parser. parser = SubcommandsOptionParser() parser.add_option('-l', '--library', dest='library', help='library database file to use') parser.add_option('-d', '--directory', dest='directory', help="destination music directory") parser.add_option('-v', '--verbose', dest='verbose', action='store_true', help='print debugging information') parser.add_option('-c', '--config', dest='config', help='path to configuration file') # Parse the command-line! options, subargs = parser.parse_global_options(args) # Add any additional config files specified with --config. This # special handling lets specified plugins get loaded before we # finish parsing the command line. if getattr(options, 'config', None) is not None: config_path = options.config del options.config config.set_file(config_path) config.set_args(options) # Configure the logger. if config['verbose'].get(bool): log.setLevel(logging.DEBUG) else: log.setLevel(logging.INFO) config_path = config.user_config_path() if os.path.isfile(config_path): log.debug('user configuration: {0}'.format( util.displayable_path(config_path))) else: log.debug('no user configuration found at {0}'.format( util.displayable_path(config_path))) # Add builtin subcommands parser.add_subcommand(*default_commands) parser.add_subcommand(migrate.migrate_cmd) # Now add the plugin commands to the parser. _load_plugins() for cmd in plugins.commands(): parser.add_subcommand(cmd) # Parse the remainder of the command line with loaded plugins. return parser.parse_subcommand(subargs)
def _configure(options): """Amend the global configuration object with command line options. """ # Add any additional config files specified with --config. This # special handling lets specified plugins get loaded before we # finish parsing the command line. if getattr(options, 'config', None) is not None: overlay_path = options.config del options.config config.set_file(overlay_path) else: overlay_path = None config.set_args(options) # Configure the logger. if config['verbose'].get(int): log.set_global_level(logging.DEBUG) else: log.set_global_level(logging.INFO) if overlay_path: log.debug(u'overlaying configuration: {0}', util.displayable_path(overlay_path)) config_path = config.user_config_path() if os.path.isfile(config_path): log.debug(u'user configuration: {0}', util.displayable_path(config_path)) else: log.debug(u'no user configuration found at {0}', util.displayable_path(config_path)) log.debug(u'data directory: {0}', util.displayable_path(config.config_dir())) return config
def _configure(args): """Parse the command line, load configuration files (including loading any indicated plugins), and return the invoked subcomand, the subcommand options, and the subcommand arguments. """ # Temporary: Migrate from 1.0-style configuration. from beets.ui import migrate migrate.automigrate() # Get the default subcommands. from beets.ui.commands import default_commands # Construct the root parser. commands = list(default_commands) commands.append(migrate.migrate_cmd) # Temporary. parser = SubcommandsOptionParser(subcommands=commands) parser.add_option('-l', '--library', dest='library', help='library database file to use') parser.add_option('-d', '--directory', dest='directory', help="destination music directory") parser.add_option('-v', '--verbose', dest='verbose', action='store_true', help='print debugging information') parser.add_option('-c', '--config', dest='config', help='path to configuration file') # Parse the command-line! options, args = optparse.OptionParser.parse_args(parser, args) # Add any additional config files specified with --config. This # special handling lets specified plugins get loaded before we # finish parsing the command line. if getattr(options, 'config', None) is not None: config_path = options.config del options.config config.set_file(config_path) config.set_args(options) # Configure the logger. if config['verbose'].get(bool): log.setLevel(logging.DEBUG) else: log.setLevel(logging.INFO) config_path = config.user_config_path() if os.path.isfile(config_path): log.debug('user configuration: {0}'.format( util.displayable_path(config_path))) else: log.debug('no user configuration found at {0}'.format( util.displayable_path(config_path))) # Now add the plugin commands to the parser. _load_plugins() for cmd in plugins.commands(): parser.add_subcommand(cmd) # Parse the remainder of the command line with loaded plugins. return parser._parse_sub(args)
def _configure(args): """Parse the command line, load configuration files (including loading any indicated plugins), and return the invoked subcomand, the subcommand options, and the subcommand arguments. """ # Temporary: Migrate from 1.0-style configuration. from beets.ui import migrate migrate.automigrate() # Get the default subcommands. from beets.ui.commands import default_commands # Construct the root parser. commands = list(default_commands) commands.append(migrate.migrate_cmd) # Temporary. parser = SubcommandsOptionParser(subcommands=commands) parser.add_option("-l", "--library", dest="library", help="library database file to use") parser.add_option("-d", "--directory", dest="directory", help="destination music directory") parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="print debugging information") parser.add_option("-c", "--config", dest="config", help="path to configuration file") # Parse the command-line! options, args = optparse.OptionParser.parse_args(parser, args) # Add any additional config files specified with --config. This # special handling lets specified plugins get loaded before we # finish parsing the command line. if getattr(options, "config", None) is not None: config_path = options.config del options.config config.set_file(config_path) config.set_args(options) # Configure the logger. if config["verbose"].get(bool): log.setLevel(logging.DEBUG) else: log.setLevel(logging.INFO) config_path = config.user_config_path() if os.path.isfile(config_path): log.debug("user configuration: {0}".format(util.displayable_path(config_path))) else: log.debug("no user configuration found at {0}".format(util.displayable_path(config_path))) # Now add the plugin commands to the parser. _load_plugins() for cmd in plugins.commands(): parser.add_subcommand(cmd) # Parse the remainder of the command line with loaded plugins. return parser._parse_sub(args)
def _configure(options): """Amend the global configuration object with command line options. """ # Add any additional config files specified with --config. This # special handling lets specified plugins get loaded before we # finish parsing the command line. if getattr(options, b'config', None) is not None: config_path = options.config del options.config config.set_file(config_path) config.set_args(options) # Configure the logger. if config['verbose'].get(int): log.set_global_level(logging.DEBUG) else: log.set_global_level(logging.INFO) # Ensure compatibility with old (top-level) color configuration. # Deprecation msg to motivate user to switch to config['ui']['color]. if config['color'].exists(): log.warning(u'Warning: top-level configuration of `color` ' u'is deprecated. Configure color use under `ui`. ' u'See documentation for more info.') config['ui']['color'].set(config['color'].get(bool)) # Compatibility from list_format_{item,album} to format_{item,album} for elem in ('item', 'album'): old_key = 'list_format_{0}'.format(elem) if config[old_key].exists(): new_key = 'format_{0}'.format(elem) log.warning( u'Warning: configuration uses "{0}" which is deprecated' u' in favor of "{1}" now that it affects all commands. ' u'See changelog & documentation.', old_key, new_key, ) config[new_key].set(config[old_key]) config_path = config.user_config_path() if os.path.isfile(config_path): log.debug(u'user configuration: {0}', util.displayable_path(config_path)) else: log.debug(u'no user configuration found at {0}', util.displayable_path(config_path)) log.debug(u'data directory: {0}', util.displayable_path(config.config_dir())) return config
def _configure(options): """Amend the global configuration object with command line options. """ # Add any additional config files specified with --config. This # special handling lets specified plugins get loaded before we # finish parsing the command line. if getattr(options, 'config', None) is not None: config_path = options.config del options.config config.set_file(config_path) config.set_args(options) # Configure the logger. if config['verbose'].get(int): log.set_global_level(logging.DEBUG) else: log.set_global_level(logging.INFO) # Ensure compatibility with old (top-level) color configuration. # Deprecation msg to motivate user to switch to config['ui']['color]. if config['color'].exists(): log.warning(u'Warning: top-level configuration of `color` ' u'is deprecated. Configure color use under `ui`. ' u'See documentation for more info.') config['ui']['color'].set(config['color'].get(bool)) # Compatibility from list_format_{item,album} to format_{item,album} for elem in ('item', 'album'): old_key = 'list_format_{0}'.format(elem) if config[old_key].exists(): new_key = 'format_{0}'.format(elem) log.warning( u'Warning: configuration uses "{0}" which is deprecated' u' in favor of "{1}" now that it affects all commands. ' u'See changelog & documentation.', old_key, new_key, ) config[new_key].set(config[old_key]) config_path = config.user_config_path() if os.path.isfile(config_path): log.debug(u'user configuration: {0}', util.displayable_path(config_path)) else: log.debug(u'no user configuration found at {0}', util.displayable_path(config_path)) log.debug(u'data directory: {0}', util.displayable_path(config.config_dir())) return config
def _configure(args): """Parse the command line, load configuration files (including loading any indicated plugins), and return the invoked subcomand, the subcommand options, and the subcommand arguments. """ # Temporary: Migrate from 1.0-style configuration. from beets.ui import migrate migrate.automigrate() # Get the default subcommands. from beets.ui.commands import default_commands # Construct the root parser. commands = list(default_commands) commands.append(migrate.migrate_cmd) # Temporary. parser = SubcommandsOptionParser(subcommands=commands) parser.add_option('-l', '--library', dest='library', help='library database file to use') parser.add_option('-d', '--directory', dest='directory', help="destination music directory") parser.add_option('-v', '--verbose', dest='verbose', action='store_true', help='print debugging information') parser.add_option('-c', '--config', dest='config', help='path to configuration file') # Parse the command-line! options, args = optparse.OptionParser.parse_args(parser, args) # Add any additional config files specified with --config. This # special handling lets specified plugins get loaded before we # finish parsing the command line. if getattr(options, 'config', None) is not None: config_path = options.config del options.config config.set_file(config_path) config.set_args(options) # Now add the plugin commands to the parser. _load_plugins() for cmd in plugins.commands(): parser.add_subcommand(cmd) # Parse the remainder of the command line with loaded plugins. return parser._parse_sub(args)
def _configure(options): """Amend the global configuration object with command line options. """ # Add any additional config files specified with --config. This # special handling lets specified plugins get loaded before we # finish parsing the command line. if getattr(options, b'config', None) is not None: config_path = options.config del options.config config.set_file(config_path) config.set_args(options) # Configure the logger. if config['verbose'].get(int): log.setLevel(logging.DEBUG) else: log.setLevel(logging.INFO) # Ensure compatibility with old (top-level) color configuration. # Deprecation msg to motivate user to switch to config['ui']['color]. if config['color'].exists(): log.warning(u'Warning: top-level configuration of `color` ' u'is deprecated. Configure color use under `ui`. ' u'See documentation for more info.') config['ui']['color'].set(config['color'].get(bool)) config_path = config.user_config_path() if os.path.isfile(config_path): log.debug(u'user configuration: {0}', util.displayable_path(config_path)) else: log.debug(u'no user configuration found at {0}', util.displayable_path(config_path)) log.debug(u'data directory: {0}', util.displayable_path(config.config_dir())) return config
def _raw_main(args): """A helper function for `main` without top-level exception handling. """ # Temporary: Migrate from 1.0-style configuration. from beets.ui import migrate migrate.automigrate() # Get the default subcommands. from beets.ui.commands import default_commands # Add plugin paths. import beetsplug beetsplug.__path__ = get_plugin_paths() + beetsplug.__path__ # For backwards compatibility sys.path += get_plugin_paths() # Load requested plugins. plugins.load_plugins(config['plugins'].as_str_seq()) plugins.send("pluginload") # Construct the root parser. commands = list(default_commands) commands += plugins.commands() commands.append(migrate.migrate_cmd) # Temporary. parser = SubcommandsOptionParser(subcommands=commands) parser.add_option('-l', '--library', dest='library', help='library database file to use') parser.add_option('-d', '--directory', dest='directory', help="destination music directory") parser.add_option('-v', '--verbose', dest='verbose', action='store_true', help='print debugging information') parser.add_option('-c', '--config', dest='config', help='path to configuration file') # Parse the command-line! options, subcommand, suboptions, subargs = parser.parse_args(args) if getattr(options, 'config', None) is not None: config_path = options.config del options.config config.set_file(config_path) config.set_args(options) # Open library file. dbpath = config['library'].as_filename() try: lib = library.Library( dbpath, config['directory'].as_filename(), get_path_formats(), get_replacements(), ) except sqlite3.OperationalError: raise UserError(u"database file {0} could not be opened".format( util.displayable_path(dbpath) )) plugins.send("library_opened", lib=lib) # Configure the logger. if config['verbose'].get(bool): log.setLevel(logging.DEBUG) else: log.setLevel(logging.INFO) log.debug(u'data directory: {0}\n' u'library database: {1}\n' u'library directory: {2}' .format( util.displayable_path(config.config_dir()), util.displayable_path(lib.path), util.displayable_path(lib.directory), ) ) # Configure the MusicBrainz API. mb.configure() # Invoke the subcommand. subcommand.func(lib, suboptions, subargs) plugins.send('cli_exit', lib=lib)