mirror of
https://git.deluge-torrent.org/deluge
synced 2025-04-20 11:35:49 +00:00
Force blocklist to re-detect the format when a download is forced.
Move remove_zeros to common.py and simplify / speed up. Change debug logging lines to be more uniform.
This commit is contained in:
parent
441c20491c
commit
1b46d99620
5 changed files with 27 additions and 29 deletions
|
@ -18,6 +18,9 @@
|
|||
* Allow commands that are .pyc files to be used
|
||||
* Fix printing info, help, etc.. on the command line
|
||||
|
||||
==== Blocklist ====
|
||||
* Force blocklist to auto-detect format when a download / import is forced
|
||||
|
||||
=== Deluge 1.2.0_rc3 (01 November 2009) ===
|
||||
==== Core ====
|
||||
* Fix #1047 move completed does not work if saving to non default path
|
||||
|
|
|
@ -49,3 +49,18 @@ def raiseError(error):
|
|||
raise error
|
||||
return new
|
||||
return safer
|
||||
|
||||
def remove_zeros(ip):
|
||||
"""
|
||||
Removes unneeded zeros from ip addresses.
|
||||
|
||||
Example: 000.000.000.003 -> 0.0.0.3
|
||||
|
||||
:param ip: the ip address
|
||||
:type ip: string
|
||||
|
||||
:returns: the ip address without the unneeded zeros
|
||||
:rtype: string
|
||||
|
||||
"""
|
||||
return ".".join([part.lstrip("0").zfill(1) for part in ip.split(".")])
|
||||
|
|
|
@ -128,6 +128,8 @@ class Core(CorePluginBase):
|
|||
self.use_cache = False
|
||||
self.failed_attempts = 0
|
||||
self.auto_detected = False
|
||||
if force:
|
||||
self.reader = None
|
||||
|
||||
# Start callback chain
|
||||
d = self.download_list()
|
||||
|
@ -218,8 +220,8 @@ class Core(CorePluginBase):
|
|||
if self.config["last_update"] and not self.force_download:
|
||||
headers['If-Modified-Since'] = self.config["last_update"]
|
||||
|
||||
log.debug("Attempting to download blocklist %s" % url)
|
||||
log.debug("Sending headers: %s" % headers)
|
||||
log.debug("Attempting to download blocklist %s", url)
|
||||
log.debug("Sending headers: %s", headers)
|
||||
self.up_to_date = False
|
||||
self.is_downloading = True
|
||||
return download_file(url, deluge.configmanager.get_config_dir("blocklist.download"), on_retrieve_data, headers)
|
||||
|
@ -239,7 +241,7 @@ class Core(CorePluginBase):
|
|||
# Handle redirect errors
|
||||
location = error_msg.split(" to ")[1]
|
||||
if "Moved Permanently" in error_msg:
|
||||
log.debug("Setting blocklist url to %s" % location)
|
||||
log.debug("Setting blocklist url to %s", location)
|
||||
self.config["url"] = location
|
||||
f.trap(f.type)
|
||||
d = self.download_list(url=location)
|
||||
|
@ -291,7 +293,7 @@ class Core(CorePluginBase):
|
|||
self.auto_detect(blocklist)
|
||||
self.auto_detected = True
|
||||
|
||||
log.debug("Importing using reader: %s",self.reader)
|
||||
log.debug("Importing using reader: %s", self.reader)
|
||||
log.debug("Reader type: %s compression: %s", self.config["list_type"], self.config["list_compression"])
|
||||
d = threads.deferToThread(self.reader(blocklist).read, on_read_ip_range)
|
||||
d.addCallback(on_finish_read)
|
||||
|
@ -327,7 +329,7 @@ class Core(CorePluginBase):
|
|||
elif os.path.exists(blocklist) and not self.use_cache:
|
||||
# If we have a backup and we haven't already used it
|
||||
e = f.trap(Exception)
|
||||
log.warning("Error reading blocklist: ", e)
|
||||
log.warning("Error reading blocklist: %s", e)
|
||||
self.use_cache = True
|
||||
try_again = True
|
||||
|
||||
|
@ -347,7 +349,7 @@ class Core(CorePluginBase):
|
|||
"""
|
||||
self.config["list_compression"] = detect_compression(blocklist)
|
||||
self.config["list_type"] = detect_format(blocklist, self.config["list_compression"])
|
||||
log.debug("Auto-detected type: %s compression: %s", self.config["list_type"], self.config["list_compression"])
|
||||
log.debug("Auto-detected type: %s compression: %s", self.config["list_type"], self.config["list_compression"])
|
||||
if not self.config["list_type"]:
|
||||
self.config["list_compression"] = ""
|
||||
raise UnknownFormatError
|
||||
|
|
|
@ -77,5 +77,4 @@ def create_reader(format, compression=""):
|
|||
decompressor = DECOMPRESSERS.get(compression)
|
||||
if decompressor:
|
||||
reader = decompressor(reader)
|
||||
|
||||
return reader
|
||||
|
|
|
@ -33,29 +33,8 @@
|
|||
#
|
||||
#
|
||||
|
||||
from deluge.log import LOG as log
|
||||
from common import raiseError
|
||||
from common import raiseError, remove_zeros
|
||||
|
||||
def remove_zeros(ip):
|
||||
"""
|
||||
Removes unneeded zeros from ip addresses.
|
||||
|
||||
Example: 000.000.000.003 -> 0.0.0.3
|
||||
|
||||
:param ip: the ip address
|
||||
:type ip: string
|
||||
|
||||
:returns: the ip address without the unneeded zeros
|
||||
:rtype: string
|
||||
|
||||
"""
|
||||
new_ip = []
|
||||
for part in ip.split("."):
|
||||
while part[0] == "0" and len(part) > 1:
|
||||
part = part[1:]
|
||||
new_ip.append(part)
|
||||
return ".".join(new_ip)
|
||||
|
||||
class ReaderParseError(Exception):
|
||||
pass
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue