Browse Source

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.
pull/6/head 1.0
George Vlahavas 8 years ago
parent
commit
2f5a4761e0
  1. 21
      src/xdgmenumaker

21
src/xdgmenumaker

@ -7,6 +7,7 @@ from __future__ import print_function
import os import os
import sys import sys
import getopt import getopt
import fnmatch
import xdg.DesktopEntry as dentry import xdg.DesktopEntry as dentry
import xdg.Exceptions as exc import xdg.Exceptions as exc
import xdg.BaseDirectory as bd import xdg.BaseDirectory as bd
@ -366,16 +367,16 @@ def desktopfilelist():
for d in dirs: for d in dirs:
xdgdir = '{}/applications'.format(d) xdgdir = '{}/applications'.format(d)
if os.path.isdir(xdgdir): if os.path.isdir(xdgdir):
for i in os.listdir(xdgdir): for root, dirnames, filenames in os.walk(xdgdir):
if i.endswith('.desktop'): for i in fnmatch.filter(filenames, '*.desktop'):
# for duplicate .desktop files that exist in more # for duplicate .desktop files that exist in more
# than one locations, only keep the first occurence. # than one locations, only keep the first occurence.
# That one should have precedence anyway (e.g. # That one should have precedence anyway (e.g.
# ~/.local/share/applications has precedence over # ~/.local/share/applications has precedence over
# /usr/share/applications # /usr/share/applications
if i not in df_temp: if i not in df_temp:
df_temp.append(i) df_temp.append(i)
filelist.append('{}/{}'.format(xdgdir, i)) filelist.append(os.path.join(root, i))
return filelist return filelist

Loading…
Cancel
Save