summaryrefslogtreecommitdiffstats
path: root/pyload/manager
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2014-10-03 21:20:20 +0200
committerGravatar Walter Purcaro <vuolter@gmail.com> 2014-10-03 21:20:20 +0200
commitf6e5359110f4bd5facc04a98f94acbc41b6e5228 (patch)
tree1f625724951c1b3a848f96c65708f437807f7190 /pyload/manager
parent[UpdateManager] Support new plugins structure (diff)
downloadpyload-f6e5359110f4bd5facc04a98f94acbc41b6e5228.tar.xz
Update pyload to the new plugins structure
Diffstat (limited to 'pyload/manager')
-rw-r--r--pyload/manager/AccountManager.py2
-rw-r--r--pyload/manager/AddonManager.py (renamed from pyload/manager/HookManager.py)51
-rw-r--r--pyload/manager/CaptchaManager.py4
-rw-r--r--pyload/manager/PluginManager.py27
-rw-r--r--pyload/manager/ThreadManager.py8
-rw-r--r--pyload/manager/thread/PluginThread.py16
6 files changed, 56 insertions, 52 deletions
diff --git a/pyload/manager/AccountManager.py b/pyload/manager/AccountManager.py
index d1958f4b6..ec092d740 100644
--- a/pyload/manager/AccountManager.py
+++ b/pyload/manager/AccountManager.py
@@ -36,7 +36,7 @@ class AccountManager:
if plugin in self.accounts:
if plugin not in self.plugins:
try:
- self.plugins[plugin] = self.core.pluginManager.loadClass("accounts", plugin)(self, self.accounts[plugin])
+ self.plugins[plugin] = self.core.pluginManager.loadClass("account", plugin)(self, self.accounts[plugin])
except TypeError: # The account class no longer exists (blacklisted plugin). Skipping the account to avoid crash
return None
diff --git a/pyload/manager/HookManager.py b/pyload/manager/AddonManager.py
index 6f5477aeb..a81e0a74f 100644
--- a/pyload/manager/HookManager.py
+++ b/pyload/manager/AddonManager.py
@@ -25,21 +25,21 @@ from threading import RLock
from types import MethodType
-from pyload.manager.thread.PluginThread import HookThread
+from pyload.manager.thread.PluginThread import AddonThread
from pyload.manager.PluginManager import literal_eval
from utils import lock
-class HookManager:
- """Manages hooks, delegates and handles Events.
+class AddonManager:
+ """Manages addons, delegates and handles Events.
Every plugin can define events, \
but some very usefull events are called by the Core.
- Contrary to overwriting hook methods you can use event listener,
+ Contrary to overwriting addon methods you can use event listener,
which provides additional entry point in the control flow.
Only do very short tasks or use threads.
**Known Events:**
- Most hook methods exists as events. These are the additional known events.
+ Most addon methods exists as events. These are the additional known events.
===================== ============== ==================================
Name Arguments Description
@@ -65,7 +65,7 @@ class HookManager:
self.core = core
self.config = self.core.config
- __builtin__.hookManager = self #needed to let hooks register themself
+ __builtin__.addonManager = self #needed to let addons register themself
self.log = self.core.log
self.plugins = []
@@ -77,7 +77,7 @@ class HookManager:
#registering callback for config event
self.config.pluginCB = MethodType(self.dispatchEvent, "pluginConfigChanged", basestring)
- self.addEvent("pluginConfigChanged", self.manageHooks)
+ self.addEvent("pluginConfigChanged", self.manageAddon)
self.lock = RLock()
self.createIndex()
@@ -87,7 +87,7 @@ class HookManager:
try:
return func(*args)
except Exception, e:
- args[0].log.error(_("Error executing hooks: %s") % str(e))
+ args[0].log.error(_("Error executing addon: %s") % e)
if args[0].core.debug:
traceback.print_exc()
@@ -119,12 +119,12 @@ class HookManager:
active = []
deactive = []
- for pluginname in self.core.pluginManager.hookPlugins:
+ for pluginname in self.core.pluginManager.addonPlugins:
try:
- #hookClass = getattr(plugin, plugin.__name__)
+ # hookClass = getattr(plugin, plugin.__name__)
if self.config.getPlugin(pluginname, "activated"):
- pluginClass = self.core.pluginManager.loadClass("hooks", pluginname)
+ pluginClass = self.core.pluginManager.loadClass("addon", pluginname)
if not pluginClass: continue
plugin = pluginClass(self.core, self)
@@ -146,20 +146,20 @@ class HookManager:
self.plugins = plugins
- def manageHooks(self, plugin, name, value):
+ def manageAddon(self, plugin, name, value):
if name == "activated" and value:
- self.activateHook(plugin)
+ self.activateAddon(plugin)
elif name == "activated" and not value:
- self.deactivateHook(plugin)
+ self.deactivateAddon(plugin)
- def activateHook(self, plugin):
+ def activateAddon(self, plugin):
#check if already loaded
for inst in self.plugins:
if inst.__name__ == plugin:
return
- pluginClass = self.core.pluginManager.loadClass("hooks", plugin)
+ pluginClass = self.core.pluginManager.loadClass("addon", plugin)
if not pluginClass: return
@@ -172,23 +172,24 @@ class HookManager:
# call core Ready
start_new_thread(plugin.coreReady, tuple())
- def deactivateHook(self, plugin):
+ def deactivateAddon(self, plugin):
- hook = None
+ addon = None
for inst in self.plugins:
if inst.__name__ == plugin:
- hook = inst
+ addon = inst
- if not hook: return
+ if not addon:
+ return
self.log.debug("Plugin unloaded: %s" % plugin)
- hook.unload()
+ addon.unload()
#remove periodic call
- self.log.debug("Removed callback %s" % self.core.scheduler.removeJob(hook.cb))
- self.plugins.remove(hook)
- del self.pluginMap[hook.__name__]
+ self.log.debug("Removed callback %s" % self.core.scheduler.removeJob(addon.cb))
+ self.plugins.remove(addon)
+ del self.pluginMap[addon.__name__]
@try_catch
@@ -256,7 +257,7 @@ class HookManager:
self.dispatchEvent("afterReconnecting", ip)
def startThread(self, function, *args, **kwargs):
- t = HookThread(self.core.threadManager, function, args, kwargs)
+ t = AddonThread(self.core.threadManager, function, args, kwargs)
def activePlugins(self):
""" returns all active plugins """
diff --git a/pyload/manager/CaptchaManager.py b/pyload/manager/CaptchaManager.py
index 0ba876ae8..06f1347fc 100644
--- a/pyload/manager/CaptchaManager.py
+++ b/pyload/manager/CaptchaManager.py
@@ -64,7 +64,7 @@ class CaptchaManager:
if cli: #client connected -> should solve the captcha
task.setWaiting(50) #wait 50 sec for response
- for plugin in self.core.hookManager.activePlugins():
+ for plugin in self.core.addonManager.activePlugins():
try:
plugin.newCaptchaTask(task)
except:
@@ -87,7 +87,7 @@ class CaptchaTask:
self.captchaFormat = format
self.captchaFile = file
self.captchaResultType = result_type
- self.handler = [] #the hook plugins that will take care of the solution
+ self.handler = [] #: the hook plugins that will take care of the solution
self.result = None
self.waitUntil = None
self.error = None #error message
diff --git a/pyload/manager/PluginManager.py b/pyload/manager/PluginManager.py
index 56e59237c..939b17347 100644
--- a/pyload/manager/PluginManager.py
+++ b/pyload/manager/PluginManager.py
@@ -17,7 +17,7 @@ from pyload.config.Parser import IGNORE
class PluginManager:
ROOT = "pyload.plugins."
USERROOT = "userplugins."
- TYPES = ("accounts", "container", "crypter", "hooks", "hoster", "internal", "ocr")
+ TYPES = ("account", "addon", "base", "container", "crypter", "hook", "hoster", "internal", "ocr")
PATTERN = re.compile(r'__pattern__.*=.*r("|\')([^"\']+)')
VERSION = re.compile(r'__version__.*=.*("|\')([0-9.]+)')
@@ -49,14 +49,15 @@ class PluginManager:
f = open(join("userplugins", "__init__.py"), "wb")
f.close()
- self.plugins['crypter'] = self.crypterPlugins = self.parse("crypter", pattern=True)
+ self.plugins['account'] = self.accountPlugins = self.parse("account")
+ self.plugins['addon'] = self.addonPlugins = self.parse("addon")
+ self.plugins['base'] = self.basePlugins = self.parse("base")
self.plugins['container'] = self.containerPlugins = self.parse("container", pattern=True)
+ self.plugins['crypter'] = self.crypterPlugins = self.parse("crypter", pattern=True)
+ # self.plugins['hook'] = self.hookPlugins = self.parse("hook")
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.ocrPlugins = self.parse("ocr")
self.log.debug("created index of plugins")
@@ -154,7 +155,7 @@ class PluginManager:
else:
config = [list(config)]
- if folder == "hooks":
+ if folder == "addon":
append = True
for item in config:
if item[0] == "activated": append = False
@@ -167,7 +168,7 @@ class PluginManager:
except:
self.log.error("Invalid config in %s: %s" % (name, config))
- elif folder == "hooks": #force config creation
+ elif folder == "addon": #force config creation
desc = self.DESC.findall(content)
desc = desc[0][1] if desc else ""
config = (["activated", "bool", "Activated", False],)
@@ -318,7 +319,7 @@ class PluginManager:
as_dict = {}
for t,n in type_plugins:
- if t in ("hooks", "internal"): #: do not reload hooks or internals, because would cause to much side effects
+ if t in ("base", "addon", "internal"): #: do not reload them because would cause to much side effects
continue
elif t in as_dict:
as_dict[t].append(n)
@@ -339,11 +340,13 @@ class PluginManager:
reloaded.append(id)
#index creation
- self.plugins['crypter'] = self.crypterPlugins = self.parse("crypter", pattern=True)
+ self.plugins['account'] = self.accountPlugins = self.parse("account")
self.plugins['container'] = self.containerPlugins = self.parse("container", pattern=True)
+ self.plugins['crypter'] = self.crypterPlugins = self.parse("crypter", pattern=True)
+ # self.plugins['hook'] = self.hookPlugins = self.parse("hook")
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['ocr'] = self.ocrPlugins = self.parse("ocr")
+
if "accounts" in as_dict: #: accounts needs to be reloaded
self.core.accountManager.initPlugins()
diff --git a/pyload/manager/ThreadManager.py b/pyload/manager/ThreadManager.py
index 1073f8040..50af4a93a 100644
--- a/pyload/manager/ThreadManager.py
+++ b/pyload/manager/ThreadManager.py
@@ -42,8 +42,8 @@ class ThreadManager:
self.core = core
self.log = core.log
- self.threads = [] # thread list
- self.localThreads = [] #hook+decrypter threads
+ self.threads = [] #: thread list
+ self.localThreads = [] #: addon+decrypter threads
self.pause = True
@@ -185,7 +185,7 @@ class ThreadManager:
ip = self.getIP()
- self.core.hookManager.beforeReconnecting(ip)
+ self.core.addonManager.beforeReconnecting(ip)
self.log.debug("Old IP: %s" % ip)
@@ -202,7 +202,7 @@ class ThreadManager:
reconn.wait()
sleep(1)
ip = self.getIP()
- self.core.hookManager.afterReconnecting(ip)
+ self.core.addonManager.afterReconnecting(ip)
self.log.info(_("Reconnected, new IP: %s") % ip)
diff --git a/pyload/manager/thread/PluginThread.py b/pyload/manager/thread/PluginThread.py
index 5c274fa46..c5092a207 100644
--- a/pyload/manager/thread/PluginThread.py
+++ b/pyload/manager/thread/PluginThread.py
@@ -182,11 +182,11 @@ class DownloadThread(PluginThread):
self.m.log.info(_("Download starts: %s" % pyfile.name))
# start download
- self.m.core.hookManager.downloadPreparing(pyfile)
+ self.m.core.addonManager.downloadPreparing(pyfile)
pyfile.plugin.preprocessing(self)
self.m.log.info(_("Download finished: %s") % pyfile.name)
- self.m.core.hookManager.downloadFinished(pyfile)
+ self.m.core.addonManager.downloadFinished(pyfile)
self.m.core.files.checkPackageFinished(pyfile)
except NotImplementedError:
@@ -236,7 +236,7 @@ class DownloadThread(PluginThread):
self.m.log.warning(_("Download failed: %(name)s | %(msg)s") % {"name": pyfile.name, "msg": msg})
pyfile.error = msg
- self.m.core.hookManager.downloadFailed(pyfile)
+ self.m.core.addonManager.downloadFailed(pyfile)
self.clean(pyfile)
continue
@@ -277,7 +277,7 @@ class DownloadThread(PluginThread):
print_exc()
self.writeDebugReport(pyfile)
- self.m.core.hookManager.downloadFailed(pyfile)
+ self.m.core.addonManager.downloadFailed(pyfile)
self.clean(pyfile)
continue
@@ -307,7 +307,7 @@ class DownloadThread(PluginThread):
print_exc()
self.writeDebugReport(pyfile)
- self.m.core.hookManager.downloadFailed(pyfile)
+ self.m.core.addonManager.downloadFailed(pyfile)
self.clean(pyfile)
continue
@@ -409,7 +409,7 @@ class DecrypterThread(PluginThread):
exc_clear()
- #self.m.core.hookManager.downloadFinished(pyfile)
+ #self.m.core.addonManager.downloadFinished(pyfile)
#self.m.localThreads.remove(self)
@@ -418,8 +418,8 @@ class DecrypterThread(PluginThread):
pyfile.delete()
-class HookThread(PluginThread):
- """thread for hooks"""
+class AddonThread(PluginThread):
+ """thread for addons"""
#--------------------------------------------------------------------------
def __init__(self, m, function, args, kwargs):