#!/usr/bin/env python ################################################# # Python script to install a new .desktop files # # Usage: # # - domenu file1 file2 file3 ... # # - domenu dir1 dir2 dir3 ... # # - domenu file1 dir1 ... # ################################################# import sys, os, re try: from xdg.DesktopEntry import * from xdg.Exceptions import * except ImportError: noxdg = True def domenu(path): if os.path.isfile(path): if re.search(".desktop$", path): print ">>> domenu: making " + path + " menu entry..." if not noxdg: try: file = DesktopEntry() file.parse(path) file.validate("Errors") os.system("install -m0644 " + path + " " + os.path.join(D, "usr/share/applications)")) except ValidationError, e: print e else: os.system("install -m0644 " + path + " " + os.path.join(D, "usr/share/applications")) elif os.path.isdir(path): ls = os.listdir(path) for i in ls: domenu(os.path.join(path, i)) D = os.getenv("D") os.system("install -d " + os.path.join(D, "usr/share/applications")) for i in range(1,len(sys.argv)): domenu(sys.argv[i])