Improved logic for adding .png to the end of possible icon names when downloading or displaying icons

This commit is contained in:
Greg Neagle
2014-07-25 15:16:07 -07:00
parent ae5f9b4c75
commit fd85f4ef5c
2 changed files with 8 additions and 6 deletions
@@ -501,12 +501,13 @@ class GenericItem(dict):
def getIcon(self):
'''Return name/relative path of image file to use for the icon'''
# first look for downloaded icons
icon_known_exts = [ 'bmp', 'gif', 'icns', 'jpg', 'jpeg', 'png', 'psd', 'tga', 'tif', 'tiff', 'yuv' ]
icon_known_exts = [
'bmp', 'gif', 'icns', 'jpg', 'jpeg', 'png', 'psd', 'tga', 'tif', 'tiff', 'yuv']
icon_name = self.get('icon_name') or self['name']
if not os.path.splitext(icon_name)[1]:
if not os.path.splitext(icon_name)[1] in icon_known_exts:
icon_name += '.png'
icon_path = os.path.join(msulib.html_dir(), 'icons', icon_name)
if not [ ext for ext in icon_known_exts if ext in icon_name ]:
if os.path.exists(icon_path):
return 'icons/' + icon_name
# didn't find one in the downloaded icons
# so create one if needed from a locally installed app
@@ -514,7 +515,7 @@ class GenericItem(dict):
if key in self:
name = self[key]
icon_name = name
if not os.path.splitext(icon_name)[1]:
if not os.path.splitext(icon_name)[1] in icon_known_exts:
icon_name += '.png'
icon_path = os.path.join(msulib.html_dir(), icon_name)
if os.path.exists(icon_path) or convertIconToPNG(name, icon_path, 350):
+3 -2
View File
@@ -2725,7 +2725,8 @@ def download_icons(item_list):
'''Attempts to download icons (actually png files) for items in
item_list'''
icon_list = []
icon_known_exts = [ 'bmp', 'gif', 'icns', 'jpg', 'jpeg', 'png', 'psd', 'tga', 'tif', 'tiff', 'yuv' ]
icon_known_exts = ['bmp', 'gif', 'icns', 'jpg', 'jpeg', 'png', 'psd',
'tga', 'tif', 'tiff', 'yuv']
icon_base_url = (munkicommon.pref('IconURL') or
munkicommon.pref('SoftwareRepoURL') + '/icons/')
icon_base_url = icon_base_url.rstrip('/') + '/'
@@ -2733,7 +2734,7 @@ def download_icons(item_list):
munkicommon.display_debug2('Icon base URL is: %s', icon_base_url)
for item in item_list:
icon_name = item.get('icon_name') or item['name']
if not [ ext for ext in icon_known_exts if ext in icon_name ]:
if not os.path.splitext(icon_name)[1] in icon_known_exts:
icon_name += '.png'
icon_list.append(icon_name)
icon_url = icon_base_url + urllib2.quote(icon_name)