3 from policy
import policy
6 def do_env_binding(binding
, 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
]
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
):
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
)
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
)
31 os
.execl(prog_path
, prog_path
, *prog_args
)
33 def get_impl(interface
):
35 return policy
.implementation
[interface
]
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
:
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
))