mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
[UI] Fix usage of 'with Image.open' in trackericons
* Revert changes made to fix 'too many files open' as Image.open does not return a file descriptor and generated the following error: exceptions.AttributeError: 'NoneType' object has no attribute 'startswith' * Also fix style for raising an exception.
This commit is contained in:
parent
bf01b53bda
commit
af76abb038
1 changed files with 10 additions and 11 deletions
|
@ -359,13 +359,12 @@ class TrackerIcons(Component):
|
||||||
|
|
||||||
if PIL_INSTALLED:
|
if PIL_INSTALLED:
|
||||||
try:
|
try:
|
||||||
with Image.open(icon_name):
|
Image.open(icon_name)
|
||||||
pass
|
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
raise InvalidIconError(e)
|
raise InvalidIconError(e)
|
||||||
else:
|
else:
|
||||||
if os.stat(icon_name).st_size == 0L:
|
if os.stat(icon_name).st_size == 0L:
|
||||||
raise InvalidIconError, "empty icon"
|
raise InvalidIconError("empty icon")
|
||||||
|
|
||||||
return icon_name
|
return icon_name
|
||||||
|
|
||||||
|
@ -434,14 +433,14 @@ class TrackerIcons(Component):
|
||||||
"""
|
"""
|
||||||
if icon:
|
if icon:
|
||||||
filename = icon.get_filename()
|
filename = icon.get_filename()
|
||||||
with Image.open(filename) as img:
|
img = Image.open(filename)
|
||||||
if img.size > (16, 16):
|
if img.size > (16, 16):
|
||||||
new_filename = filename.rpartition('.')[0]+".png"
|
new_filename = filename.rpartition('.')[0]+".png"
|
||||||
img = img.resize((16, 16), Image.ANTIALIAS)
|
img = img.resize((16, 16), Image.ANTIALIAS)
|
||||||
img.save(new_filename)
|
img.save(new_filename)
|
||||||
if new_filename != filename:
|
if new_filename != filename:
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
icon = TrackerIcon(new_filename)
|
icon = TrackerIcon(new_filename)
|
||||||
return icon
|
return icon
|
||||||
|
|
||||||
def store_icon(self, icon, host):
|
def store_icon(self, icon, host):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue