diff options
Diffstat (limited to 'module/plugins/PluginManager.py')
-rw-r--r-- | module/plugins/PluginManager.py | 83 |
1 files changed, 34 insertions, 49 deletions
diff --git a/module/plugins/PluginManager.py b/module/plugins/PluginManager.py index 1e1656ce8..32ea4d16b 100644 --- a/module/plugins/PluginManager.py +++ b/module/plugins/PluginManager.py @@ -1,34 +1,19 @@ # -*- coding: utf-8 -*- -""" - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. - - @author: mkaay, RaNaN -""" - import re import sys +from itertools import chain from os import listdir, makedirs from os.path import isfile, join, exists, abspath from sys import version_info -from itertools import chain from traceback import print_exc from module.lib.SafeEval import const_eval as literal_eval + from module.ConfigParser import IGNORE + class PluginManager: ROOT = "module.plugins." USERROOT = "userplugins." @@ -64,20 +49,20 @@ class PluginManager: f = open(join("userplugins", "__init__.py"), "wb") f.close() - 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['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["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") + 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") self.log.debug("created index of plugins") def parse(self, folder, pattern=False, home={}): """ - returns dict with information + returns dict with information home contains parsed plugins from module. { @@ -122,20 +107,20 @@ class PluginManager: # home contains plugins from pyload root if home and name in home: - if home[name]["v"] >= version: + if home[name]['v'] >= version: continue if name in IGNORE or (folder, name) in IGNORE: continue plugins[name] = {} - plugins[name]["v"] = version + plugins[name]['v'] = version module = f.replace(".pyc", "").replace(".py", "") # the plugin is loaded from user directory - plugins[name]["user"] = True if home else False - plugins[name]["name"] = module + plugins[name]['user'] = True if home else False + plugins[name]['name'] = module if pattern: pattern = self.PATTERN.findall(content) @@ -145,10 +130,10 @@ class PluginManager: else: pattern = "^unmachtable$" - plugins[name]["pattern"] = pattern + plugins[name]['pattern'] = pattern try: - plugins[name]["re"] = re.compile(pattern) + plugins[name]['re'] = re.compile(pattern) except: self.log.error(_("%s has a invalid pattern.") % name) @@ -209,13 +194,13 @@ class PluginManager: if type(url) not in (str, unicode, buffer): continue found = False - if last and last[1]["re"].match(url): + if last and last[1]['re'].match(url): res.append((url, last[0])) continue for name, value in chain(self.crypterPlugins.iteritems(), self.hosterPlugins.iteritems(), self.containerPlugins.iteritems()): - if value["re"].match(url): + if value['re'].match(url): res.append((url, name)) last = (name, value) found = True @@ -238,10 +223,10 @@ class PluginManager: if not plugin: self.log.warning("Plugin %s not found." % name) - plugin = self.hosterPlugins["BasePlugin"] + plugin = self.hosterPlugins['BasePlugin'] if "new_module" in plugin and not original: - return plugin["new_module"] + return plugin['new_module'] return self.loadModule(type, name) @@ -250,7 +235,7 @@ class PluginManager: plugin, type = self.findPlugin(name) if "new_name" in plugin: - return plugin["new_name"] + return plugin['new_name'] return name @@ -262,11 +247,11 @@ class PluginManager: """ plugins = self.plugins[type] if name in plugins: - if "module" in plugins[name]: return plugins[name]["module"] + if "module" in plugins[name]: return plugins[name]['module'] try: - module = __import__(self.ROOT + "%s.%s" % (type, plugins[name]["name"]), globals(), locals(), - plugins[name]["name"]) - plugins[name]["module"] = module #cache import, maybe unneeded + module = __import__(self.ROOT + "%s.%s" % (type, plugins[name]['name']), globals(), locals(), + plugins[name]['name']) + plugins[name]['module'] = module #cache import, maybe unneeded return module except Exception, e: self.log.error(_("Error importing %(name)s: %(msg)s") % {"name": name, "msg": str(e)}) @@ -294,10 +279,10 @@ class PluginManager: if type in self.plugins and name in self.plugins[type]: #userplugin is a newer version - if not user and self.plugins[type][name]["user"]: + if not user and self.plugins[type][name]['user']: return self #imported from userdir, but pyloads is newer - if user and not self.plugins[type][name]["user"]: + if user and not self.plugins[type][name]['user']: return self @@ -346,7 +331,7 @@ class PluginManager: self.log.debug("Reloading %s" % plugin) id = (type, plugin) try: - reload(self.plugins[type][plugin]["module"]) + reload(self.plugins[type][plugin]['module']) except Exception, e: self.log.error("Error when reloading %s" % id, str(e)) continue @@ -354,11 +339,11 @@ class PluginManager: 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["ocr"] = self.captchaPlugins = self.parse("ocr") - self.plugins["accounts"] = self.accountPlugins = self.parse("accounts") + 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['ocr'] = self.captchaPlugins = self.parse("ocr") + self.plugins['accounts'] = self.accountPlugins = self.parse("accounts") if "accounts" in as_dict: #: accounts needs to be reloaded self.core.accountManager.initPlugins() |