diff --git a/beets/plugins.py b/beets/plugins.py index ca93b9d0a..74b399adb 100755 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -1,5 +1,5 @@ # This file is part of beets. -# Copyright 2011, Adrian Sampson. +# Copyright 2012, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -15,10 +15,10 @@ """Support for beets plugins.""" import logging -import itertools import traceback from collections import defaultdict +import beets from beets import mediafile PLUGIN_NAMESPACE = 'beetsplug' @@ -37,12 +37,13 @@ class BeetsPlugin(object): functionality by defining a subclass of BeetsPlugin and overriding the abstract methods defined here. """ - def __init__(self): - """Perform one-time plugin setup. There is probably no reason to - override this method. + def __init__(self, name=None): + """Perform one-time plugin setup. """ _add_media_fields(self.item_fields()) self.import_stages = [] + self.name = name or self.__module__.split('.')[-1] + self.config = beets.config[self.name] def commands(self): """Should return a list of beets.ui.Subcommand objects for diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 47b52933d..ed535cbc8 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -935,10 +935,7 @@ default_commands.append(stats_cmd) def show_version(lib, opts, args): print_('beets version %s' % beets.__version__) # Show plugins. - names = [] - for plugin in plugins.find_plugins(): - modname = plugin.__module__ - names.append(modname.split('.')[-1]) + names = [p.name for p in plugins.find_plugins()] if names: print_('plugins:', ', '.join(names)) else: diff --git a/beets/util/confit.py b/beets/util/confit.py index e3425404c..d1f6f4f93 100644 --- a/beets/util/confit.py +++ b/beets/util/confit.py @@ -139,6 +139,13 @@ class ConfigView(object): return value + def add(self, value): + """Add a value as a source for configuration data. The object as + added as the lowest-priority source. This can be used to + dynamically extend the defaults. + """ + raise NotImplementedError + def set(self, value): """Create an overlay source to set the value at this view. """ @@ -324,12 +331,6 @@ class RootView(ConfigView): self.name = ROOT_NAME def add(self, obj): - """Add the object (probably a dict) as a source for - configuration data. The object as added as the lowest-priority - source. This can be used to dynamically extend the defaults - (i.e., when loading a plugin that shares the main application's - config file). - """ self.sources.append(obj) def set(self, value): @@ -382,6 +383,9 @@ class Subview(ConfigView): def set(self, value): self.parent.set({self.key: value}) + def add(self, value): + self.parent.add({self.key: value}) + # Config file paths, including platform-specific paths and in-package # defaults. diff --git a/beetsplug/bpd/__init__.py b/beetsplug/bpd/__init__.py index 89fbc68cf..af9d548e3 100644 --- a/beetsplug/bpd/__init__.py +++ b/beetsplug/bpd/__init__.py @@ -32,14 +32,6 @@ from beets import vfs from beets import config from beets.util import bluelet -config.add({ - 'bpd': { - 'host': u'', - 'port': 6600, - 'password': u'', - } -}) - PROTOCOL_VERSION = '0.13.0' BUFSIZE = 1024 @@ -1129,6 +1121,14 @@ class BPDPlugin(BeetsPlugin): """Provides the "beet bpd" command for running a music player server. """ + def __init__(self): + super(BPDPlugin, self).__init__() + self.config.add({ + 'host': u'', + 'port': 6600, + 'password': u'', + }) + def start_bpd(self, lib, host, port, password, debug): """Starts a BPD server.""" if debug: @@ -1149,11 +1149,11 @@ class BPDPlugin(BeetsPlugin): help='dump all MPD traffic to stdout') def func(lib, opts, args): - host = args.pop(0) if args else config['bpd']['host'].get(unicode) - port = args.pop(0) if args else config['bpd']['port'].get(int) + host = args.pop(0) if args else self.config['host'].get(unicode) + port = args.pop(0) if args else self.config['port'].get(int) if args: raise beets.ui.UserError('too many arguments') - password = config['bpd']['password'].get(unicode) + password = self.config['password'].get(unicode) debug = opts.debug or False self.start_bpd(lib, host, int(port), password, debug)