diff options
Diffstat (limited to 'module')
-rw-r--r-- | module/plugins/hooks/DeleteFinished.py | 89 |
1 files changed, 40 insertions, 49 deletions
diff --git a/module/plugins/hooks/DeleteFinished.py b/module/plugins/hooks/DeleteFinished.py index 01cb1b8e1..155158701 100644 --- a/module/plugins/hooks/DeleteFinished.py +++ b/module/plugins/hooks/DeleteFinished.py @@ -1,6 +1,6 @@ # -*- 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, @@ -15,79 +15,70 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. @author: Walter Purcaro -""" +''' from module.database import style from module.plugins.Hook import Hook class DeleteFinished(Hook): - __name__ = "DeleteFinished" - __version__ = "1.02" - __description__ = "Automatically delete finished packages from queue" + __name__ = 'DeleteFinished' + __version__ = '1.09' + __description__ = 'Automatically delete all finished packages from queue' __config__ = [ - ("activated", "bool", "Activated", "False"), - ("interval", "int", "Delete every (hours)", "72") + ('activated', 'bool', 'Activated', 'False'), + ('interval', 'int', 'Delete every (hours)', '72'), + ('deloffline', 'bool', 'Delete packages with offline links', 'False') ] - __author_name__ = ("Walter Purcaro") - __author_mail__ = ("vuolter@gmail.com") + __author_name__ = ('Walter Purcaro') + __author_mail__ = ('vuolter@gmail.com') ## overwritten methods ## def periodical(self): - # self.logDebug("self.periodical") - if not self.info["sleep"]: - self.logInfo("self.deleteFinished") - self.deleteFinished() - self.info["sleep"] = True - self.addEvent("packageFinished", self.wakeup) + if not self.info['sleep']: + deloffline = self.getConfig('deloffline') + mode = '0,1,4' if deloffline else '0,4' + msg = 'delete all finished packages in queue list (%s packages with offline links)' + self.logInfo(msg % ('including' if deloffline else 'excluding')) + self.deleteFinished(mode) + self.info['sleep'] = True + self.addEvent('packageFinished', self.wakeup) def pluginConfigChanged(self, plugin, name, value): - # self.logDebug("self.pluginConfigChanged") - if name == "interval" and value != self.interval: - self.interval = value + if name == 'interval' and value != self.interval: + self.interval = value * 3600 self.initPeriodical() def unload(self): - # self.logDebug("self.unload") - self.removeEvent("packageFinished", self.wakeup) + self.removeEvent('packageFinished', self.wakeup) def coreReady(self): - # self.logDebug("self.coreReady") - self.info = {"sleep": True} - interval = self.getConfig("interval") * 3600 - self.pluginConfigChanged("DeleteFinished", "interval", interval) - self.addEvent("packageFinished", self.wakeup) + self.info = {'sleep': True} + interval = self.getConfig('interval') + self.pluginConfigChanged('DeleteFinished', 'interval', interval) + self.addEvent('packageFinished', self.wakeup) ## own methods ## @style.queue - def deleteFinished(self): - self.c.execute("DELETE FROM packages WHERE NOT EXISTS(SELECT 1 FROM links WHERE package=packages.id AND status NOT IN (0,4))") - self.c.execute("DELETE FROM links WHERE NOT EXISTS(SELECT 1 FROM packages WHERE id=links.package)") + def deleteFinished(self, mode): + self.c.execute('DELETE FROM packages WHERE NOT EXISTS(SELECT 1 FROM links WHERE package=packages.id AND status NOT IN (%s))' % mode) + self.c.execute('DELETE FROM links WHERE NOT EXISTS(SELECT 1 FROM packages WHERE id=links.package)') def wakeup(self, pypack): - # self.logDebug("self.wakeup") - self.removeEvent("packageFinished", self.wakeup) - self.info["sleep"] = False + self.removeEvent('packageFinished', self.wakeup) + self.info['sleep'] = False ## event managing ## - def addEvent(self, event, handler): - if event in self.manager.events: - if handler not in self.manager.events[event]: - self.manager.events[event].append(handler) - # self.logDebug("self.addEvent: " + event + ": added handler") + def addEvent(self, event, func): + '''Adds an event listener for event name''' + if event in self.m.events: + if func in self.m.events[event]: + self.logDebug('Function already registered %s' % func) else: - # self.logDebug("self.addEvent: " + event + ": NOT added handler") - return False + self.m.events[event].append(func) else: - self.manager.events[event] = [handler] - # self.logDebug("self.addEvent: " + event + ": added event and handler") - return True + self.m.events[event] = [func] - def removeEvent(self, event, handler): - if event in self.manager.events and handler in self.manager.events[event]: - self.manager.events[event].remove(handler) - # self.logDebug("self.removeEvent: " + event + ": removed handler") - return True - else: - # self.logDebug("self.removeEvent: " + event + ": NOT removed handler") - return False + def setup(self): + self.m = self.manager + self.removeEvent = self.m.removeEvent |