Fixed argument expansion for quoted arguments.
[rox-shell.git] / roxshell / support.py
blob0d033858c44c813a1d9ab782aa6349b089737cf4
1 """
2 @copyright: (C) 2008, Thomas Leonard
3 @see: U{http://roscidus.com}
4 """
6 import gobject
7 from logging import debug
8 import os
9 from zeroinstall.support import tasks # tmp
11 def wait_for_blocker(blocker):
12 """Run a recursive mainloop until blocker is triggered.
13 @param blocker: event to wait on
14 @type blocker: L{tasks.Blocker}"""
15 if not blocker.happened:
16 loop = gobject.MainLoop(gobject.main_context_default())
17 def quitter():
18 yield blocker
19 loop.quit()
20 quit = tasks.Task(quitter(), "quitter")
22 debug("Entering mainloop, waiting for %s", blocker)
23 loop.run()
25 assert blocker.happened, "Someone quit the main loop!"
27 tasks.check(blocker)
29 def find_in_path(cmd):
30 if os.path.isabs(cmd):
31 return cmd
32 for x in os.environ['PATH'].split(':'):
33 full = os.path.join(x, cmd)
34 if os.path.exists(full):
35 return full
36 return None
38 def split_expanded_path(value):
39 """Like os.path.split(os.path.expanduser(value))"""
40 if value.startswith('~'):
41 value = os.path.expanduser(value)
42 if value.startswith('~') and '/' not in value:
43 value = os.path.join(os.path.dirname(os.path.expanduser('~')), value[1:])
44 return os.path.split(value)