add config option for importing additional plugins

This commit is contained in:
Adrian Sampson 2010-07-08 17:18:43 -07:00
parent 8ccc8e1ccd
commit 7cdcc9a277
2 changed files with 22 additions and 12 deletions

View file

@ -16,6 +16,7 @@
import logging
import itertools
import traceback
# Global logger.
log = logging.getLogger('beets')
@ -44,13 +45,18 @@ def load_plugins(names=()):
for name in itertools.chain(names, DEFAULT_PLUGINS):
modname = '%s.%s' % (PLUGIN_NAMESPACE, name)
try:
__import__(modname, None, None)
except ImportError, exc:
# Again, this is hacky:
if exc.args[0].endswith(modname):
log.warn('plugin %s not found' % name)
else:
raise
try:
__import__(modname, None, None)
except ImportError, exc:
# Again, this is hacky:
if exc.args[0].endswith(' ' + name):
log.warn('** plugin %s not found' % name)
else:
raise
except:
log.warn('** error loading plugin %s' % name)
log.warn(traceback.format_exc())
_instances = {}
def find_plugins():

View file

@ -339,7 +339,15 @@ def main():
"""Run the main command-line interface for beets."""
# Get the default subcommands.
from beets.ui.commands import default_commands
# Read defaults from config file.
config = ConfigParser.SafeConfigParser()
config.read(CONFIG_FILE)
# Load requested plugins.
plugnames = config_val(config, 'beets', 'plugins', '')
plugins.load_plugins(plugnames.split())
# Construct the root parser.
commands = list(default_commands)
commands += plugins.commands()
@ -354,10 +362,6 @@ def main():
# Parse the command-line!
options, subcommand, suboptions, subargs = parser.parse_args()
# Read defaults from config file.
config = ConfigParser.SafeConfigParser()
config.read(CONFIG_FILE)
# Open library file.
libpath = options.libpath or \
config_val(config, 'beets', 'library', DEFAULT_LIBRARY)