From 6eae782f13953dd0ba2bbe1b582cf33fd4d7d90a Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 19 Dec 2011 23:10:49 +0100 Subject: configparser v2, warning CONFIG will be DELETED. --- module/plugins/Hook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/Hook.py') diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py index 5efd08bae..860dc76bb 100644 --- a/module/plugins/Hook.py +++ b/module/plugins/Hook.py @@ -119,7 +119,7 @@ class Hook(Base): def isActivated(self): """ checks if hook is activated""" - return self.config.getPlugin(self.__name__, "activated") + return self.config.get(self.__name__, "activated") #event methods - overwrite these if needed -- cgit v1.2.3 From d35c003cc53d4723d1dfe0d81eeb9bea78cee594 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 31 Dec 2011 16:01:24 +0100 Subject: new crypter plugin API, now decrypting possible for now. --- module/plugins/Hook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/Hook.py') diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py index 860dc76bb..a3b86a794 100644 --- a/module/plugins/Hook.py +++ b/module/plugins/Hook.py @@ -20,7 +20,7 @@ from traceback import print_exc -from Plugin import Base +from Base import Base class Expose(object): """ used for decoration to declare rpc services """ -- cgit v1.2.3 From 18466eb7f8f3cd4ca9a0824074d2ff454939fce6 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Wed, 4 Jan 2012 17:23:13 +0100 Subject: some fixes --- module/plugins/Hook.py | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) (limited to 'module/plugins/Hook.py') diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py index a3b86a794..fe464bdaa 100644 --- a/module/plugins/Hook.py +++ b/module/plugins/Hook.py @@ -14,8 +14,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, see . - @author: mkaay - @interface-version: 0.2 + @author: RaNaN """ from traceback import print_exc @@ -24,11 +23,24 @@ from Base import Base class Expose(object): """ used for decoration to declare rpc services """ - def __new__(cls, f, *args, **kwargs): hookManager.addRPC(f.__module__, f.func_name, f.func_doc) return f +def AddEventListener(event): + """ used to register method for events """ + class _klass(object): + def __new__(cls, f, *args, **kwargs): + hookManager.addEventListener(f.__module__, f.func_name, event) + return f + return _klass + +class ConfigHandler(object): + """ register method as config handler """ + def __new__(cls, f, *args, **kwargs): + hookManager.addConfigHandler(f.__module__, f.func_name) + return f + def threaded(f): def run(*args,**kwargs): hookManager.startThread(f, *args, **kwargs) @@ -38,14 +50,6 @@ class Hook(Base): """ Base class for hook plugins. """ - __name__ = "Hook" - __version__ = "0.2" - __type__ = "hook" - __threaded__ = [] - __config__ = [ ("name", "type", "desc" , "default") ] - __description__ = """interface for hook""" - __author_name__ = ("mkaay", "RaNaN") - __author_mail__ = ("mkaay@mkaay.de", "RaNaN@pyload.org") #: automatically register event listeners for functions, attribute will be deleted dont use it yourself event_map = None @@ -108,7 +112,11 @@ class Hook(Base): def __repr__(self): return "" % self.__name__ - + + def isActivated(self): + """ checks if hook is activated""" + return self.getConfig("activated") + def setup(self): """ more init stuff if needed """ pass @@ -116,11 +124,12 @@ class Hook(Base): def unload(self): """ called when hook was deactivated """ pass - - def isActivated(self): - """ checks if hook is activated""" - return self.config.get(self.__name__, "activated") - + + def deactivate(self): + pass + + def activate(self): + pass #event methods - overwrite these if needed def coreReady(self): @@ -134,10 +143,7 @@ class Hook(Base): def downloadFinished(self, pyfile): pass - - def downloadFailed(self, pyfile): - pass - + def packageFinished(self, pypack): pass -- cgit v1.2.3 From b877847094b0ba03a098dff0fd769eb456b48dd1 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Fri, 6 Jan 2012 17:54:53 +0100 Subject: several improvements, also closes #486, #487 --- module/plugins/Hook.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'module/plugins/Hook.py') diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py index fe464bdaa..76bc19dbe 100644 --- a/module/plugins/Hook.py +++ b/module/plugins/Hook.py @@ -19,6 +19,9 @@ from traceback import print_exc +from functools import wraps +from module.utils import has_method + from Base import Base class Expose(object): @@ -35,6 +38,7 @@ def AddEventListener(event): return f return _klass + class ConfigHandler(object): """ register method as config handler """ def __new__(cls, f, *args, **kwargs): @@ -42,13 +46,14 @@ class ConfigHandler(object): return f def threaded(f): + @wraps(f) def run(*args,**kwargs): hookManager.startThread(f, *args, **kwargs) return run class Hook(Base): """ - Base class for hook plugins. + Base class for hook plugins. Please use @threaded decorator for all longer running task. """ #: automatically register event listeners for functions, attribute will be deleted dont use it yourself @@ -79,16 +84,16 @@ class Hook(Base): for event, funcs in self.event_map.iteritems(): if type(funcs) in (list, tuple): for f in funcs: - self.manager.addEvent(event, getattr(self,f)) + self.evm.addEvent(event, getattr(self,f)) else: - self.manager.addEvent(event, getattr(self,funcs)) + self.evm.addEvent(event, getattr(self,funcs)) #delete for various reasons self.event_map = None if self.event_list: for f in self.event_list: - self.manager.addEvent(f, getattr(self,f)) + self.evm.addEvent(f, getattr(self,f)) self.event_list = None @@ -121,23 +126,16 @@ class Hook(Base): """ more init stuff if needed """ pass - def unload(self): - """ called when hook was deactivated """ - pass - - def deactivate(self): - pass - def activate(self): - pass + """ Used to activate the hook """ + if has_method(self.__class__, "coreReady"): + self.logDebug("Deprecated method .coreReady() use activated() instead") + self.coreReady() - #event methods - overwrite these if needed - def coreReady(self): + def deactivate(self): + """ Used to deactivate the hook. """ pass - def coreExiting(self): - pass - def downloadPreparing(self, pyfile): pass -- cgit v1.2.3 From 1bb6ebf544b43cacf7c0755c5a8608b79b95e2d6 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 7 Jan 2012 20:11:16 +0100 Subject: MultiHoster plugin type, some fixes, new documentation structure --- module/plugins/Hook.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'module/plugins/Hook.py') diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py index 76bc19dbe..c1090aa70 100644 --- a/module/plugins/Hook.py +++ b/module/plugins/Hook.py @@ -136,30 +136,31 @@ class Hook(Base): """ Used to deactivate the hook. """ pass - def downloadPreparing(self, pyfile): + def periodical(self): pass - - def downloadFinished(self, pyfile): + + def newCaptchaTask(self, task): + """ new captcha task for the plugin, it MUST set the handler and timeout or will be ignored """ pass - def packageFinished(self, pypack): + def captchaCorrect(self, task): pass - def beforeReconnecting(self, ip): + def captchaInvalid(self, task): pass - - def afterReconnecting(self, ip): + + # public events starts from here + def downloadPreparing(self, pyfile): pass - def periodical(self): + def downloadFinished(self, pyfile): pass - def newCaptchaTask(self, task): - """ new captcha task for the plugin, it MUST set the handler and timeout or will be ignored """ + def packageFinished(self, pypack): pass - def captchaCorrect(self, task): + def beforeReconnecting(self, ip): pass - - def captchaInvalid(self, task): + + def afterReconnecting(self, ip): pass \ No newline at end of file -- cgit v1.2.3 From 6eaa7bb25e2254c80c43fe46166142d590e86c64 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 7 Jan 2012 23:58:28 +0100 Subject: some cleanups --- module/plugins/Hook.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'module/plugins/Hook.py') diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py index c1090aa70..6e2057f03 100644 --- a/module/plugins/Hook.py +++ b/module/plugins/Hook.py @@ -156,6 +156,9 @@ class Hook(Base): def downloadFinished(self, pyfile): pass + def downloadFailed(self, pyfile): + pass + def packageFinished(self, pypack): pass -- cgit v1.2.3 From bac28b7740aae772636d8b90e291d9c17dfd59a7 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 8 Jan 2012 14:44:59 +0100 Subject: new MultiHoster hook --- module/plugins/Hook.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'module/plugins/Hook.py') diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py index 6e2057f03..c0ce7d99c 100644 --- a/module/plugins/Hook.py +++ b/module/plugins/Hook.py @@ -98,6 +98,7 @@ class Hook(Base): self.event_list = None self.initPeriodical() + self.init() self.setup() def initPeriodical(self): @@ -122,6 +123,9 @@ class Hook(Base): """ checks if hook is activated""" return self.getConfig("activated") + def init(self): + pass + def setup(self): """ more init stuff if needed """ pass -- cgit v1.2.3 From 1ecdd9f6b53fec45e1d48592e3ff56aa7a576bec Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 8 Jan 2012 16:47:52 +0100 Subject: some cleanups, closed #490 --- module/plugins/Hook.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'module/plugins/Hook.py') diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py index c0ce7d99c..83ef091ae 100644 --- a/module/plugins/Hook.py +++ b/module/plugins/Hook.py @@ -19,22 +19,25 @@ from traceback import print_exc -from functools import wraps +#from functools import wraps from module.utils import has_method from Base import Base +def class_name(p): + return p.rpartition(".")[2] + class Expose(object): """ used for decoration to declare rpc services """ def __new__(cls, f, *args, **kwargs): - hookManager.addRPC(f.__module__, f.func_name, f.func_doc) + hookManager.addRPC(class_name(f.__module__), f.func_name, f.func_doc) return f def AddEventListener(event): """ used to register method for events """ class _klass(object): def __new__(cls, f, *args, **kwargs): - hookManager.addEventListener(f.__module__, f.func_name, event) + hookManager.addEventListener(class_name(f.__module__), f.func_name, event) return f return _klass @@ -42,11 +45,11 @@ def AddEventListener(event): class ConfigHandler(object): """ register method as config handler """ def __new__(cls, f, *args, **kwargs): - hookManager.addConfigHandler(f.__module__, f.func_name) + hookManager.addConfigHandler(class_name(f.__module__), f.func_name) return f def threaded(f): - @wraps(f) + #@wraps(f) def run(*args,**kwargs): hookManager.startThread(f, *args, **kwargs) return run -- cgit v1.2.3 From d7eef2c28eae2e43e3ade4441810ecc0cdea6fd7 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 5 Feb 2012 21:21:36 +0100 Subject: option for internal plugins --- module/plugins/Hook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/Hook.py') diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py index 83ef091ae..22765c525 100644 --- a/module/plugins/Hook.py +++ b/module/plugins/Hook.py @@ -124,7 +124,7 @@ class Hook(Base): def isActivated(self): """ checks if hook is activated""" - return self.getConfig("activated") + return True if self.__internal__ else self.getConfig("activated") def init(self): pass -- cgit v1.2.3 From 4df2b77fdf42046fe19bd371be7c7255986b5980 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Tue, 6 Mar 2012 13:36:39 +0100 Subject: renamed hooks to addons, new filemanager and database, many new api methods you will loose ALL your LINKS, webinterface will NOT work --- module/plugins/Hook.py | 176 ------------------------------------------------- 1 file changed, 176 deletions(-) delete mode 100644 module/plugins/Hook.py (limited to 'module/plugins/Hook.py') diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py deleted file mode 100644 index 22765c525..000000000 --- a/module/plugins/Hook.py +++ /dev/null @@ -1,176 +0,0 @@ -# -*- 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: RaNaN -""" - -from traceback import print_exc - -#from functools import wraps -from module.utils import has_method - -from Base import Base - -def class_name(p): - return p.rpartition(".")[2] - -class Expose(object): - """ used for decoration to declare rpc services """ - def __new__(cls, f, *args, **kwargs): - hookManager.addRPC(class_name(f.__module__), f.func_name, f.func_doc) - return f - -def AddEventListener(event): - """ used to register method for events """ - class _klass(object): - def __new__(cls, f, *args, **kwargs): - hookManager.addEventListener(class_name(f.__module__), f.func_name, event) - return f - return _klass - - -class ConfigHandler(object): - """ register method as config handler """ - def __new__(cls, f, *args, **kwargs): - hookManager.addConfigHandler(class_name(f.__module__), f.func_name) - return f - -def threaded(f): - #@wraps(f) - def run(*args,**kwargs): - hookManager.startThread(f, *args, **kwargs) - return run - -class Hook(Base): - """ - Base class for hook plugins. Please use @threaded decorator for all longer running task. - """ - - #: automatically register event listeners for functions, attribute will be deleted dont use it yourself - event_map = None - - # Alternative to event_map - #: List of events the plugin can handle, name the functions exactly like eventname. - event_list = None # dont make duplicate entries in event_map - - - #: periodic call interval in secondc - interval = 60 - - def __init__(self, core, manager): - Base.__init__(self, core) - - #: Provide information in dict here, usable by API `getInfo` - self.info = None - - #: Callback of periodical job task, used by hookmanager - self.cb = None - - #: `HookManager` - self.manager = manager - - #register events - if self.event_map: - for event, funcs in self.event_map.iteritems(): - if type(funcs) in (list, tuple): - for f in funcs: - self.evm.addEvent(event, getattr(self,f)) - else: - self.evm.addEvent(event, getattr(self,funcs)) - - #delete for various reasons - self.event_map = None - - if self.event_list: - for f in self.event_list: - self.evm.addEvent(f, getattr(self,f)) - - self.event_list = None - - self.initPeriodical() - self.init() - self.setup() - - def initPeriodical(self): - if self.interval >=1: - self.cb = self.core.scheduler.addJob(0, self._periodical, threaded=False) - - def _periodical(self): - try: - if self.isActivated(): self.periodical() - except Exception, e: - self.core.log.error(_("Error executing hooks: %s") % str(e)) - if self.core.debug: - print_exc() - - self.cb = self.core.scheduler.addJob(self.interval, self._periodical, threaded=False) - - - def __repr__(self): - return "" % self.__name__ - - def isActivated(self): - """ checks if hook is activated""" - return True if self.__internal__ else self.getConfig("activated") - - def init(self): - pass - - def setup(self): - """ more init stuff if needed """ - pass - - def activate(self): - """ Used to activate the hook """ - if has_method(self.__class__, "coreReady"): - self.logDebug("Deprecated method .coreReady() use activated() instead") - self.coreReady() - - def deactivate(self): - """ Used to deactivate the hook. """ - pass - - def periodical(self): - pass - - def newCaptchaTask(self, task): - """ new captcha task for the plugin, it MUST set the handler and timeout or will be ignored """ - pass - - def captchaCorrect(self, task): - pass - - def captchaInvalid(self, task): - pass - - # public events starts from here - def downloadPreparing(self, pyfile): - pass - - def downloadFinished(self, pyfile): - pass - - def downloadFailed(self, pyfile): - pass - - def packageFinished(self, pypack): - pass - - def beforeReconnecting(self, ip): - pass - - def afterReconnecting(self, ip): - pass \ No newline at end of file -- cgit v1.2.3