summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Vuolter <vuolter@gmail.com> 2013-05-12 14:51:14 +0200
committerGravatar Vuolter <vuolter@gmail.com> 2013-05-12 14:55:39 +0200
commit0d76c92ebf0b4b4188b961e956ed187fc996b043 (patch)
tree9abb7b93dc781f41dec211fd1bdbb3f4ffae2083
parentMerge pull request #113 from 4Christopher/stable (diff)
downloadpyload-0d76c92ebf0b4b4188b961e956ed187fc996b043.tar.xz
Version 0.3: rewrited code and added new feature "Sleep mode"
-rw-r--r--module/plugins/hooks/DeleteFinished.py69
1 files changed, 55 insertions, 14 deletions
diff --git a/module/plugins/hooks/DeleteFinished.py b/module/plugins/hooks/DeleteFinished.py
index be83d6ced..d5b4d3345 100644
--- a/module/plugins/hooks/DeleteFinished.py
+++ b/module/plugins/hooks/DeleteFinished.py
@@ -23,25 +23,66 @@ from time import time
class DeleteFinished(Hook):
__name__ = "DeleteFinished"
- __version__ = "0.2"
+ __version__ = "0.3"
__description__ = "Automatically delete finished packages from queue"
__config__ = [
("activated", "bool", "Activated", "False"),
- ("interval", "int", "Delete every (hours)", "72")
+ ("interval", "int", "Delete every (hours)", "72"),
+ ("sleep", "bool", "Sleep mode (useful if interval is small)", "False")
]
__author_name__ = ("Walter Purcaro")
__author_mail__ = ("vuolter@gmail.com")
- #: event_map don't load periodical anyway
def periodical(self):
- now = time()
- deletetime = self.getConfig("interval") * 3600 + self.info["lastdelete"]
- if now >= deletetime:
- self.core.api.deleteFinished()
- self.logDebug("called self.core.api.deleteFinished()")
- self.info["lastdelete"] = now
-
- def setup(self):
- now = time()
- self.info = {"lastdelete": now}
- self.interval = 3600
+ # self.logDebug("self.periodical")
+ self.core.api.deleteFinished()
+ self.logDebug("called self.core.api.deleteFinished")
+ if self.getConfig("sleep"):
+ self.interval = 0
+
+ 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")
+ else:
+ # self.logDebug("self.addEvent: " + event + ": NOT added handler")
+ return False
+ else:
+ self.manager.events[event] = [handler]
+ # self.logDebug("self.addEvent: " + event + ": added event and handler")
+ return True
+
+ 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 enPeriodical(self):
+ # self.logDebug("self.enPeriodical")
+ if not self.interval:
+ self.interval = self.getConfig("interval") * 3600
+
+ def configEvents(self, plugin, name, value):
+ # self.logDebug("self.configEvents")
+ self.enPeriodical()
+ if self.getConfig("sleep"):
+ self.addEvent("packageFinished", self.enPeriodical)
+ else:
+ self.removeEvent("packageFinished", self.enPeriodical)
+
+ def unload(self):
+ # self.logDebug("self.unload")
+ self.removeEvent("pluginConfigChanged", self.configEvents)
+ self.removeEvent("packageFinished", self.enPeriodical)
+ self.interval = 0
+
+ def coreReady(self):
+ # self.logDebug("self.coreReady")
+ self.interval = 0
+ self.addEvent("pluginConfigChanged", self.configEvents)
+ self.configEvents(None, None, None)