If a service property exists but the window it points to doesn't, then
[rox-lib.git] / python / rox / launch.py
blob24a15aeddd179377f9c554409284b23f4ed21238
1 """Launch programs using 0launch"""
3 import os
4 from rox import _
6 class InjectorNotInstalled(Exception):
7 uri = None
8 def __init__(self, uri):
9 self.uri = uri
10 Exception.__init__(self,
11 _("The program '%s' cannot be run, as the "
12 "0launch command is not available. "
13 "It can be downloaded from here:\n\n"
14 "http://0install.net/injector.html") % uri)
16 def launch(*args):
17 """Runs a program using 0launch, and returns the PID.
18 If 0launch isn't installed, it raises InjectorNotInstalled,
19 telling the user how to get it."""
20 binpath = os.environ.get('PATH', '').split(':')
21 # Try to run with '0launch'
22 for bindir in binpath:
23 path = os.path.join(bindir, '0launch')
24 if os.path.isfile(path):
25 break
26 else:
27 for x in args:
28 if not x.startswith('-'):
29 raise InjectorNotInstalled(x)
30 raise InjectorNotInstalled(repr(args))
32 pid = os.spawnvp(os.P_NOWAIT, '0launch', ('0launch',) + args)
33 return pid