Added non-interactive injector-auto.
[zeroinstall.git] / injector / run.py
blob5cbabca9595a81aa5c6d18e1bbcdbdc35d89f520
1 import os, sys
3 from policy import policy
4 from model import *
6 def do_env_binding(binding, iface):
7 impl = get_impl(iface)
8 extra = os.path.join(impl.path, binding.insert)
9 if binding.name in os.environ:
10 os.environ[binding.name] = extra + ':' + os.environ[binding.name]
11 else:
12 os.environ[binding.name] = extra
13 #print "%s=%s" % (binding.name, os.environ[binding.name])
15 def execute(iface, prog, prog_args):
16 def setup_bindings(i):
17 impl = get_impl(i)
18 for dep in impl.dependencies.values():
19 dep_iface = dep.get_interface()
20 for b in dep.bindings:
21 if isinstance(b, EnvironmentBinding):
22 do_env_binding(b, dep_iface)
23 setup_bindings(dep_iface)
24 setup_bindings(iface)
26 prog_path = os.path.join(policy.implementation[iface].path, prog)
27 if not os.path.exists(prog_path):
28 print "'%s' does not exist." % prog_path
29 print "(implementation '%s' + program '%s')" % (policy.implementation[iface].path, prog)
30 sys.exit(1)
31 os.execl(prog_path, prog_path, *prog_args)
33 def get_impl(interface):
34 try:
35 return policy.implementation[interface]
36 except KeyError:
37 if not interface.name:
38 raise SafeException("We don't have enough information to "
39 "run this program yet. "
40 "Need to download:\n%s" % interface.uri)
41 if interface.implementations:
42 offline = ""
43 if policy.network_use == network_offline:
44 offline = "\nThis may be because 'Network Use' is set to Off-line."
45 raise SafeException("No usable implementation found for '%s'.%s" %
46 (interface.name, offline))