-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild-menu.py
More file actions
executable file
·79 lines (58 loc) · 2.07 KB
/
build-menu.py
File metadata and controls
executable file
·79 lines (58 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python2
from xdg.DesktopEntry import DesktopEntry
import glob
import md5 #TODO: use hashlib instead
#import sys
import os
import codecs
#sys.stdout = codecs.getwriter('utf8')(sys.stdout)
HOMEDIR = os.getenv("HOME")
execfile(HOMEDIR+'/.config/dmenu-xdg.conf')
menuFile = codecs.open(HOMEDIR+'/bin/xdg-dmenu.cache', 'w', encoding='utf-8')
execFile = codecs.open(HOMEDIR+'/bin/xdg-exec.cache', 'w', encoding='utf-8')
execs = {}
def printEntry(catName, de, mainGroup):
exc = de.getExec()
hsh = md5.new(exc).hexdigest()
name = de.getName() if mainGroup else " " + de.getName()
mimeStr = str(de.getMimeTypes()) if de.getMimeTypes() else ""
comment = de.getComment()
genericName = (" (" + de.getGenericName() + ")") if de.getGenericName() else ""
line = (u"%s / %s%s: %s %s" % (catName, name, genericName, comment, mimeStr)).ljust(250)+" "+hsh+"\n"
menuFile.write(line)
if de.getType() == "Link":
exc = BROWSER_CMD + de.getURL()
else:
#munch field codes we can't do anything with:
for c in 'fFuUdDnNickvm':
exc = exc.replace('%'+c, '')
if de.getTerminal():
exc = TERM_CMD + exc
if de.getPath():
exc = "cd '"+de.getPath()+"'; "+exc
execs[hsh] = hsh + " " + exc + "\n"
categories = {}
for dir in SEARCH_DIRS:
fnames = glob.glob(dir+'/*/*.desktop')
for fname in fnames:
de = DesktopEntry(fname)
cats = de.getCategories() or ["All"]
for cat in cats:
if not cat in categories:
categories[cat] = []
categories[cat].append(de)
for k, v in sorted(categories.items()):
catName = k
for de in v:
if de.getNoDisplay() or de.getHidden():
continue
mainGroup = de.defaultGroup
printEntry(catName, de, True)
for group in de.groups():
if group != mainGroup:
de.defaultGroup = group
printEntry(catName, de, False)
for exc in execs.values():
execFile.write(exc)
menuFile.close()
execFile.close()