diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-12-11 02:07:42 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-12-11 02:07:42 +0100 |
commit | 25f6be5c9259d17ee0a3de5eb056b07f505a5f7d (patch) | |
tree | 8f7d1982620452aa65c26b381a5682a509044422 /pyload | |
parent | Rename some Addon methods (diff) | |
download | pyload-25f6be5c9259d17ee0a3de5eb056b07f505a5f7d.tar.xz |
Rename some events + engage renamed addon methods
Diffstat (limited to 'pyload')
-rw-r--r-- | pyload/api/__init__.py | 2 | ||||
-rw-r--r-- | pyload/database/FileDatabase.py | 8 | ||||
-rw-r--r-- | pyload/manager/AddonManager.py | 130 | ||||
-rw-r--r-- | pyload/manager/CaptchaManager.py | 2 | ||||
-rw-r--r-- | pyload/plugins/Addon.py | 2 | ||||
-rw-r--r-- | pyload/plugins/Plugin.py | 2 | ||||
-rw-r--r-- | pyload/plugins/addon/ExternalScripts.py | 14 | ||||
-rw-r--r-- | pyload/plugins/addon/ExtractArchive.py | 18 | ||||
-rw-r--r-- | pyload/plugins/addon/RestartSlow.py | 2 |
9 files changed, 105 insertions, 75 deletions
diff --git a/pyload/api/__init__.py b/pyload/api/__init__.py index 76cba0d50..223b48b0a 100644 --- a/pyload/api/__init__.py +++ b/pyload/api/__init__.py @@ -138,7 +138,7 @@ class Api(Iface): :param value: new config value :param section: 'plugin' or 'core """ - self.core.addonManager.dispatchEvent("configChanged", category, option, value, section) + self.core.addonManager.dispatchEvent("config-changed", category, option, value, section) if section == "core": self.core.config[category][option] = value if option in ("limit_speed", "max_speed"): # not so nice to update the limit diff --git a/pyload/database/FileDatabase.py b/pyload/database/FileDatabase.py index 592b05b6a..933e06d80 100644 --- a/pyload/database/FileDatabase.py +++ b/pyload/database/FileDatabase.py @@ -104,7 +104,7 @@ class FileHandler(object): def addLinks(self, urls, package): """adds links""" - self.core.addonManager.dispatchEvent("linksAdded", urls, package) + self.core.addonManager.dispatchEvent("links-added", urls, package) data = self.core.pluginManager.parseUrls(urls) @@ -150,7 +150,7 @@ class FileHandler(object): self.db.deletePackage(p) self.core.pullManager.addEvent(e) - self.core.addonManager.dispatchEvent("packageDeleted", id) + self.core.addonManager.dispatchEvent("package-deleted", id) if id in self.packageCache: del self.packageCache[id] @@ -352,7 +352,7 @@ class FileHandler(object): """checks if all files are finished and dispatch event""" if not self.getQueueCount(True): - self.core.addonManager.dispatchEvent("allDownloadsFinished") + self.core.addonManager.dispatchEvent("all_downloads-finished") self.core.log.debug("All downloads finished") return True @@ -365,7 +365,7 @@ class FileHandler(object): self.resetCount() if not self.db.processcount(1, fid): - self.core.addonManager.dispatchEvent("allDownloadsProcessed") + self.core.addonManager.dispatchEvent("all_downloads-processed") self.core.log.debug("All downloads processed") return True diff --git a/pyload/manager/AddonManager.py b/pyload/manager/AddonManager.py index 6ae9f4fbc..0fc3efb7b 100644 --- a/pyload/manager/AddonManager.py +++ b/pyload/manager/AddonManager.py @@ -11,7 +11,7 @@ from types import MethodType from pyload.manager.thread.AddonThread import AddonThread from pyload.manager.PluginManager import literal_eval -from utils import lock +from pyload.utils import lock class AddonManager(object): @@ -26,44 +26,45 @@ class AddonManager(object): **Known Events:** Most addon methods exists as events. These are the additional known events. - ===================== ============== ================================== + ======================= ============== ================================== Name Arguments Description - ===================== ============== ================================== - downloadPreparing fid A download was just queued and will be prepared now. - downloadStarts fid A plugin will immediately starts the download afterwards. - linksAdded links, pid Someone just added links, you are able to modify the links. - allDownloadsProcessed Every link was handled, pyload would idle afterwards. - allDownloadsFinished Every download in queue is finished. - unrarFinished folder, fname An Unrar job finished - configChanged The config was changed via the api. - pluginConfigChanged The plugin config changed, due to api or internal process. - ===================== ============== ================================== + ======================= ============== ================================== + download-preparing fid A download was just queued and will be prepared now. + download-start fid A plugin will immediately starts the download afterwards. + links-added links, pid Someone just added links, you are able to modify the links. + all_downloads-processed Every link was handled, pyload would idle afterwards. + all_downloads-finished Every download in queue is finished. + config-changed The config was changed via the api. + pluginConfigChanged The plugin config changed, due to api or internal process. + ======================= ============== ================================== | Notes: - | allDownloadsProcessed is *always* called before allDownloadsFinished. - | configChanged is *always* called before pluginConfigChanged. + | all_downloads-processed is *always* called before all_downloads-finished. + | config-changed is *always* called before pluginConfigChanged. """ def __init__(self, core): - __builtin__.addonManager = self #needed to let addons register themself + __builtin__.addonManager = self #: needed to let addons register themself self.plugins = [] self.pluginMap = {} - self.methods = {} #dict of names and list of methods usable by rpc + self.methods = {} #: dict of names and list of methods usable by rpc - self.events = {} # contains events + self.events = {} #: contains events # registering callback for config event - self.core.config.pluginCB = MethodType(self.dispatchEvent, "pluginConfigChanged", basestring) + self.core.config.pluginCB = MethodType(self.dispatchEvent, "pluginConfigChanged", basestring) #@TODO: Rename event pluginConfigChanged self.addEvent("pluginConfigChanged", self.manageAddon) self.lock = RLock() self.createIndex() + def try_catch(func): + def new(*args): try: return func(*args) @@ -71,8 +72,10 @@ class AddonManager(object): args[0].log.error(_("Error executing addon: %s") % e) if args[0].core.debug: traceback.print_exc() + return new + def addRPC(self, plugin, func, doc): plugin = plugin.rpartition(".")[2] doc = doc.strip() if doc else "" @@ -82,17 +85,20 @@ class AddonManager(object): else: self.methods[plugin] = {func: doc} + def callRPC(self, plugin, func, args, parse): - if not args: args = tuple() + if not args: + args = tuple() if parse: args = tuple([literal_eval(x) for x in args]) plugin = self.pluginMap[plugin] f = getattr(plugin, func) return f(*args) + def createIndex(self): - plugins = [] - active = [] + plugins = [] + active = [] deactive = [] for pluginname in self.core.pluginManager.addonPlugins: @@ -100,7 +106,8 @@ class AddonManager(object): # hookClass = getattr(plugin, plugin.__name) if self.core.config.getPlugin(pluginname, "activated"): pluginClass = self.core.pluginManager.loadClass("addon", pluginname) - if not pluginClass: continue + if not pluginClass: + continue plugin = pluginClass(self.core, self) plugins.append(plugin) @@ -120,50 +127,50 @@ class AddonManager(object): self.plugins = plugins + def manageAddon(self, plugin, name, value): if name == "activated" and value: self.activateAddon(plugin) + elif name == "activated" and not value: self.deactivateAddon(plugin) - def activateAddon(self, plugin): + + def activateAddon(self, pluginname): # check if already loaded for inst in self.plugins: - if inst.__name == plugin: + if inst.__name == pluginname: return - pluginClass = self.core.pluginManager.loadClass("addon", plugin) + pluginClass = self.core.pluginManager.loadClass("addon", pluginname) if not pluginClass: return - self.core.log.debug("Plugin loaded: %s" % plugin) + self.core.log.debug("Activate addon: %s" % pluginname) - plugin = pluginClass(self.core, self) - self.plugins.append(plugin) - self.pluginMap[pluginClass.__name] = plugin + addon = pluginClass(self.core, self) + self.plugins.append(addon) + self.pluginMap[pluginClass.__name] = addon - # call core Ready - t = Thread(target=plugin.coreReady) - t.setDaemon(True) - t.start() + addon.activate() - def deactivateAddon(self, plugin): - addon = None - for inst in self.plugins: - if inst.__name == plugin: - addon = inst - - if not addon: + def deactivateAddon(self, pluginname): + for plugin in self.plugins: + if plugin.__name == pluginname: + addon = plugin + break + else: return - self.core.log.debug("Plugin unloaded: %s" % plugin) + self.core.log.debug("Deactivate addon: %s" % pluginname) - addon.unload() + addon.deactivate() #remove periodic call - self.core.log.debug("Removed callback %s" % self.core.scheduler.removeJob(addon.cb)) + self.core.log.debug("Removed callback: %s" % self.core.scheduler.removeJob(addon.cb)) + self.plugins.remove(addon) del self.pluginMap[addon.__name] @@ -172,22 +179,28 @@ class AddonManager(object): def coreReady(self): for plugin in self.plugins: if plugin.isActivated(): - plugin.coreReady() - self.dispatchEvent("coreReady") + plugin.activate() + + self.dispatchEvent("addon-start") + @try_catch def coreExiting(self): for plugin in self.plugins: if plugin.isActivated(): - plugin.coreExiting() - self.dispatchEvent("coreExiting") + plugin.exit() + + self.dispatchEvent("addon-exit") + @lock def downloadPreparing(self, pyfile): for plugin in self.plugins: if plugin.isActivated(): plugin.downloadPreparing(pyfile) - self.dispatchEvent("downloadPreparing", pyfile) + + self.dispatchEvent("download-preparing", pyfile) + @lock def downloadFinished(self, pyfile): @@ -195,7 +208,8 @@ class AddonManager(object): if plugin.isActivated(): plugin.downloadFinished(pyfile) - self.dispatchEvent("downloadFinished", pyfile) + self.dispatchEvent("download-finished", pyfile) + @lock @try_catch @@ -204,7 +218,8 @@ class AddonManager(object): if plugin.isActivated(): plugin.downloadFailed(pyfile) - self.dispatchEvent("downloadFailed", pyfile) + self.dispatchEvent("download-failed", pyfile) + @lock def packageFinished(self, package): @@ -212,30 +227,37 @@ class AddonManager(object): if plugin.isActivated(): plugin.packageFinished(package) - self.dispatchEvent("packageFinished", package) + self.dispatchEvent("package-finished", package) + @lock def beforeReconnecting(self, ip): for plugin in self.plugins: plugin.beforeReconnecting(ip) + self.dispatchEvent("beforeReconnecting", ip) + @lock def afterReconnecting(self, ip): for plugin in self.plugins: if plugin.isActivated(): plugin.afterReconnecting(ip) + self.dispatchEvent("afterReconnecting", ip) + def startThread(self, function, *args, **kwargs): return AddonThread(self.core.threadManager, function, args, kwargs) + def activePlugins(self): """ returns all active plugins """ return [x for x in self.plugins if x.isActivated()] + def getAllInfo(self): - """returns info stored by hook plugins""" + """returns info stored by addon plugins""" info = {} for name, plugin in self.pluginMap.iteritems(): if plugin.info: @@ -244,6 +266,7 @@ class AddonManager(object): [(x, str(y) if not isinstance(y, basestring) else y) for x, y in plugin.info.iteritems()]) return info + def getInfo(self, plugin): info = {} if plugin in self.pluginMap and self.pluginMap[plugin].info: @@ -251,6 +274,7 @@ class AddonManager(object): for x, y in self.pluginMap[plugin].info.iteritems()) return info + def addEvent(self, event, func): """Adds an event listener for event name""" if event in self.events: @@ -258,11 +282,13 @@ class AddonManager(object): else: self.events[event] = [func] + def removeEvent(self, event, func): """removes previously added event listener""" if event in self.events: self.events[event].remove(func) + def dispatchEvent(self, event, *args): """dispatches event with args""" if event in self.events: diff --git a/pyload/manager/CaptchaManager.py b/pyload/manager/CaptchaManager.py index 1a1d2f6bf..e54eacf30 100644 --- a/pyload/manager/CaptchaManager.py +++ b/pyload/manager/CaptchaManager.py @@ -52,7 +52,7 @@ class CaptchaManager(object): for plugin in self.core.addonManager.activePlugins(): try: - plugin.newCaptchaTask(task) + plugin.captchaTask(task) except Exception: if self.core.debug: print_exc() diff --git a/pyload/plugins/Addon.py b/pyload/plugins/Addon.py index 43743848a..1c3049c10 100644 --- a/pyload/plugins/Addon.py +++ b/pyload/plugins/Addon.py @@ -41,7 +41,7 @@ class Addon(Base): #: automatically register event listeners for functions, attribute will be deleted dont use it yourself event_map = {} - # Alternative to event_map + # Deprecated alternative to event_map #: List of events the plugin can handle, name the functions exactly like eventname. event_list = [] #@NOTE: dont make duplicate entries in event_map diff --git a/pyload/plugins/Plugin.py b/pyload/plugins/Plugin.py index 77ae50123..07797e8c6 100644 --- a/pyload/plugins/Plugin.py +++ b/pyload/plugins/Plugin.py @@ -618,7 +618,7 @@ class Plugin(Base): filename = join(location, name) - self.core.addonManager.dispatchEvent("downloadStarts", self.pyfile, url, filename) + self.core.addonManager.dispatchEvent("download-start", self.pyfile, url, filename) try: newname = self.req.httpDownload(url, filename, get=get, post=post, ref=ref, cookies=cookies, diff --git a/pyload/plugins/addon/ExternalScripts.py b/pyload/plugins/addon/ExternalScripts.py index e6ee6a765..a2d7b8d86 100644 --- a/pyload/plugins/addon/ExternalScripts.py +++ b/pyload/plugins/addon/ExternalScripts.py @@ -20,13 +20,17 @@ class ExternalScripts(Addon): __description = """Run external scripts""" __license = "GPLv3" __authors = [("mkaay", "mkaay@mkaay.de"), - ("RaNaN", "ranan@pyload.org"), - ("spoob", "spoob@pyload.org"), - ("Walter Purcaro", "vuolter@gmail.com")] + ("RaNaN", "ranan@pyload.org"), + ("spoob", "spoob@pyload.org"), + ("Walter Purcaro", "vuolter@gmail.com")] - event_list = ["archive_extracted", "package_extracted", "all_archives_extracted", "all_archives_processed", - "allDownloadsFinished", "allDownloadsProcessed"] + event_map = {'archive-extracted' : "archive_extracted", + 'package-extracted' : "package_extracted", + 'all_archives-extracted' : "all_archives_extracted", + 'all_archives-processed' : "all_archives_processed", + 'all_downloads-finished' : "allDownloadsFinished", + 'all_downloads-processed': "allDownloadsProcessed"} def setup(self): diff --git a/pyload/plugins/addon/ExtractArchive.py b/pyload/plugins/addon/ExtractArchive.py index 135e460c3..15224eba5 100644 --- a/pyload/plugins/addon/ExtractArchive.py +++ b/pyload/plugins/addon/ExtractArchive.py @@ -76,11 +76,11 @@ class ExtractArchive(Addon): __description = """Extract different kind of archives""" __license = "GPLv3" __authors = [("RaNaN", "ranan@pyload.org"), - ("AndroKev", None), - ("Walter Purcaro", "vuolter@gmail.com")] + ("AndroKev", None), + ("Walter Purcaro", "vuolter@gmail.com")] - event_list = ["allDownloadsProcessed"] + event_map = {'all_downloads-processed': "allDownloadsProcessed"} def setup(self): @@ -138,8 +138,8 @@ class ExtractArchive(Addon): local = copy(self.queue) del self.queue[:] if self.extract(local, thread): #: check only if all gone fine, no failed reporting for now - self.manager.dispatchEvent("all_archives_extracted") - self.manager.dispatchEvent("all_archives_processed") + self.manager.dispatchEvent("all_archives-extracted") + self.manager.dispatchEvent("all_archives-processed") def extract(self, ids, thread=None): @@ -224,10 +224,10 @@ class ExtractArchive(Addon): if matched: if success: extracted.append(pid) - self.manager.dispatchEvent("package_extracted", p) + self.manager.dispatchEvent("package-extracted", p) else: failed.append(pid) - self.manager.dispatchEvent("package_extract_failed", p) + self.manager.dispatchEvent("package-extract_failed", p) else: self.logInfo(_("No files found to extract")) @@ -287,7 +287,7 @@ class ExtractArchive(Addon): self.logInfo(basename(plugin.file), _("Extracting finished")) extracted_files = plugin.getExtractedFiles() - self.manager.dispatchEvent("archive_extracted", pyfile, plugin.out, plugin.file, extracted_files) + self.manager.dispatchEvent("archive-extracted", pyfile, plugin.out, plugin.file, extracted_files) return extracted_files @@ -300,7 +300,7 @@ class ExtractArchive(Addon): print_exc() self.logError(basename(plugin.file), _("Unknown Error"), e) - self.manager.dispatchEvent("archive_extract_failed", pyfile) + self.manager.dispatchEvent("archive-extract_failed", pyfile) raise Exception(_("Extract failed")) diff --git a/pyload/plugins/addon/RestartSlow.py b/pyload/plugins/addon/RestartSlow.py index 2f1657154..61d842b7d 100644 --- a/pyload/plugins/addon/RestartSlow.py +++ b/pyload/plugins/addon/RestartSlow.py @@ -21,7 +21,7 @@ class RestartSlow(Addon): __authors = [("Walter Purcaro", "vuolter@gmail.com")] - event_list = ["downloadStarts"] + event_map = {'download-start': "downloadStarts"} def setup(self): |