Blocklist: check for updates iff interval > 0

This commit is contained in:
John Garland 2012-02-29 12:18:24 +11:00
commit 00ebaae67a

View file

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