Blocklist: check for updates iff interval > 0

This commit is contained in:
John Garland 2012-02-29 12:18:24 +11:00
parent eb773bba2c
commit 00ebaae67a
1 changed files with 10 additions and 8 deletions

View File

@ -97,12 +97,13 @@ class Core(CorePluginBase):
update_now = False
if self.config["load_on_start"]:
self.pause_session()
if self.config["check_after_days"] > 0:
if self.config["last_update"]:
last_update = datetime.fromtimestamp(self.config["last_update"])
check_period = timedelta(days=self.config["check_after_days"])
if not self.config["last_update"] or last_update + check_period < datetime.now():
update_now = True
else:
if not update_now:
d = self.import_list(deluge.configmanager.get_config_dir("blocklist.cache"))
d.addCallbacks(self.on_import_complete, self.on_import_error)
if self.need_to_resume_session:
@ -110,6 +111,7 @@ class Core(CorePluginBase):
# This function is called every 'check_after_days' days, to download
# and import a new list if needed.
if self.config["check_after_days"] > 0:
self.update_timer = LoopingCall(self.check_import)
self.update_timer.start(self.config["check_after_days"] * 24 * 60 * 60, update_now)