diff options
Diffstat (limited to 'module/plugins/PluginManager.py')
-rw-r--r-- | module/plugins/PluginManager.py | 66 |
1 files changed, 29 insertions, 37 deletions
diff --git a/module/plugins/PluginManager.py b/module/plugins/PluginManager.py index 9c7cab64c..32ea4d16b 100644 --- a/module/plugins/PluginManager.py +++ b/module/plugins/PluginManager.py @@ -17,7 +17,7 @@ from module.ConfigParser import IGNORE class PluginManager: ROOT = "module.plugins." USERROOT = "userplugins." - TYPES = ("crypter", "container", "hoster", "captcha", "accounts", "hooks", "internal") + TYPES = ("accounts", "container", "crypter", "hooks", "hoster", "internal", "ocr") PATTERN = re.compile(r'__pattern__.*=.*r("|\')([^"\']+)') VERSION = re.compile(r'__version__.*=.*("|\')([0-9.]+)') @@ -28,7 +28,7 @@ class PluginManager: def __init__(self, core): self.core = core - #self.config = self.core.config + self.config = core.config self.log = core.log self.plugins = {} @@ -53,7 +53,7 @@ class PluginManager: self.plugins['container'] = self.containerPlugins = self.parse("container", pattern=True) self.plugins['hoster'] = self.hosterPlugins = self.parse("hoster", pattern=True) - self.plugins['captcha'] = self.captchaPlugins = self.parse("captcha") + self.plugins['ocr'] = self.captchaPlugins = self.parse("ocr") self.plugins['accounts'] = self.accountPlugins = self.parse("accounts") self.plugins['hooks'] = self.hookPlugins = self.parse("hooks") self.plugins['internal'] = self.internalPlugins = self.parse("internal") @@ -140,7 +140,7 @@ class PluginManager: # internals have no config if folder == "internal": - self.core.config.deleteConfig(name) + self.config.deleteConfig(name) continue config = self.CONFIG.findall(content) @@ -163,7 +163,7 @@ class PluginManager: if append: config.append(["activated", "bool", "Activated", False]) try: - self.core.config.addPluginConfig(name, config, desc) + self.config.addPluginConfig(name, config, desc) except: self.log.error("Invalid config in %s: %s" % (name, config)) @@ -173,7 +173,7 @@ class PluginManager: config = (["activated", "bool", "Activated", False],) try: - self.core.config.addPluginConfig(name, config, desc) + self.config.addPluginConfig(name, config, desc) except: self.log.error("Invalid config in %s: %s" % (name, config)) @@ -308,57 +308,49 @@ class PluginManager: def reloadPlugins(self, type_plugins): - """ reloads and reindexes plugins """ - if not type_plugins: return False + """ reload and reindex plugins """ + if not type_plugins: + return None self.log.debug("Request reload of plugins: %s" % type_plugins) + reloaded = [] + as_dict = {} for t,n in type_plugins: - if t in as_dict: + if t in ("hooks", "internal"): #: do not reload hooks or internals, because would cause to much side effects + continue + elif t in as_dict: as_dict[t].append(n) else: as_dict[t] = [n] - # we do not reload hooks or internals, would cause to much side effects - if "hooks" in as_dict or "internal" in as_dict: - return False - for type in as_dict.iterkeys(): for plugin in as_dict[type]: - if plugin in self.plugins[type]: - if "module" in self.plugins[type][plugin]: - self.log.debug("Reloading %s" % plugin) + if plugin in self.plugins[type] and "module" in self.plugins[type][plugin]: + self.log.debug("Reloading %s" % plugin) + id = (type, plugin) + try: reload(self.plugins[type][plugin]['module']) + except Exception, e: + self.log.error("Error when reloading %s" % id, str(e)) + continue + else: + reloaded.append(id) #index creation self.plugins['crypter'] = self.crypterPlugins = self.parse("crypter", pattern=True) self.plugins['container'] = self.containerPlugins = self.parse("container", pattern=True) self.plugins['hoster'] = self.hosterPlugins = self.parse("hoster", pattern=True) - self.plugins['captcha'] = self.captchaPlugins = self.parse("captcha") + self.plugins['ocr'] = self.captchaPlugins = self.parse("ocr") self.plugins['accounts'] = self.accountPlugins = self.parse("accounts") - if "accounts" in as_dict: #accounts needs to be reloaded + if "accounts" in as_dict: #: accounts needs to be reloaded self.core.accountManager.initPlugins() self.core.scheduler.addJob(0, self.core.accountManager.getAccountInfos) - return True - - - -if __name__ == "__main__": - _ = lambda x: x - pypath = "/home/christian/Projekte/pyload-0.4/module/plugins" - - from time import time - - p = PluginManager(None) - - a = time() - - test = ["http://www.youtube.com/watch?v=%s" % x for x in xrange(0, 100)] - print p.parseUrls(test) - - b = time() + return reloaded #: return a list of the plugins successfully reloaded - print b - a, "s" + def reloadPlugin(self, type_plugin): + """ reload and reindex ONE plugin """ + return True if self.reloadPlugins(type_plugin) else False |