Travis Shirk avatar Travis Shirk committed 35a72b6

Hacking on user config, etc.

Comments (0)

Files changed (4)

 
-[DEFAULT]
-plugin = classic
+[default]
+
+# Default plugin to use.
+plugin = 
+
+# General options to always use. These can be plugin specific but SHOULD NOT be
+# A -C/--config and -P/--plugin options are ignored.
 options = -Q --pdb -l debug
+
+# Extra directories to load plugins. Separated by ':'
+plugin_path = ~/.eyeD3:${HOME}/.eyeD3/plugins
+
+
+

src/eyed3/info.py.in

 %s
 """ % (VERSION, RELEASE, AUTHOR, URL)
 
-USER_DIR = os.path.expandvars(os.path.join("${HOME}", ".eyeD3"))
-PLUGIN_DIRS = [ os.path.join(USER_DIR, "plugins") ]
+USER_CONFIG = os.path.expandvars(os.path.join("${HOME}", ".eyeD3rc"))
 
 LICENCE = """
 		    GNU GENERAL PUBLIC LICENSE

src/eyed3/main.py

 
 
 DEFAULT_PLUGIN = "classic"
-DEFAULT_CONFIG = os.path.join(eyed3.info.USER_DIR, "config.ini")
+DEFAULT_CONFIG = eyed3.info.USER_CONFIG
 
 
 def main(args, config):
     config = _loadConfig(args.config)
 
     if args.plugin:
-        # Plugins on the command line take precedence over config.
+        # Plugin on the command line takes precedence over config.
         plugin_name = args.plugin
-    elif config:
+    elif config and config.has_option("default", "plugin"):
         # Get default plugin from config or use DEFAULT_CONFIG
-        try:
-            plugin_name = config.get("DEFAULT", "plugin")
-        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as ex:
+        plugin_name = config.get("default", "plugin")
+        if not plugin_name:
             plugin_name = DEFAULT_PLUGIN
     else:
         plugin_name = DEFAULT_PLUGIN
     assert(plugin_name)
 
-    PluginClass = eyed3.plugins.load(plugin_name)
+    plugin_path = []
+    if config and config.has_option("default", "plugin_path"):
+        val = config.get("default", "plugin_path")
+        plugin_path = [os.path.expanduser(os.path.expandvars(d)) for d
+                            in val.split(':')]
+
+
+    PluginClass = eyed3.plugins.load(plugin_name, paths=plugin_path)
     if PluginClass is None:
         eyed3.utils.cli.printError("Plugin not found: %s" % plugin_name)
         parser.exit(1)
     plugin = PluginClass(parser)
 
-    # Reparse the command line with options from the config.
-    if config:
-        try:
-            config_opts = config.get("DEFAULT", "options").split()
-            cmd_line_args.extend(config_opts)
-        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as ex:
-            pass
+    if config and config.has_option("default", "options"):
+        cmd_line_args.extend(config.get("default", "options").split())
+
+    # Reparse the command line including options from the config.
     args = parser.parse_args(args=cmd_line_args)
 
     if args.list_plugins:

src/eyed3/plugins/__init__.py

 
 log = logging.getLogger(__name__)
 
-def load(name=None, reload=False):
+def load(name=None, reload=False, paths=None):
     '''Returns the eyed3.plugins.Plugin *class* identified by ``name``.
     If ``name`` is ``None`` then the full list of plugins is returned.
     Once a plugin is loaded its class object is cached, and future calls to
     this function will returned the cached version. Use ``reload=True`` to
     refresh the cache.'''
-    from eyed3.info import PLUGIN_DIRS
     global _PLUGINS
 
     if len(_PLUGINS.keys()) and reload == False:
                     and f[0] not in ('_', '.')
                     and f.endswith(".py"))
 
-    for d in [os.path.dirname(__file__)] + PLUGIN_DIRS:
+    for d in [os.path.dirname(__file__)] + (paths if paths else []):
         log.debug("Searching '%s' for plugins", d)
         if not os.path.isdir(d):
             continue
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.