summaryrefslogtreecommitdiffstats
path: root/pyload/plugin/addon/DeleteFinished.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/plugin/addon/DeleteFinished.py')
-rw-r--r--pyload/plugin/addon/DeleteFinished.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/pyload/plugin/addon/DeleteFinished.py b/pyload/plugin/addon/DeleteFinished.py
new file mode 100644
index 000000000..045f58d61
--- /dev/null
+++ b/pyload/plugin/addon/DeleteFinished.py
@@ -0,0 +1,79 @@
+# -*- coding: utf-8 -*-
+
+from pyload.database import style
+from pyload.plugin.Addon import Addon
+
+
+class DeleteFinished(Addon):
+ __name = "DeleteFinished"
+ __type = "addon"
+ __version = "1.11"
+
+ __config = [('interval' , 'int' , 'Delete every (hours)' , '72' ),
+ ('deloffline', 'bool', 'Delete packages with offline links', 'False')]
+
+ __description = """Automatically delete all finished packages from queue"""
+ __license = "GPLv3"
+ __authors = [("Walter Purcaro", "vuolter@gmail.com")]
+
+
+ # event_list = ["pluginConfigChanged"]
+
+
+ ## overwritten methods ##
+ def periodical(self):
+ 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):
+ if name == "interval" and value != self.interval:
+ self.interval = value * 3600
+ self.initPeriodical()
+
+
+ def deactivate(self):
+ self.removeEvent('packageFinished', self.wakeup)
+
+
+ def activate(self):
+ self.info = {'sleep': True}
+ interval = self.getConfig('interval')
+ self.pluginConfigChanged(self.__name, 'interval', interval)
+ self.addEvent('packageFinished', self.wakeup)
+
+
+ ## own methods ##
+ @style.queue
+ 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.removeEvent('packageFinished', self.wakeup)
+ self.info['sleep'] = False
+
+
+ ## event managing ##
+ 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", func)
+ else:
+ self.m.events[event].append(func)
+ else:
+ self.m.events[event] = [func]
+
+
+ def setup(self):
+ self.interval = 0
+ self.m = self.manager
+ self.removeEvent = self.m.removeEvent