4 __builtins__
._ = lambda x
: x
7 print "Usage: injector INTERFACE [ARGS]"
9 print "injector http://example.com/myprog.xml --help"
11 interface_uri
= sys
.argv
[1]
12 if not interface_uri
.startswith('http:'):
13 interface_uri
= os
.path
.realpath(interface_uri
) # For testing
14 prog_args
= sys
.argv
[2:]
17 from policy
import Policy
24 class AutoPolicy(Policy
):
25 monitored_downloads
= None
27 def __init__(self
, interface_uri
):
28 Policy
.__init
__(self
, interface_uri
)
29 self
.monitored_downloads
= []
31 def monitor_download(self
, dl
):
32 error_stream
= dl
.start()
33 self
.monitored_downloads
.append((error_stream
, dl
))
35 def start_downloading_impls(self
):
36 for impl
in self
.get_uncached_implementations():
37 if not impl
.download_sources
:
38 raise SafeException("Implementation " + impl
+ " of "
39 "interface " + impl
.interface
+ " cannot be "
40 "downloaded (no download locations given in "
42 dl
= download
.begin_impl_download(impl
.download_sources
[0])
43 self
.monitor_download(dl
)
45 # Singleton instance used everywhere...
46 policy
= AutoPolicy(interface_uri
)
49 def wait_for_downloads():
50 while policy
.monitored_downloads
:
51 print "Currently downloading:"
52 for e
, dl
in policy
.monitored_downloads
:
55 for e
, dl
in policy
.monitored_downloads
[:]:
58 print "Got errors:", errors
60 policy
.monitored_downloads
.remove((e
, dl
))
61 data
= dl
.error_stream_closed()
62 if isinstance(dl
, download
.InterfaceDownload
):
63 policy
.check_signed_data(dl
, data
)
64 elif isinstance(dl
, download
.ImplementationDownload
):
65 policy
.add_to_cache(dl
.source
, data
)
67 raise Exception("Unknown download type %s" % dl
)
72 policy
.start_downloading_impls()
76 run
.execute(policy
, prog_args
)
83 except model
.SafeException
, ex
:
84 if policy
.network_use
!= model
.network_full
:
85 print >>sys
.stderr
, "Error. Retrying with network use = full"
86 policy
.network_use
= model
.network_full
90 except model
.SafeException
, ex
:
91 print >>sys
.stderr
, ex
93 print >>sys
.stderr
, ex