From 5060e4c6374a5116d0d8b02528f910f8c5f8bcf9 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 15 Jul 2014 16:25:41 +0200 Subject: Fix code indentation, some bad whitespaces and missing authors + use 'not' instead 'is None' + replace __pattern__'s r" with r' + other minor cosmetics --- module/plugins/PluginManager.py | 1 + 1 file changed, 1 insertion(+) (limited to 'module/plugins/PluginManager.py') diff --git a/module/plugins/PluginManager.py b/module/plugins/PluginManager.py index e976b2c4a..b290c2746 100644 --- a/module/plugins/PluginManager.py +++ b/module/plugins/PluginManager.py @@ -29,6 +29,7 @@ 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." -- cgit v1.2.3 From a1495eb2f9502fdf29974458845f928025bedf53 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 26 Jul 2014 02:36:15 +0200 Subject: Prefer single quote for dict key --- module/plugins/PluginManager.py | 60 ++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'module/plugins/PluginManager.py') diff --git a/module/plugins/PluginManager.py b/module/plugins/PluginManager.py index b290c2746..adfa5845e 100644 --- a/module/plugins/PluginManager.py +++ b/module/plugins/PluginManager.py @@ -65,14 +65,14 @@ 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["captcha"] = self.captchaPlugins = self.parse("captcha") - 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['captcha'] = self.captchaPlugins = self.parse("captcha") + 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") @@ -123,20 +123,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) @@ -146,10 +146,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) @@ -210,13 +210,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 @@ -239,10 +239,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) @@ -251,7 +251,7 @@ class PluginManager: plugin, type = self.findPlugin(name) if "new_name" in plugin: - return plugin["new_name"] + return plugin['new_name'] return name @@ -263,11 +263,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)}) @@ -295,10 +295,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 @@ -345,14 +345,14 @@ class PluginManager: if plugin in self.plugins[type]: if "module" in self.plugins[type][plugin]: self.log.debug("Reloading %s" % plugin) - reload(self.plugins[type][plugin]["module"]) + reload(self.plugins[type][plugin]['module']) #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["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['captcha'] = self.captchaPlugins = self.parse("captcha") + self.plugins['accounts'] = self.accountPlugins = self.parse("accounts") if "accounts" in as_dict: #accounts needs to be reloaded self.core.accountManager.initPlugins() -- cgit v1.2.3 From ba916633f2bedb04c7358000b91aed69f52e8e43 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 1 Aug 2014 19:35:59 +0200 Subject: Remove trailing whitespaces + remove license headers + import urllib methods directly + sort and fix key attributes + use save_join instead join + sort some import declarations + other minor code cosmetics --- module/plugins/PluginManager.py | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) (limited to 'module/plugins/PluginManager.py') diff --git a/module/plugins/PluginManager.py b/module/plugins/PluginManager.py index adfa5845e..9c7cab64c 100644 --- a/module/plugins/PluginManager.py +++ b/module/plugins/PluginManager.py @@ -1,32 +1,16 @@ # -*- 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 . - - @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 @@ -78,7 +62,7 @@ class PluginManager: def parse(self, folder, pattern=False, home={}): """ - returns dict with information + returns dict with information home contains parsed plugins from module. { -- cgit v1.2.3