3 from optparse
import OptionParser
5 from zeroinstall
.injector
import model
, download
, autopolicy
, run
7 parser
= OptionParser(usage
="usage: %prog [options] interface [args]\n"
8 " %prog --list [search-term]")
9 parser
.add_option("-c", "--console", help="never use GUI", action
='store_false', dest
='gui')
10 parser
.add_option("-d", "--download-only", help="fetch but don't run", action
='store_true')
11 parser
.add_option("-g", "--gui", help="show graphical policy editor", action
='store_true')
12 parser
.add_option("-l", "--list", help="list all known interfaces", action
='store_true')
13 parser
.add_option("-q", "--quiet", help="suppress informational messages", action
='store_true')
14 parser
.add_option("-r", "--refresh", help="refresh all used interfaces", action
='store_true')
15 parser
.add_option("-v", "--verbose", help="more verbose output", action
='store_true')
16 parser
.add_option("-V", "--version", help="display version information", action
='store_true')
17 parser
.disable_interspersed_args()
19 (options
, args
) = parser
.parse_args()
25 match
= args
[0].lower()
29 from zeroinstall
.injector
import reader
30 for i
in reader
.list_all_interfaces():
31 if match
and match
not in i
.lower(): continue
37 print "0launch (zero-install) " + zeroinstall
.version
38 print "Copyright (C) 2005 Thomas Leonard"
39 print "This program comes with ABSOLUTELY NO WARRANTY,"
40 print "to the extent permitted by law."
41 print "You may redistribute copies of this program"
42 print "under the terms of the GNU General Public License."
43 print "For more information about these matters, see the file named COPYING."
50 if options
.gui
is None and os
.environ
.get('DISPLAY', None):
54 # Decide whether to use the GUI or not...
56 test_policy
= autopolicy
.AutoPolicy(args
[0], False, quiet
= True)
57 test_policy
.recalculate()
58 test_policy
.start_downloading_impls()
59 except autopolicy
.NeedDownload
:
61 print "Need to download; switching to GUI mode"
65 interface_uri
= 'http://0install.net/2005/interfaces/injector-gui'
67 if options
.download_only
:
68 options
.download_only
= False
69 prog_args
.insert(0, '--download-only')
71 options
.refresh
= False
72 prog_args
.insert(0, '--refresh')
74 interface_uri
= args
[0]
77 # Singleton instance used everywhere...
78 policy
= autopolicy
.AutoPolicy(interface_uri
, True,
79 quiet
= bool(options
.quiet
),
80 verbose
= bool(options
.verbose
),
81 download_only
= bool(options
.download_only
))
85 for x
in policy
.walk_interfaces():
86 policy
.begin_iface_download(x
, False)
90 policy
.wait_for_downloads()
91 except model
.SafeException
, ex
:
92 print >>sys
.stderr
, ex
96 policy
.execute(prog_args
)
97 except model
.SafeException
, ex
:
98 if policy
.network_use
!= model
.network_full
:
100 print >>sys
.stderr
, "Error. Retrying with network use = full"
101 policy
.network_use
= model
.network_full
104 policy
.execute(prog_args
)
105 except model
.SafeException
, ex
:
106 print >>sys
.stderr
, ex
108 print >>sys
.stderr
, ex