~kxteam/xts/xts-server-trunk

« back to all changes in this revision

Viewing changes to src/xts-getapps.in

  • Committer: Joshua Mark Higgins
  • Date: 2013-04-08 00:01:22 UTC
  • Revision ID: joshiggins@gmail.com-20130408000122-0aedn2unx9r5hfmn
Started xts-getapps, implemented basic functionality of reading XDG menu, and creating .desktop files under ~/.local/share/applications prepending exec lines with xts-remoterun

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
'''
3
3
xts-getapps
4
4
 
5
 
    Get the .desktop files from an Xpra server to send
6
 
    to a terminal client
 
5
    Get the .desktop files and cache them in ~/.local/share/applications,
 
6
    prepending xts-remoterun to the exec lines
7
7
 
8
8
Copyright 2012 Joshua Higgins
9
9
 
26
26
 
27
27
import sys
28
28
sys.path.insert(1, '@pythondir@')
 
29
 
 
30
 
 
31
import os
 
32
import xdg.Menu
 
33
 
 
34
 
 
35
XDGMENU = "/etc/xdg/menus/xts-applications.menu"
 
36
APPSDIR = "~/.local/share/applications"
 
37
 
 
38
 
 
39
if __name__ == "__main__":
 
40
    USERAPPSDIR = os.path.expanduser(APPSDIR)
 
41
    # ensure local application directory exists
 
42
    if not os.path.exists(USERAPPSDIR):
 
43
        os.makedirs(USERAPPSDIR)
 
44
    # walk the menu xdg style
 
45
    xdgmenu = xdg.Menu.parse(XDGMENU)
 
46
    for entry in xdgmenu.getEntries():
 
47
        if isinstance(entry, xdg.Menu.Menu) and entry.Show is True:
 
48
            for entry2 in entry.getEntries():
 
49
                try:
 
50
                    # read existing desktop entry
 
51
                    name = entry2.DesktopEntry.getName()
 
52
                    icon = entry2.DesktopEntry.getIcon()
 
53
                    categories = entry2.DesktopEntry.getCategories()
 
54
                    # make new exec line
 
55
                    texec = entry2.DesktopEntry.getExec().split("%")[0]
 
56
                    nexec = "xts-remoteapp " + texec
 
57
                    # write new desktop entry
 
58
                    filename = USERAPPSDIR + "/" + entry2.Filename
 
59
                    f = open(filename, "w")
 
60
                    f.write("[Desktop Entry]\n")
 
61
                    f.write("Name=" + name + "\n")
 
62
                    f.write("Icon=" + icon + "\n")
 
63
                    f.write("Categories=" + ";".join(categories) + "\n")
 
64
                    f.write("Exec=" + nexec + "\n")
 
65
                    f.close()
 
66
                    print "written", filename
 
67
                except Exception as e:
 
68
                    print "could not write", filename, str(e)
 
 
b'\\ No newline at end of file'