From c20f64685f84abaecb06794e681dc5706b65d066 Mon Sep 17 00:00:00 2001 From: Ruud Date: Tue, 11 Mar 2014 22:15:27 +0100 Subject: [PATCH] Autoload from single file --- couchpotato/core/loader.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/couchpotato/core/loader.py b/couchpotato/core/loader.py index 5a528b1..1b4fc5f 100644 --- a/couchpotato/core/loader.py +++ b/couchpotato/core/loader.py @@ -93,7 +93,12 @@ class Loader(object): self.addModule(priority, plugin_type, module, os.path.basename(dir_name)) for name in os.listdir(dir_name): - if os.path.isdir(os.path.join(dir_name, name)) and name != 'static' and os.path.isfile(os.path.join(dir_name, name, '__init__.py')): + path = os.path.join(dir_name, name) + ext = os.path.splitext(path)[1] + ext_length = len(ext) + if name != 'static' and ((os.path.isdir(path) and os.path.isfile(os.path.join(path, '__init__.py'))) + or (os.path.isfile(path) and ext == '.py')): + name = name[:-ext_length] if ext_length > 0 else name module_name = '%s.%s' % (module, name) self.addModule(priority, plugin_type, module_name, name) @@ -118,11 +123,16 @@ class Loader(object): def loadPlugins(self, module, name): - if not hasattr(module, 'start'): + if not hasattr(module, 'autoload'): log.debug('Skip startup for plugin %s as it has no start section' % module.__file__) return False try: - module.start() + # Load single file plugin + if isinstance(module.autoload, (str, unicode)): + getattr(module, module.autoload)() + # Load folder plugin + else: + module.autoload() return True except: log.error('Failed loading plugin "%s": %s', (module.__file__, traceback.format_exc()))