mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-22 10:09:14 +00:00
add error management to blocklist plugin
This commit is contained in:
parent
67e79250d2
commit
91d8ad33ae
5 changed files with 52 additions and 25 deletions
|
@ -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)
|
Deluge 0.5.6.2 (31 October 2007)
|
||||||
* Set default piece size to 256-KiB in TorrentCreator plugin and add 2048KiB
|
* Set default piece size to 256-KiB in TorrentCreator plugin and add 2048KiB
|
||||||
as a size option.
|
as a size option.
|
||||||
|
|
1
TODO
1
TODO
|
@ -1,6 +1,5 @@
|
||||||
for 0.5.7
|
for 0.5.7
|
||||||
1. manual recheck
|
1. manual recheck
|
||||||
2. preference for .torrent location
|
2. preference for .torrent location
|
||||||
3. have blocklist detect 7zip files and popup a warning instead of crashing
|
|
||||||
4. add auto-pickup folder
|
4. add auto-pickup folder
|
||||||
5. remap filenames
|
5. remap filenames
|
||||||
|
|
|
@ -88,8 +88,8 @@ class BlocklistImport:
|
||||||
filename, headers = urllib.urlretrieve(self.config.get('url'),
|
filename, headers = urllib.urlretrieve(self.config.get('url'),
|
||||||
filename=self.blockfile,
|
filename=self.blockfile,
|
||||||
reporthook=self._download_update)
|
reporthook=self._download_update)
|
||||||
except IOError, (errno, strerr):
|
except IOError, e:
|
||||||
err = ui.GTKError(_("Couldn't download URL") + ": %s"%strerr)
|
err = ui.GTKError(_("Couldn't download URL") + ": %s"%e)
|
||||||
self.gtkprog.stop()
|
self.gtkprog.stop()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -101,13 +101,16 @@ class BlocklistImport:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
reader = readers[ltype][1](self.blockfile)
|
reader = readers[ltype][1](self.blockfile)
|
||||||
except IOError, (errno, strerr):
|
except IOError, e:
|
||||||
err = ui.GTKError(_("Couldn't open blocklist file") + ": %s"%strerr)
|
err = ui.GTKError(_("Couldn't open blocklist file") + ": %s"%e)
|
||||||
self.gtkprog.stop()
|
self.gtkprog.stop()
|
||||||
return
|
return
|
||||||
|
|
||||||
print "Starting import"
|
print "Starting import"
|
||||||
|
try:
|
||||||
ips = reader.next()
|
ips = reader.next()
|
||||||
|
except:
|
||||||
|
ui.GTKError(_("Wrong file type or corrupted blocklist file."))
|
||||||
curr = 0
|
curr = 0
|
||||||
try:
|
try:
|
||||||
while ips and not self.cancelled:
|
while ips and not self.cancelled:
|
||||||
|
@ -119,8 +122,7 @@ class BlocklistImport:
|
||||||
else:
|
else:
|
||||||
self.gtkprog.import_prog()
|
self.gtkprog.import_prog()
|
||||||
|
|
||||||
except FormatException, (ex):
|
except:
|
||||||
err = ui.GTKError(_("Format error in blocklist") + ": %s"%ex)
|
|
||||||
self.gtkprog.stop()
|
self.gtkprog.stop()
|
||||||
reader.close()
|
reader.close()
|
||||||
return
|
return
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
from exceptions import Exception
|
from exceptions import Exception
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
import gzip, socket
|
import gzip, socket
|
||||||
|
import ui
|
||||||
|
|
||||||
class PGException(Exception):
|
class PGException(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -17,8 +18,11 @@ class PGReader:
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
print "PGReader loading",filename
|
print "PGReader loading",filename
|
||||||
|
|
||||||
# FIXME: Catch and convert exception?
|
try:
|
||||||
self.fd = gzip.open(filename, "rb")
|
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
|
# 4 bytes, should be 0xffffffff
|
||||||
buf = self.fd.read(4)
|
buf = self.fd.read(4)
|
||||||
|
|
|
@ -9,7 +9,7 @@ import re, gzip, os
|
||||||
from socket import inet_aton
|
from socket import inet_aton
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
import ui
|
||||||
|
|
||||||
class TextException(Exception):
|
class TextException(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -34,9 +34,13 @@ class TextBase:
|
||||||
|
|
||||||
match = self.re.search(txt)
|
match = self.re.search(txt)
|
||||||
if not match:
|
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."))
|
||||||
|
|
||||||
|
try:
|
||||||
g = match.groups()
|
g = match.groups()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
start = ".".join(g[0:4])
|
start = ".".join(g[0:4])
|
||||||
end = ".".join(g[4:8])
|
end = ".".join(g[4:8])
|
||||||
|
|
||||||
|
@ -60,7 +64,10 @@ class TextReader(PGTextReader):
|
||||||
|
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
print "TextReader loading",filename
|
print "TextReader loading",filename
|
||||||
|
try:
|
||||||
PGTextReader.__init__(self, open(filename, 'r'))
|
PGTextReader.__init__(self, open(filename, 'r'))
|
||||||
|
except:
|
||||||
|
ui.GTKError(_("Wrong file type or corrupted blocklist file."))
|
||||||
|
|
||||||
|
|
||||||
# Reads Emule style blocklists (aka nipfilter)
|
# Reads Emule style blocklists (aka nipfilter)
|
||||||
|
@ -75,7 +82,10 @@ class GZMuleReader(MuleReader):
|
||||||
|
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
print "GZMuleReader loading",filename
|
print "GZMuleReader loading",filename
|
||||||
|
try:
|
||||||
MuleReader.__init__(self, gzip.open(filename, "r"))
|
MuleReader.__init__(self, gzip.open(filename, "r"))
|
||||||
|
except:
|
||||||
|
ui.GTKError(_("Wrong file type or corrupted blocklist file."))
|
||||||
|
|
||||||
|
|
||||||
# Reads zip files from SafePeer style files
|
# Reads zip files from SafePeer style files
|
||||||
|
@ -83,9 +93,12 @@ class PGZip(TextBase):
|
||||||
|
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
# Open zip and extract first file
|
# Open zip and extract first file
|
||||||
|
try:
|
||||||
self.zfd = ZipFile(filename, 'r')
|
self.zfd = ZipFile(filename, 'r')
|
||||||
|
except:
|
||||||
|
ui.GTKError(_("Wrong file type or corrupted blocklist file."))
|
||||||
|
else:
|
||||||
self.files = self.zfd.namelist()
|
self.files = self.zfd.namelist()
|
||||||
|
|
||||||
self.opennext()
|
self.opennext()
|
||||||
|
|
||||||
def opennext(self):
|
def opennext(self):
|
||||||
|
@ -112,14 +125,19 @@ class PGZip(TextBase):
|
||||||
return False
|
return False
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
except FormatException, (e):
|
except FormatException, e:
|
||||||
print "Got format exception for zipfile:",e
|
ui.GTKError(_("Got format exception for zipfile:",e))
|
||||||
# Just skip
|
# Just skip
|
||||||
if len(self.files) > 0:
|
if len(self.files) > 0:
|
||||||
self.opennext()
|
self.opennext()
|
||||||
return self.next()
|
return self.next()
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
try:
|
||||||
self.zfd.close()
|
self.zfd.close()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue