mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-30 13:16:17 +00:00
need_new_blocklist is no longer blocking
removed download arg from import_list updated gtkui and webui
This commit is contained in:
parent
813063bd12
commit
1ec3751f91
@ -74,7 +74,7 @@ class Core(CorePluginBase):
|
||||
|
||||
self.config = deluge.configmanager.ConfigManager("blocklist.conf", DEFAULT_PREFS)
|
||||
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
|
||||
# and import a new list if needed.
|
||||
@ -98,10 +98,10 @@ class Core(CorePluginBase):
|
||||
self.download_blocklist(_import)
|
||||
|
||||
@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
|
||||
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
|
||||
def get_config(self):
|
||||
@ -142,15 +142,14 @@ class Core(CorePluginBase):
|
||||
if load:
|
||||
self.import_list()
|
||||
|
||||
def import_blocklist(self, download=False, force=False):
|
||||
def import_blocklist(self, force=False):
|
||||
"""Imports the downloaded blocklist into the session"""
|
||||
if self.is_downloading:
|
||||
return
|
||||
|
||||
if download:
|
||||
if force or self.need_new_blocklist():
|
||||
self.download_blocklist(True)
|
||||
return
|
||||
if force or self.need_new_blocklist():
|
||||
self.download_blocklist(True)
|
||||
return
|
||||
|
||||
self.is_importing = True
|
||||
log.debug("Reset IP Filter..")
|
||||
@ -244,6 +243,11 @@ class Core(CorePluginBase):
|
||||
|
||||
def need_new_blocklist(self):
|
||||
"""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:
|
||||
# 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"))
|
||||
@ -256,6 +260,7 @@ class Core(CorePluginBase):
|
||||
|
||||
# If local blocklist file exists but nothing is in it
|
||||
if list_size == 0:
|
||||
log.debug("Empty blocklist")
|
||||
return True
|
||||
|
||||
import socket
|
||||
@ -264,13 +269,14 @@ class Core(CorePluginBase):
|
||||
try:
|
||||
# Get remote blocklist time stamp and size
|
||||
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")
|
||||
except Exception, e:
|
||||
log.debug("Unable to get blocklist stats: %s", e)
|
||||
return False
|
||||
|
||||
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 False
|
||||
|
@ -139,11 +139,11 @@ class GtkUI(ui.UI):
|
||||
|
||||
def _on_button_check_download_clicked(self, widget):
|
||||
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):
|
||||
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):
|
||||
component.get("Preferences").show("Blocklist")
|
||||
|
@ -60,10 +60,7 @@ class BlockListCfgForm(forms.Form):
|
||||
del cfg["btn_import_now"]
|
||||
sclient.blocklist.set_config(cfg)
|
||||
if data.btn_import_now:
|
||||
aclient.blocklist.import_list(None, data.btn_download_now)
|
||||
elif data.btn_download_now:
|
||||
aclient.blocklist.download(None)
|
||||
|
||||
aclient.blocklist.import_list(None, data.btn_force_download)
|
||||
|
||||
#input fields :
|
||||
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)
|
||||
load_on_start = forms.CheckBox(_('Import on daemon startup'))
|
||||
|
||||
btn_download_now = forms.CheckBox(_('Download Now'))
|
||||
btn_import_now = forms.CheckBox(_('Import Now'))
|
||||
btn_force_download = forms.CheckBox(_('Force Download'))
|
||||
|
||||
def post_html(self):
|
||||
"show blocklist status"
|
||||
|
Loading…
x
Reference in New Issue
Block a user