def config_func(lib, opts, args): # Make sure lazy configuration is loaded config.resolve() # Print paths. if opts.paths: filenames = [] for source in config.sources: if not opts.defaults and source.default: continue if source.filename: filenames.append(source.filename) # In case the user config file does not exist, prepend it to the # list. user_path = config.user_config_path() if user_path not in filenames: filenames.insert(0, user_path) for filename in filenames: print(filename) # Open in editor. elif opts.edit: path = config.user_config_path() if 'EDITOR' in os.environ: editor = os.environ['EDITOR'] args = [editor, editor, path] elif platform.system() == 'Darwin': args = ['open', 'open', '-n', path] elif platform.system() == 'Windows': # On windows we can execute arbitrary files. The os will # take care of starting an appropriate application args = [path, path] else: # Assume Unix args = ['xdg-open', 'xdg-open', path] try: os.execlp(*args) except OSError: raise ui.UserError("Could not edit configuration. Please" "set the EDITOR environment variable.") # Dump configuration. else: print(config.dump(full=opts.defaults))
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(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 preview_playlist_command(self, lib, opts, args): name_column_length = 60 count = 10 self._log.info(config.user_config_path()) if opts.count: count = int(opts.count) if opts.playlist: if opts.playlist not in _settings.playlists: self._log.error(u'Playlist not defined: {}'.format(opts.playlist)) return query = _settings.playlists[opts.playlist].query.split(u" ") else: query = decargs(args) query = u" ".join(query) query = ignore_deleted_in_query(query) items = playlist_generator.generate_playlist(lib, _settings.rules, count, opts.shuffle, query) for item in items: score_string = ", ".join(['%s: %s' % (key.replace("rule_", ""), value) for (key, value) in sorted(item.scores.items())]) score_sum = round(sum(item.scores.values()), 2) item_name = unicode(item) if len(item_name) > name_column_length-5: item_name = item_name[:name_column_length-5] + "..." item_string = item_name.ljust(name_column_length) print_(u"Track: {0} Scores: {1}=[{2}]".format(item_string, score_sum, score_string))
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(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(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 preview_playlist_command(self, lib, opts, args): name_column_length = 60 count = 10 self._log.info(config.user_config_path()) if opts.count: count = int(opts.count) if opts.playlist: if opts.playlist not in _settings.playlists: self._log.error(u'Playlist not defined: {}'.format( opts.playlist)) return query = _settings.playlists[opts.playlist].query.split(u" ") else: query = decargs(args) query = u" ".join(query) query = ignore_deleted_in_query(query) items = playlist_generator.generate_playlist(lib, _settings.rules, count, opts.shuffle, query) for item in items: score_string = ", ".join([ '%s: %s' % (key.replace("rule_", ""), value) for (key, value) in sorted(item.scores.items()) ]) score_sum = round(sum(item.scores.values()), 2) item_name = unicode(item) if len(item_name) > name_column_length - 5: item_name = item_name[:name_column_length - 5] + "..." item_string = item_name.ljust(name_column_length) print_(u"Track: {0} Scores: {1}=[{2}]".format( item_string, score_sum, score_string))
from os import path import pickle import pprint from beets import config from beets import logging _beets_log = logging.getLogger('beets') _log = _beets_log.getChild("radio-stream-settings") _settings_file = path.join(path.dirname(config.user_config_path()), "radio-stream.pickle") _log.debug("settings location: " + _settings_file) class Settings: def __init__(self): self.playlists = None self.rules = None @staticmethod def load(): settings = None try: with open(_settings_file, 'rb') as f: settings = pickle.load(f) except Exception as exc: _log.warn(u'could not open radio-stream settings: {0}', exc) if settings is None: settings = Settings()
def get_config_path(self): return config.user_config_path()