add error management to blocklist plugin

This commit is contained in:
Marcos Pinto 2007-11-04 22:33:55 +00:00
parent 67e79250d2
commit 91d8ad33ae
5 changed files with 52 additions and 25 deletions

View File

@ -1,3 +1,7 @@
Deluge 0.5.7 (xx November 2007)
* Blocklist plugin will now display errors, instead of just crashing on a bad
list
Deluge 0.5.6.2 (31 October 2007)
* Set default piece size to 256-KiB in TorrentCreator plugin and add 2048KiB
as a size option.

1
TODO
View File

@ -1,6 +1,5 @@
for 0.5.7
1. manual recheck
2. preference for .torrent location
3. have blocklist detect 7zip files and popup a warning instead of crashing
4. add auto-pickup folder
5. remap filenames

View File

@ -88,8 +88,8 @@ class BlocklistImport:
filename, headers = urllib.urlretrieve(self.config.get('url'),
filename=self.blockfile,
reporthook=self._download_update)
except IOError, (errno, strerr):
err = ui.GTKError(_("Couldn't download URL") + ": %s"%strerr)
except IOError, e:
err = ui.GTKError(_("Couldn't download URL") + ": %s"%e)
self.gtkprog.stop()
return
@ -101,13 +101,16 @@ class BlocklistImport:
try:
reader = readers[ltype][1](self.blockfile)
except IOError, (errno, strerr):
err = ui.GTKError(_("Couldn't open blocklist file") + ": %s"%strerr)
except IOError, e:
err = ui.GTKError(_("Couldn't open blocklist file") + ": %s"%e)
self.gtkprog.stop()
return
print "Starting import"
ips = reader.next()
try:
ips = reader.next()
except:
ui.GTKError(_("Wrong file type or corrupted blocklist file."))
curr = 0
try:
while ips and not self.cancelled:
@ -119,8 +122,7 @@ class BlocklistImport:
else:
self.gtkprog.import_prog()
except FormatException, (ex):
err = ui.GTKError(_("Format error in blocklist") + ": %s"%ex)
except:
self.gtkprog.stop()
reader.close()
return

View File

@ -6,6 +6,7 @@
from exceptions import Exception
from struct import unpack
import gzip, socket
import ui
class PGException(Exception):
pass
@ -17,8 +18,11 @@ class PGReader:
def __init__(self, filename):
print "PGReader loading",filename
# FIXME: Catch and convert exception?
self.fd = gzip.open(filename, "rb")
try:
self.fd = gzip.open(filename, "rb")
except IOError, e:
ui.GTKError(_("We were expecting a gzip file, but didn't get that, \
or possibly the file is corrupt. Please edit your Blocklist preferences"))
# 4 bytes, should be 0xffffffff
buf = self.fd.read(4)

View File

@ -9,7 +9,7 @@ import re, gzip, os
from socket import inet_aton
from struct import unpack
from zipfile import ZipFile
import ui
class TextException(Exception):
pass
@ -34,13 +34,17 @@ class TextBase:
match = self.re.search(txt)
if not match:
raise FormatException(_("Couldn't match on line") + " %d: %s (%s)"%(self.count,txt,txt))
ui.GTKError(_("Wrong file type or corrupted blocklist file."))
g = match.groups()
start = ".".join(g[0:4])
end = ".".join(g[4:8])
try:
g = match.groups()
except AttributeError:
pass
else:
start = ".".join(g[0:4])
end = ".".join(g[4:8])
return (start, end)
return (start, end)
def close(self):
self.fd.close()
@ -60,7 +64,10 @@ class TextReader(PGTextReader):
def __init__(self, filename):
print "TextReader loading",filename
PGTextReader.__init__(self, open(filename, 'r'))
try:
PGTextReader.__init__(self, open(filename, 'r'))
except:
ui.GTKError(_("Wrong file type or corrupted blocklist file."))
# Reads Emule style blocklists (aka nipfilter)
@ -75,7 +82,10 @@ class GZMuleReader(MuleReader):
def __init__(self, filename):
print "GZMuleReader loading",filename
MuleReader.__init__(self, gzip.open(filename, "r"))
try:
MuleReader.__init__(self, gzip.open(filename, "r"))
except:
ui.GTKError(_("Wrong file type or corrupted blocklist file."))
# Reads zip files from SafePeer style files
@ -83,10 +93,13 @@ class PGZip(TextBase):
def __init__(self, filename):
# Open zip and extract first file
self.zfd = ZipFile(filename, 'r')
self.files = self.zfd.namelist()
self.opennext()
try:
self.zfd = ZipFile(filename, 'r')
except:
ui.GTKError(_("Wrong file type or corrupted blocklist file."))
else:
self.files = self.zfd.namelist()
self.opennext()
def opennext(self):
self.tmp = os.tmpfile()
@ -112,14 +125,19 @@ class PGZip(TextBase):
return False
return ret
except FormatException, (e):
print "Got format exception for zipfile:",e
except FormatException, e:
ui.GTKError(_("Got format exception for zipfile:",e))
# Just skip
if len(self.files) > 0:
self.opennext()
return self.next()
else:
return False
except AttributeError:
pass
def close(self):
self.zfd.close()
try:
self.zfd.close()
except AttributeError:
pass