diff options
Diffstat (limited to 'pyload/manager/Plugin.py')
-rw-r--r-- | pyload/manager/Plugin.py | 64 |
1 files changed, 25 insertions, 39 deletions
diff --git a/pyload/manager/Plugin.py b/pyload/manager/Plugin.py index 739fa3538..918f6de8a 100644 --- a/pyload/manager/Plugin.py +++ b/pyload/manager/Plugin.py @@ -25,30 +25,27 @@ class PluginManager(object): CONFIG = re.compile(r'__config\s*=\s*\[([^\]]+)', re.M) DESC = re.compile(r'__description\s*=\s*("|"""|\')([^"\']+)') - def __init__(self, core): self.core = core self.plugins = {} self.createIndex() - #register for import addon + # register for import addon sys.meta_path.append(self) - def loadTypes(self): rootdir = join(pypath, "pyload", "plugin") userdir = "userplugins" types = set().union(*[[d for d in listdir(p) if isdir(join(p, d))] - for p in (rootdir, userdir) if exists(p)]) + for p in (rootdir, userdir) if exists(p)]) if not types: self.core.log.critical(_("No plugins found!")) self.TYPES = list(set(self.TYPES) | types) - def createIndex(self): """create information for all plugins available""" @@ -67,7 +64,6 @@ class PluginManager(object): self.core.log.debug("Created index of plugins") - def parse(self, folder, rootplugins={}): """ returns dict with information @@ -168,7 +164,7 @@ class PluginManager(object): except Exception: self.core.log.error("Invalid config in %s: %s" % (name, config)) - elif folder in ("addon", "hook"): #force config creation + elif folder in ("addon", "hook"): # force config creation desc = self.DESC.findall(content) desc = desc[0][1] if desc else "" config = (["activated", "bool", "Activated", False],) @@ -183,7 +179,6 @@ class PluginManager(object): return plugins - def parseUrls(self, urls): """parse plugins for given list of urls""" @@ -200,28 +195,28 @@ class PluginManager(object): res.append((url, last[0], last[1])) continue - for type in self.TYPES: - for name, plugin in self.plugins[type]: - - m = None + for plugintype in self.TYPES: + m = None + for name, plugin in self.plugins[plugintype].iteritems(): try: if 'pattern' in plugin: m = plugin['re'].match(url) except KeyError: self.core.log.error(_("Plugin [%(type)s] %(name)s skipped due broken pattern") - % {'name': name, 'type': type}) + % {'name': plugin['name'], 'type': plugintype}) if m: - res.append((url, type, name)) - last = (type, name, plugin) + res.append((url, plugintype, name)) + last = (plugintype, name, plugin) break - else: - res.append((url, "internal", "BasePlugin")) - + if m: + break + else: + res.append((url, "internal", "BasePlugin")) + print res return res - def findPlugin(self, type, name): if type not in self.plugins: return None @@ -234,7 +229,6 @@ class PluginManager(object): else: return self.plugins[type][name] - def getPlugin(self, type, name, original=False): """return plugin module from hoster|decrypter|container""" plugin = self.findPlugin(type, name) @@ -247,7 +241,6 @@ class PluginManager(object): else: return self.loadModule(type, name) - def getPluginName(self, type, name): """ used to obtain new name if other plugin was injected""" plugin = self.findPlugin(type, name) @@ -260,7 +253,6 @@ class PluginManager(object): return name - def loadModule(self, type, name): """ Returns loaded module for plugin @@ -284,13 +276,12 @@ class PluginManager(object): print_exc() else: - plugins[name]['module'] = module #: cache import, maybe unneeded + plugins[name]['module'] = module # : cache import, maybe unneeded self.core.log.debug(_("Loaded plugin: [%(type)s] %(name)s (v%(version).2f)") % {'name': name, 'type': type, 'version': plugins[name]['version']}) return module - def loadClass(self, type, name): """Returns the class of a plugin with the same name""" module = self.loadModule(type, name) @@ -299,33 +290,30 @@ class PluginManager(object): else: return None - def getAccountPlugins(self): """return list of account plugin names""" return self.accountPlugins.keys() - def find_module(self, fullname, path=None): - #redirecting imports if necesarry - if fullname.startswith(self.ROOT) or fullname.startswith(self.USERROOT): #seperate pyload plugins + # redirecting imports if necesarry + if fullname.startswith(self.ROOT) or fullname.startswith(self.USERROOT): # seperate pyload plugins if fullname.startswith(self.USERROOT): user = 1 - else: user = 0 #used as bool and int + else: user = 0 # used as bool and int split = fullname.split(".") if len(split) != 4 - user: return type, name = split[2 - user:4 - user] if type in self.plugins and name in self.plugins[type]: - #userplugin is a newer version + # userplugin is a newer version if not user and self.plugins[type][name]['user']: return self - #imported from userdir, but pyloads is newer + # imported from userdir, but pyloads is newer if user and not self.plugins[type][name]['user']: return self - def load_module(self, name, replace=True): - if name not in sys.modules: #could be already in modules + if name not in sys.modules: # could be already in modules if replace: if self.ROOT in name: newname = name.replace(self.ROOT, self.USERROOT) @@ -339,13 +327,12 @@ class PluginManager(object): self.core.log.debug("Redirected import %s -> %s" % (name, newname)) module = __import__(newname, globals(), locals(), [plugin]) - #inject under new an old name + # inject under new an old name sys.modules[name] = module sys.modules[newname] = module return sys.modules[name] - def reloadPlugins(self, type_plugins): """ reload and reindex plugins """ if not type_plugins: @@ -356,14 +343,14 @@ class PluginManager(object): reloaded = [] as_dict = {} - for t,n in type_plugins: + for t, n in type_plugins: if t in as_dict: as_dict[t].append(n) else: as_dict[t] = [n] for type in as_dict.iterkeys(): - if type in ("addon", "internal"): #: do not reload them because would cause to much side effects + if type in ("addon", "internal"): # : do not reload them because would cause to much side effects self.core.log.debug("Skipping reload for plugin: [%(type)s] %(name)s" % {'name': plugin, 'type': type}) continue @@ -381,7 +368,7 @@ class PluginManager(object): else: reloaded.append((type, plugin)) - #index creation + # index creation self.plugins[type] = self.parse(type) setattr(self, "%sPlugins" % type, self.plugins[type]) @@ -391,7 +378,6 @@ class PluginManager(object): return reloaded #: return a list of the plugins successfully reloaded - def reloadPlugin(self, type_plugin): """ reload and reindex ONE plugin """ return True if self.reloadPlugins(type_plugin) else False |