However this annoyed me seeing my perfectly good blocklist would get overwritten with an invalid one.
So I've written a patch for the blocklist importer which I thought I would share which only downloads the blocklist if the url is correct (i.e. offering the right type of file) and the remote blocklist is actually newer than the one you have (based on last-modified times and lengths)
I should mention that I'm quite new to python (but not to programming) and I've only really tested it out with bluetack's nipfitler.dat.gz & splist.zip URLs.
EDIT: updated for deluge 0.5.9.3
__init__.py patch
Code: Select all
37c37,38
< import os.path, os, time
---
> from socket import setdefaulttimeout, getdefaulttimeout
> import os, datetime, re
78a80,133
> def validurl(self, header):
> valid = False
> listtype = self.config.get('listtype')
> if listtype == "spzip":
> type = "application/zip"
> elif listtype == "gzmule" or listtype == "p2bgz":
> type = "application/x-gzip"
> if header['content-type'] == type:
> valid = True
> return valid
>
> def outdated(self):
> # only perform check if it's a url
> if re.match("^http\:\/\/",self.config.get('url'),re.I):
> print "Checking for updated blocklist..."
> # initialise variables
> outdated = False
> local = {}
> remote = {}
> timeout = getdefaulttimeout()
> # allow 5s to connect to server
> setdefaulttimeout(5)
> try:
> # collect remote blocklist info
> header = urllib.urlopen(self.config.get('url')).info()
> remote['size'] = int(header['content-length'])
> remote['time'] = datetime.datetime.strptime(header['last-modified'],"%a, %d %b %Y %H:%M:%S GMT")
> except IOError:
> print "...Remote blocklist timed out"
> else:
> if self.validurl(header):
> try:
> # collect local blocklist info
> local['stat'] = os.stat(self.blockfile)
> local['size'] = local['stat'].st_size
> local['time'] = datetime.datetime.fromtimestamp(local['stat'].st_mtime)
> except OSError:
> print "...Could not open local blocklist"
> outdated = True
> else:
> if local['size'] != remote['size'] or local['time'] < remote['time']:
> print "...Blocklist is NOT up to date"
> outdated = True
> else:
> print "...Blocklist is up to date"
> else:
> print "...Remote blocklist invalid/unavailable"
> raise IOError, "remote blocklist invalid or unavailable"
> finally:
> setdefaulttimeout(timeout)
> else:
> outdated = True
> return outdated
>
92,93c147,149
< list_timestamp = liststats.st_mtime
< now_timestamp = time.time()
---
> list_time = datetime.datetime.fromtimestamp(liststats.st_mtime)
> list_size = liststats.st_size
> now_time = datetime.datetime.today()
98d153
< # Seconds in a day = 86400
101c156
< if now_timestamp >= (list_timestamp + (86400 * days_update)):
---
> if now_time >= (list_time + datetime.timedelta(days=days_update)):
110c165
< if fetch == -1:
---
> if fetch == -1 and self.outdated():
Code: Select all
52c52
< label2.set_markup('<b>' + _("Download new blocklist every") + '</b>')
---
> label2.set_markup('<b>' + _("Check for new blocklist every") + '</b>')