summaryrefslogtreecommitdiffstats
path: root/module/plugins/PluginManager.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/PluginManager.py')
-rw-r--r--module/plugins/PluginManager.py90
1 files changed, 53 insertions, 37 deletions
diff --git a/module/plugins/PluginManager.py b/module/plugins/PluginManager.py
index 9c7cab64c..f3f5f47bc 100644
--- a/module/plugins/PluginManager.py
+++ b/module/plugins/PluginManager.py
@@ -1,19 +1,34 @@
# -*- 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."
@@ -49,26 +64,26 @@ 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")
def parse(self, folder, pattern=False, home={}):
"""
- returns dict with information
+ returns dict with information
home contains parsed plugins from module.
-
+
{
name : {path, version, config, (pattern, re), (plugin, class)}
}
-
+
"""
plugins = {}
if home:
@@ -107,20 +122,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)
@@ -130,10 +145,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)
@@ -194,13 +209,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
@@ -223,10 +238,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)
@@ -235,7 +250,7 @@ class PluginManager:
plugin, type = self.findPlugin(name)
if "new_name" in plugin:
- return plugin['new_name']
+ return plugin["new_name"]
return name
@@ -247,11 +262,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)})
@@ -279,10 +294,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
@@ -329,14 +344,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()
@@ -356,9 +371,10 @@ if __name__ == "__main__":
a = time()
- test = ["http://www.youtube.com/watch?v=%s" % x for x in xrange(0, 100)]
+ test = ["http://www.youtube.com/watch?v=%s" % x for x in range(0, 100)]
print p.parseUrls(test)
b = time()
print b - a, "s"
+