4
def get_dirlist(folder, depth=0, include=None, exclude=None):
6
Return a list of absolute paths in folder
7
include, exclude: a function returning a boolean
13
def include_file(file):
14
return (not include or include(file)) and (not exclude or not exclude(file))
16
for dirname, dirnames, fnames in walk(folder):
17
# skip deep directories
19
while not path.samefile(head, folder):
20
head, tail = path.split(head)
28
if not include_file(dir):
31
abspath = path.join(dirname, dir)
35
if not include_file(file):
37
abspath = path.join(dirname, file)
40
for dir in reversed(excl_dir):
45
def spawn_async(argv, in_dir=None):
47
from os import chdir, getcwd
51
ret = gobject.spawn_async (argv, flags=gobject.SPAWN_SEARCH_PATH)
55
def get_xdg_data_dirs():
57
Return a list of XDG data directories
59
From the deskbar applet project
63
dirs = os.getenv("XDG_DATA_HOME")
65
dirs = os.path.expanduser("~/.local/share")
67
sysdirs = os.getenv("XDG_DATA_DIRS")
69
sysdirs = "/usr/local/share:/usr/share"
71
dirs = "%s:%s" % (dirs, sysdirs)
72
return [dir for dir in dirs.split(":") if dir.strip() != "" and path.exists(dir)]
74
def new_desktop_item(exec_path, in_terminal=False):
76
Return a new desktop item with given exec_path
78
It will set name from the path, and set the item to to
79
Application. Some additional properties can be set too.
81
from gnomedesktop import item_new_from_string
82
import gnomedesktop as gd
83
name = path.basename(exec_path)
86
# Escape \ " ` $ with another \
89
esc_chars = (bsl, quot, '`', '$')
90
escaped = [bsl*(c in esc_chars) + c for c in unicode(exec_path)]
91
escaped.insert(0, quot)
93
exec_path_escaped = u"".join(escaped)
95
item = gd.DesktopItem()
96
item.set_entry_type(gd.TYPE_APPLICATION)
97
item.set_string(gd.KEY_NAME, name)
98
item.set_string(gd.KEY_EXEC, exec_path_escaped)
99
item.set_boolean(gd.KEY_TERMINAL, in_terminal)