From 85dffdd9a52e923f6bd1ad164b9e27a8b674599f Mon Sep 17 00:00:00 2001 From: George Vlahavas Date: Thu, 10 Nov 2016 01:51:34 +0200 Subject: [PATCH] Improve icon extension handling In addition to other icon file types, also detect svgz icons. Do not use them in any case, since none of the supported WMs can use them. Also, make the extension detection case-insensitive. I've never seen an icon extension with capitals in the wild, but who knows... Finally, clean up the code a bit, so it reads easier. --- src/xdgmenumaker | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/xdgmenumaker b/src/xdgmenumaker index 0f317be..0e3e89d 100755 --- a/src/xdgmenumaker +++ b/src/xdgmenumaker @@ -269,12 +269,10 @@ def usage(): def icon_strip(icon): # strip the directory and extension from the icon name icon = os.path.basename(icon) - if icon.endswith('.png'): - icon = icon.replace('.png', '') - elif icon.endswith('.svg'): - icon = icon.replace('.svg', '') - elif icon.endswith('.xpm'): - icon = icon.replace('.xpm', '') + main, ext = os.path.splitext(icon) + ext = ext.lower() + if ext == '.png' or ext == '.svg' or ext == '.svgz' or ext == '.xpm': + return main return icon @@ -299,7 +297,8 @@ def icon_full_path(icon): # But we don't want to do this for svg icons, since none of the WMs # supports them. In that case, just fall back to looking for the icon # elsewhere in the system. - if os.path.exists(icon) and os.path.splitext(icon)[1] != ".svg": + ext = os.path.splitext(icon)[1].lower() + if os.path.exists(icon) and ext != ".svg" and ext != ".svgz": if max_icon_size: return icon_max_size(icon) else: