need_new_blocklist is no longer blocking

removed download arg from import_list
updated gtkui and webui
This commit is contained in:
John Garland 2009-01-19 07:56:49 +00:00
parent 813063bd12
commit 1ec3751f91
3 changed files with 19 additions and 16 deletions

View File

@ -74,7 +74,7 @@ class Core(CorePluginBase):
self.config = deluge.configmanager.ConfigManager("blocklist.conf", DEFAULT_PREFS) self.config = deluge.configmanager.ConfigManager("blocklist.conf", DEFAULT_PREFS)
if self.config["load_on_start"]: if self.config["load_on_start"]:
self.import_list(self.need_new_blocklist()) self.import_list()
# 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.
@ -98,10 +98,10 @@ class Core(CorePluginBase):
self.download_blocklist(_import) self.download_blocklist(_import)
@export @export
def import_list(self, download=False, force=False): def import_list(self, force=False):
"""Import the blocklist from the blocklist.cache, if load is True, then """Import the blocklist from the blocklist.cache, if load is True, then
it will download the blocklist file if needed.""" it will download the blocklist file if needed."""
threading.Thread(target=self.import_blocklist, kwargs={"download": download, "force": force}).start() threading.Thread(target=self.import_blocklist, kwargs={"force": force}).start()
@export @export
def get_config(self): def get_config(self):
@ -142,15 +142,14 @@ class Core(CorePluginBase):
if load: if load:
self.import_list() self.import_list()
def import_blocklist(self, download=False, force=False): def import_blocklist(self, force=False):
"""Imports the downloaded blocklist into the session""" """Imports the downloaded blocklist into the session"""
if self.is_downloading: if self.is_downloading:
return return
if download: if force or self.need_new_blocklist():
if force or self.need_new_blocklist(): self.download_blocklist(True)
self.download_blocklist(True) return
return
self.is_importing = True self.is_importing = True
log.debug("Reset IP Filter..") log.debug("Reset IP Filter..")
@ -244,6 +243,11 @@ class Core(CorePluginBase):
def need_new_blocklist(self): def need_new_blocklist(self):
"""Returns True if a new blocklist file should be downloaded""" """Returns True if a new blocklist file should be downloaded"""
# Check to see if we've just downloaded a new blocklist
if os.path.exists(deluge.configmanager.get_config_dir("blocklist.download")):
log.debug("New blocklist waiting to be imported")
return False
try: try:
# Check current block lists time stamp and decide if it needs to be replaced # Check current block lists time stamp and decide if it needs to be replaced
list_stats = os.stat(deluge.configmanager.get_config_dir("blocklist.cache")) list_stats = os.stat(deluge.configmanager.get_config_dir("blocklist.cache"))
@ -256,6 +260,7 @@ class Core(CorePluginBase):
# If local blocklist file exists but nothing is in it # If local blocklist file exists but nothing is in it
if list_size == 0: if list_size == 0:
log.debug("Empty blocklist")
return True return True
import socket import socket
@ -264,13 +269,14 @@ class Core(CorePluginBase):
try: try:
# Get remote blocklist time stamp and size # Get remote blocklist time stamp and size
remote_stats = urllib.urlopen(self.config["url"]).info() remote_stats = urllib.urlopen(self.config["url"]).info()
remote_size = remote_stats["content-length"] remote_size = long(remote_stats["content-length"])
remote_time = datetime.datetime.strptime(remote_stats["last-modified"],"%a, %d %b %Y %H:%M:%S GMT") remote_time = datetime.datetime.strptime(remote_stats["last-modified"],"%a, %d %b %Y %H:%M:%S GMT")
except Exception, e: except Exception, e:
log.debug("Unable to get blocklist stats: %s", e) log.debug("Unable to get blocklist stats: %s", e)
return False return False
if list_time < remote_time or list_size < remote_size: if list_time < remote_time or list_size < remote_size:
log.debug("Newer blocklist exists (%s & %d vs %s & %d)", remote_time, remote_size, list_time, list_size)
return True return True
return False return False

View File

@ -139,11 +139,11 @@ class GtkUI(ui.UI):
def _on_button_check_download_clicked(self, widget): def _on_button_check_download_clicked(self, widget):
self._on_apply_prefs() self._on_apply_prefs()
client.blocklist.import_list(None, True, False) client.blocklist.import_list(None, False)
def _on_button_force_download_clicked(self, widget): def _on_button_force_download_clicked(self, widget):
self._on_apply_prefs() self._on_apply_prefs()
client.blocklist.import_list(None, True, True) client.blocklist.import_list(None, True)
def _on_status_item_clicked(self, widget, event): def _on_status_item_clicked(self, widget, event):
component.get("Preferences").show("Blocklist") component.get("Preferences").show("Blocklist")

View File

@ -60,10 +60,7 @@ class BlockListCfgForm(forms.Form):
del cfg["btn_import_now"] del cfg["btn_import_now"]
sclient.blocklist.set_config(cfg) sclient.blocklist.set_config(cfg)
if data.btn_import_now: if data.btn_import_now:
aclient.blocklist.import_list(None, data.btn_download_now) aclient.blocklist.import_list(None, data.btn_force_download)
elif data.btn_download_now:
aclient.blocklist.download(None)
#input fields : #input fields :
listtype = forms.ChoiceField(FORMAT_LIST) listtype = forms.ChoiceField(FORMAT_LIST)
@ -73,8 +70,8 @@ class BlockListCfgForm(forms.Form):
try_times = forms.IntegerField(label=_("Times to attempt download"), min_value=1, max_value=5) try_times = forms.IntegerField(label=_("Times to attempt download"), min_value=1, max_value=5)
load_on_start = forms.CheckBox(_('Import on daemon startup')) load_on_start = forms.CheckBox(_('Import on daemon startup'))
btn_download_now = forms.CheckBox(_('Download Now'))
btn_import_now = forms.CheckBox(_('Import Now')) btn_import_now = forms.CheckBox(_('Import Now'))
btn_force_download = forms.CheckBox(_('Force Download'))
def post_html(self): def post_html(self):
"show blocklist status" "show blocklist status"