diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-12-20 18:29:46 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-12-27 22:44:58 +0100 |
commit | e7cd581045d7c67be6c10237c162a2465e656661 (patch) | |
tree | bb6b10671da32450b4fd8cd984b24667e4d1f93f /module/plugins/internal/Addon.py | |
parent | [Account] Import new Periodical class (diff) | |
download | pyload-e7cd581045d7c67be6c10237c162a2465e656661.tar.xz |
[Addon] Import new Periodical class + code cosmetics
Diffstat (limited to 'module/plugins/internal/Addon.py')
-rw-r--r-- | module/plugins/internal/Addon.py | 137 |
1 files changed, 46 insertions, 91 deletions
diff --git a/module/plugins/internal/Addon.py b/module/plugins/internal/Addon.py index 1a7264c18..9179f59ec 100644 --- a/module/plugins/internal/Addon.py +++ b/module/plugins/internal/Addon.py @@ -3,9 +3,25 @@ import threading from module.plugins.internal.Plugin import Plugin -from module.plugins.internal.misc import isiterable +from module.plugins.internal.misc import Periodical, isiterable +def threaded(fn): + def run(*args, **kwargs): + hookManager.startThread(fn, *args, **kwargs) + + return run + + +class Expose(object): + """ + Used for decoration to declare rpc services + """ + def __new__(cls, fn, *args, **kwargs): + hookManager.addRPC(fn.__module__, fn.func_name, fn.func_doc) + return fn + + class Addon(Plugin): __name__ = "Addon" __type__ = "hook" #@TODO: Change to `addon` in 0.4.10 @@ -18,10 +34,7 @@ class Addon(Plugin): __license__ = "GPLv3" __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - - PERIODICAL_INTERVAL = None - - + def __init__(self, core, manager): self._init(core) @@ -32,15 +45,11 @@ class Addon(Plugin): #: Automatically register event listeners for functions, attribute will be deleted dont use it yourself self.event_map = {} - #: Deprecated alternative to event_map - #: List of events the plugin can handle, name the functions exactly like eventname. - self.event_list = [] #@NOTE: dont make duplicate entries in event_map - self.info['ip'] = None #@TODO: Remove in 0.4.10 #: Callback of periodical job task, used by HookManager - self.cb = None - self.interval = None + self.periodical = Periodical(self, self.periodical_task) + self.cb = self.periodical.cb #@TODO: Recheck in 0.4.10 self.init() self._init_events() #@TODO: Remove in 0.4.10 @@ -88,63 +97,13 @@ class Addon(Plugin): #: Delete for various reasons self.event_map = None - if self.event_list: - self.log_debug("Deprecated method `event_list`, use `event_map` instead") - - for f in self.event_list: - self.manager.addEvent(f, getattr(self, f)) - - self.event_list = None - - - def set_interval(self, value): - newinterval = max(0, self.PERIODICAL_INTERVAL, value) - - if newinterval != value: - return False - - if newinterval != self.interval: - self.interval = newinterval - - return True - - - def start_periodical(self, interval=None, threaded=False, delay=0): - if interval is not None and self.set_interval(interval) is False: - return False - else: - self.cb = self.pyload.scheduler.addJob(max(1, delay), self._periodical, [threaded], threaded=threaded) - return True - - def restart_periodical(self, *args, **kwargs): - self.stop_periodical() - return self.start_periodical(*args, **kwargs) - - - def stop_periodical(self): - try: - return self.pyload.scheduler.removeJob(self.cb) - finally: - self.cb = None - - - def _periodical(self, threaded): - try: - self.periodical() - - except Exception, e: - self.log_error(_("Error performing periodical task"), e) - - self.restart_periodical(threaded=threaded, delay=self.interval) - - - def periodical(self): + def periodical_task(self): raise NotImplementedError #: Deprecated method, use `activated` property instead (Remove in 0.4.10) - def isActivated(self, *args, **kwargs): + def isActivated(self): return self.activated @@ -156,9 +115,9 @@ class Addon(Plugin): #: Deprecated method, use `deactivate` instead (Remove in 0.4.10) - def unload(self, *args, **kwargs): + def unload(self): self.db.store("info", self.info) - return self.deactivate(*args, **kwargs) + return self.deactivate() def activate(self): @@ -169,13 +128,9 @@ class Addon(Plugin): #: Deprecated method, use `activate` instead (Remove in 0.4.10) - def coreReady(self, *args, **kwargs): + def coreReady(self): self.db.retrieve("info", self.info) - - if self.PERIODICAL_INTERVAL: - self.start_periodical(self.PERIODICAL_INTERVAL, delay=5) - - return self.activate(*args, **kwargs) + return self.activate() def exit(self): @@ -186,20 +141,20 @@ class Addon(Plugin): #: Deprecated method, use `exit` instead (Remove in 0.4.10) - def coreExiting(self, *args, **kwargs): - self.unload(*args, **kwargs) #@TODO: Fix in 0.4.10 - return self.exit(*args, **kwargs) + def coreExiting(self): + self.unload() #@TODO: Fix in 0.4.10 + return self.exit() - def all_downloads_finished(self): + def config_changed(self, category, option, value, section): pass - def all_downloads_processed(self): + def all_downloads_finished(self): pass - def config_changed(self, category, option, value, section): + def all_downloads_processed(self): pass @@ -230,9 +185,9 @@ class Addon(Plugin): #: Deprecated method, use `download_finished` instead (Remove in 0.4.10) - def downloadFinished(self, *args, **kwargs): + def downloadFinished(self, pyfile): if pyfile.hasStatus("finished"): #: Check if still "finished" (Fix in 0.4.10) - return self.download_finished(*args, **kwargs) + return self.download_finished(pyfile) def download_failed(self, pyfile): @@ -240,9 +195,9 @@ class Addon(Plugin): #: Deprecated method, use `download_failed` instead (Remove in 0.4.10) - def downloadFailed(self, *args, **kwargs): + def downloadFailed(self, pyfile): if pyfile.hasStatus("failed"): #: Check if still "failed" (Fix in 0.4.10) - return self.download_failed(*args, **kwargs) + return self.download_failed(pyfile) def package_processed(self, pypack): @@ -262,8 +217,8 @@ class Addon(Plugin): #: Deprecated method, use `package_finished` instead (Remove in 0.4.10) - def packageFinished(self, *args, **kwargs): - return self.package_finished(*args, **kwargs) + def packageFinished(self, pypack): + return self.package_finished(pypack) def before_reconnect(self, ip): @@ -271,8 +226,8 @@ class Addon(Plugin): #: Deprecated method, use `before_reconnect` instead (Remove in 0.4.10) - def beforeReconnecting(self, *args, **kwargs): - return self.before_reconnect(*args, **kwargs) + def beforeReconnecting(self, ip): + return self.before_reconnect(ip) def after_reconnect(self, ip, oldip): @@ -293,8 +248,8 @@ class Addon(Plugin): #: Deprecated method, use `captcha_task` instead (Remove in 0.4.10) - def newCaptchaTask(self, *args, **kwargs): - return self.captcha_task(*args, **kwargs) + def newCaptchaTask(self, task): + return self.captcha_task(task) def captcha_correct(self, task): @@ -302,8 +257,8 @@ class Addon(Plugin): #: Deprecated method, use `captcha_correct` instead (Remove in 0.4.10) - def captchaCorrect(self, *args, **kwargs): - return self.captcha_correct(*args, **kwargs) + def captchaCorrect(self, task): + return self.captcha_correct(task) def captcha_invalid(self, task): @@ -311,5 +266,5 @@ class Addon(Plugin): #: Deprecated method, use `captcha_invalid` instead (Remove in 0.4.10) - def captchaInvalid(self, *args, **kwargs): - return self.captcha_invalid(*args, **kwargs) + def captchaInvalid(self, task): + return self.captcha_invalid(task) |