Blocklist updates

This commit is contained in:
Andrew Resch 2008-07-19 22:37:40 +00:00
parent 31a4c4159f
commit 64e8a34940
3 changed files with 19 additions and 5 deletions

View File

@ -77,6 +77,12 @@ class Core(CorePluginBase):
if self.config["load_on_start"]:
self.export_import(self.need_new_blocklist())
# This function is called every 'check_after_days' days, to download
# and import a new list if needed.
self.update_timer = gobject.timeout_add(
self.config["check_after_days"] * 24 * 60 * 60 * 1000,
self.download_blocklist, True)
def disable(self):
log.debug('Blocklist: Plugin disabled')
self.config.save()
@ -207,11 +213,12 @@ class Core(CorePluginBase):
"""Returns True if a new blocklist file should be downloaded"""
try:
# Check current block lists time stamp and decide if it needs to be replaced
list_stats = os.stat(self.local_blocklist)
list_stats = os.stat(deluge.configmanager.get_config_dir("blocklist.cache"))
list_time = datetime.datetime.fromtimestamp(list_stats.st_mtime)
list_size = list_stats.st_size
current_time = datetime.datetime.today()
except:
except Exception, e:
log.debug("Unable to get file stats: %s", e)
return True
# If local blocklist file exists but nothing is in it

View File

@ -48,7 +48,7 @@ class GtkUI(ui.UI):
self.status_item = component.get("StatusBar").add_item(
image=self.get_resource("blocklist16.png"),
text="0",
text="",
callback=self._on_status_item_clicked,
tooltip="Blocked IP Ranges")
@ -62,6 +62,10 @@ class GtkUI(ui.UI):
# Remove the preferences page
self.plugin.remove_preferences_page("Blocklist")
# Remove status item
component.get("StatusBar").remove_item(self.status_item)
del self.status_item
# Deregister the hooks
self.plugin.deregister_hook("on_apply_prefs", self._on_apply_prefs)
self.plugin.deregister_hook("on_show_prefs", self._on_show_prefs)

View File

@ -42,6 +42,9 @@ class PluginBase:
self.plugin.enable()
except Exception, e:
log.warning("Unable to enable plugin: %s", e)
else:
# If plugin was enabled, call it's update() right away
self.update()
def disable(self):
try: