From 958bf611f5d9d117f19f824990ec6fd6b537e967 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Thu, 22 Dec 2011 23:45:38 +0100 Subject: accountmanager v2, delete your accounts.conf and re-enter them in pyload, new nice debug functions, try core.shell() and core.breakpoint() --- module/interaction/EventManager.py | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 module/interaction/EventManager.py (limited to 'module/interaction/EventManager.py') diff --git a/module/interaction/EventManager.py b/module/interaction/EventManager.py new file mode 100644 index 000000000..c45c388f3 --- /dev/null +++ b/module/interaction/EventManager.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +from time import time + +from PullEvents import ReloadAllEvent +from module.utils import uniqify + +class EventManager: + def __init__(self, core): + self.core = core + self.clients = [] + + def newClient(self, uuid): + self.clients.append(Client(uuid)) + + def clean(self): + for n, client in enumerate(self.clients): + if client.lastActive + 30 < time(): + del self.clients[n] + + def getEvents(self, uuid): + events = [] + validUuid = False + for client in self.clients: + if client.uuid == uuid: + client.lastActive = time() + validUuid = True + while client.newEvents(): + events.append(client.popEvent().toList()) + break + if not validUuid: + self.newClient(uuid) + events = [ReloadAllEvent("queue").toList(), ReloadAllEvent("collector").toList()] + return uniqify(events, repr) + + def addEvent(self, event): + for client in self.clients: + client.addEvent(event) + + +class Client: + def __init__(self, uuid): + self.uuid = uuid + self.lastActive = time() + self.events = [] + + def newEvents(self): + return len(self.events) > 0 + + def popEvent(self): + if not len(self.events): + return None + return self.events.pop(0) + + def addEvent(self, event): + self.events.append(event) \ No newline at end of file -- 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/interaction/EventManager.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'module/interaction/EventManager.py') diff --git a/module/interaction/EventManager.py b/module/interaction/EventManager.py index c45c388f3..0c4fc80c9 100644 --- a/module/interaction/EventManager.py +++ b/module/interaction/EventManager.py @@ -36,6 +36,9 @@ class EventManager: for client in self.clients: client.addEvent(event) + def dispatchEvent(self, *args): + pass + class Client: def __init__(self, uuid): -- cgit v1.2.3 From 5a3e5a8228e4c5421b44d18c9c9ae2f1fe616400 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 1 Jan 2012 18:01:25 +0100 Subject: fixed imports --- module/interaction/EventManager.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'module/interaction/EventManager.py') diff --git a/module/interaction/EventManager.py b/module/interaction/EventManager.py index 0c4fc80c9..8a80553cf 100644 --- a/module/interaction/EventManager.py +++ b/module/interaction/EventManager.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- from time import time -from PullEvents import ReloadAllEvent from module.utils import uniqify class EventManager: @@ -55,4 +54,4 @@ class Client: return self.events.pop(0) def addEvent(self, event): - self.events.append(event) \ No newline at end of file + self.events.append(event) -- 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/interaction/EventManager.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'module/interaction/EventManager.py') diff --git a/module/interaction/EventManager.py b/module/interaction/EventManager.py index 8a80553cf..931f50446 100644 --- a/module/interaction/EventManager.py +++ b/module/interaction/EventManager.py @@ -4,6 +4,28 @@ from time import time from module.utils import uniqify class EventManager: + """ + Handles all Event related task, also stores an Event queue for clients, so they can retrieve them later. + + **Known Events:** + Most hook methods exists as events. These are some 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 sec,opt,value The config was changed. + ===================== ============== ================================== + + | Notes: + | allDownloadsProcessed is *always* called before allDownloadsFinished. + | configChanged is *always* called before pluginConfigChanged. + """ def __init__(self, core): self.core = core self.clients = [] -- 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/interaction/EventManager.py | 151 ++++++++++++++++++++++++------------- 1 file changed, 100 insertions(+), 51 deletions(-) (limited to 'module/interaction/EventManager.py') diff --git a/module/interaction/EventManager.py b/module/interaction/EventManager.py index 931f50446..38faa3c46 100644 --- a/module/interaction/EventManager.py +++ b/module/interaction/EventManager.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -from time import time -from module.utils import uniqify +from traceback import print_exc +from time import time class EventManager: """ @@ -10,70 +10,119 @@ class EventManager: **Known Events:** Most hook methods exists as events. These are some 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 sec,opt,value The config was changed. - ===================== ============== ================================== + ===================== ================ =========================================================== + Name Arguments Description + ===================== ================ =========================================================== + metaEvent eventName, *args Called for every event, with eventName and orginal args + 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 sec, opt, value The config was changed. + ===================== ================ =========================================================== | Notes: | allDownloadsProcessed is *always* called before allDownloadsFinished. | configChanged is *always* called before pluginConfigChanged. """ + + CLIENT_EVENTS = ("packageUpdated", "packageInserted", "linkUpdated", "packageDeleted") + def __init__(self, core): self.core = core - self.clients = [] - - def newClient(self, uuid): - self.clients.append(Client(uuid)) + self.log = core.log - def clean(self): - for n, client in enumerate(self.clients): - if client.lastActive + 30 < time(): - del self.clients[n] + # uuid : list of events + self.clients = {} + self.events = {"metaEvent": []} def getEvents(self, uuid): - events = [] - validUuid = False - for client in self.clients: - if client.uuid == uuid: - client.lastActive = time() - validUuid = True - while client.newEvents(): - events.append(client.popEvent().toList()) - break - if not validUuid: - self.newClient(uuid) - events = [ReloadAllEvent("queue").toList(), ReloadAllEvent("collector").toList()] - return uniqify(events, repr) - - def addEvent(self, event): - for client in self.clients: - client.addEvent(event) - - def dispatchEvent(self, *args): - pass + """ Get accumulated events for uuid since last call, this also registeres new client """ + if uuid not in self.clients: + self.clients[uuid] = Client() + return self.clients[uuid].get() + + def addEvent(self, event, func): + """Adds an event listener for event name""" + if event in self.events: + if func in self.events[event]: + self.log.debug("Function already registered %s" % func) + else: + self.events[event].append(func) + 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""" + for f in self.events["metaEvent"]: + try: + f(event, *args) + except Exception, e: + self.log.warning("Error calling event handler %s: %s, %s, %s" + % ("metaEvent", f, args, str(e))) + if self.core.debug: + print_exc() + + if event in self.events: + for f in self.events[event]: + try: + f(*args) + except Exception, e: + self.log.warning("Error calling event handler %s: %s, %s, %s" + % (event, f, args, str(e))) + if self.core.debug: + print_exc() + + # append to client event queue + if event in self.CLIENT_EVENTS: + for uuid, client in self.clients.items(): + if client.delete(): + del self.clients[uuid] + else: + client.append(event, args) + + + def removeFromEvents(self, func): + """ Removes func from all known events """ + for name, events in self.events.iteritems(): + if func in events: + events.remove(func) + class Client: - def __init__(self, uuid): - self.uuid = uuid + + # delete clients after this time + TIMEOUT = 60 * 60 + # max events, if this value is reached you should assume that older events were dropped + MAX = 30 + + def __init__(self): self.lastActive = time() self.events = [] - def newEvents(self): - return len(self.events) > 0 + def delete(self): + return self.lastActive + self.TIMEOUT < time() + + def append(self, event, args): + ev = (event, args) + if ev not in self.events: + self.events.insert(0, ev) - def popEvent(self): - if not len(self.events): - return None - return self.events.pop(0) + del self.events[self.MAX:] + + + def get(self): + self.lastActive = time() + + events = self.events + self.events = [] - def addEvent(self, event): - self.events.append(event) + return [(ev, [str(x) for x in args]) for ev, args in events] \ No newline at end of file -- 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/interaction/EventManager.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'module/interaction/EventManager.py') diff --git a/module/interaction/EventManager.py b/module/interaction/EventManager.py index 38faa3c46..02ecb82fb 100644 --- a/module/interaction/EventManager.py +++ b/module/interaction/EventManager.py @@ -1,14 +1,17 @@ # -*- coding: utf-8 -*- +from threading import Lock from traceback import print_exc from time import time +from module.utils import lock + class EventManager: """ Handles all Event related task, also stores an Event queue for clients, so they can retrieve them later. **Known Events:** - Most hook methods exists as events. These are some additional known events. + Most addon methods exists as events. These are some additional known events. ===================== ================ =========================================================== Name Arguments Description @@ -38,6 +41,8 @@ class EventManager: self.clients = {} self.events = {"metaEvent": []} + self.lock = Lock() + def getEvents(self, uuid): """ Get accumulated events for uuid since last call, this also registeres new client """ if uuid not in self.clients: @@ -80,6 +85,10 @@ class EventManager: if self.core.debug: print_exc() + self.updateClients(event, args) + + @lock + def updateClients(self, event, args): # append to client event queue if event in self.CLIENT_EVENTS: for uuid, client in self.clients.items(): @@ -88,7 +97,6 @@ class EventManager: else: client.append(event, args) - def removeFromEvents(self, func): """ Removes func from all known events """ for name, events in self.events.iteritems(): -- cgit v1.2.3 From b40b32ee05f611323a7827fad2a25fa0a28dcb24 Mon Sep 17 00:00:00 2001 From: X3n0m0rph59 Date: Sun, 22 Apr 2012 19:56:17 +0200 Subject: a huge pile of spelling fixes --- module/interaction/EventManager.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'module/interaction/EventManager.py') diff --git a/module/interaction/EventManager.py b/module/interaction/EventManager.py index 02ecb82fb..976a92413 100644 --- a/module/interaction/EventManager.py +++ b/module/interaction/EventManager.py @@ -8,20 +8,20 @@ from module.utils import lock class EventManager: """ - Handles all Event related task, also stores an Event queue for clients, so they can retrieve them later. + Handles all event-related tasks, also stores an event queue for clients, so they can retrieve them later. **Known Events:** - Most addon methods exists as events. These are some additional known events. + Most addon methods exist as events. These are some additional known events. ===================== ================ =========================================================== Name Arguments Description ===================== ================ =========================================================== - metaEvent eventName, *args Called for every event, with eventName and orginal args + metaEvent eventName, *args Called for every event, with eventName and original args 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. + downloadStarts fid A plugin will immediately start the download afterwards. + linksAdded links, pid Someone just added links, you are able to modify these links. + allDownloadsProcessed All links were handled, pyLoad would idle afterwards. + allDownloadsFinished All downloads in the queue are finished. unrarFinished folder, fname An Unrar job finished configChanged sec, opt, value The config was changed. ===================== ================ =========================================================== @@ -44,7 +44,7 @@ class EventManager: self.lock = Lock() def getEvents(self, uuid): - """ Get accumulated events for uuid since last call, this also registeres new client """ + """ Get accumulated events for uuid since last call, this also registers a new client """ if uuid not in self.clients: self.clients[uuid] = Client() return self.clients[uuid].get() -- cgit v1.2.3