From 2f5a4761e0df00488e44046e0deaf46e18ccd7ec Mon Sep 17 00:00:00 2001 From: George Vlahavas Date: Sat, 1 Oct 2016 00:17:02 +0300 Subject: [PATCH] Recurse into xdg directories for .desktop files Look into all subdirs of xdg directories like /usr/share/applications etc for .desktop files. This will make applications that put their .desktop files in places like /usr/share/applications/kde4 visible. --- src/xdgmenumaker | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/xdgmenumaker b/src/xdgmenumaker index 51398fb..d3d4bf9 100755 --- a/src/xdgmenumaker +++ b/src/xdgmenumaker @@ -7,6 +7,7 @@ from __future__ import print_function import os import sys import getopt +import fnmatch import xdg.DesktopEntry as dentry import xdg.Exceptions as exc import xdg.BaseDirectory as bd @@ -366,16 +367,16 @@ def desktopfilelist(): for d in dirs: xdgdir = '{}/applications'.format(d) if os.path.isdir(xdgdir): - for i in os.listdir(xdgdir): - if i.endswith('.desktop'): - # for duplicate .desktop files that exist in more - # than one locations, only keep the first occurence. - # That one should have precedence anyway (e.g. - # ~/.local/share/applications has precedence over - # /usr/share/applications - if i not in df_temp: - df_temp.append(i) - filelist.append('{}/{}'.format(xdgdir, i)) + for root, dirnames, filenames in os.walk(xdgdir): + for i in fnmatch.filter(filenames, '*.desktop'): + # for duplicate .desktop files that exist in more + # than one locations, only keep the first occurence. + # That one should have precedence anyway (e.g. + # ~/.local/share/applications has precedence over + # /usr/share/applications + if i not in df_temp: + df_temp.append(i) + filelist.append(os.path.join(root, i)) return filelist