From 64e8a34940abba5889e88e9269fb40d05c8c5f97 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sat, 19 Jul 2008 22:37:40 +0000 Subject: [PATCH] Blocklist updates --- deluge/plugins/blocklist/blocklist/core.py | 13 ++++++++++--- deluge/plugins/blocklist/blocklist/gtkui.py | 8 ++++++-- deluge/plugins/init.py | 3 +++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/deluge/plugins/blocklist/blocklist/core.py b/deluge/plugins/blocklist/blocklist/core.py index 51ce0af79..2549c7f93 100644 --- a/deluge/plugins/blocklist/blocklist/core.py +++ b/deluge/plugins/blocklist/blocklist/core.py @@ -76,7 +76,13 @@ class Core(CorePluginBase): self.config = deluge.configmanager.ConfigManager("blocklist.conf", DEFAULT_PREFS) 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 diff --git a/deluge/plugins/blocklist/blocklist/gtkui.py b/deluge/plugins/blocklist/blocklist/gtkui.py index 35e423b18..7fec00ebf 100644 --- a/deluge/plugins/blocklist/blocklist/gtkui.py +++ b/deluge/plugins/blocklist/blocklist/gtkui.py @@ -48,10 +48,10 @@ 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") - + # Register some hooks self.plugin.register_hook("on_apply_prefs", self._on_apply_prefs) self.plugin.register_hook("on_show_prefs", self._on_show_prefs) @@ -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) diff --git a/deluge/plugins/init.py b/deluge/plugins/init.py index bbc5a398a..9a9098093 100644 --- a/deluge/plugins/init.py +++ b/deluge/plugins/init.py @@ -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: