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("-t", "--trust", help="add a trusted key", action
='append', metavar
='FINGERPRINT')
16 parser
.add_option("-v", "--verbose", help="more verbose output", action
='store_true')
17 parser
.add_option("-V", "--version", help="display version information", action
='store_true')
18 parser
.disable_interspersed_args()
20 (options
, args
) = parser
.parse_args()
23 from zeroinstall
.injector
import trust
24 for x
in options
.trust
:
25 if trust
.trust_db
.trust_key(x
) and options
.verbose
is True:
26 print "Marked key with fingerprint '%s' as trusted." % x
32 match
= args
[0].lower()
36 from zeroinstall
.injector
import reader
37 for i
in reader
.list_all_interfaces():
38 if match
and match
not in i
.lower(): continue
44 print "0launch (zero-install) " + zeroinstall
.version
45 print "Copyright (C) 2005 Thomas Leonard"
46 print "This program comes with ABSOLUTELY NO WARRANTY,"
47 print "to the extent permitted by law."
48 print "You may redistribute copies of this program"
49 print "under the terms of the GNU General Public License."
50 print "For more information about these matters, see the file named COPYING."
59 if options
.gui
is None and os
.environ
.get('DISPLAY', None):
63 # Decide whether to use the GUI or not...
65 test_policy
= autopolicy
.AutoPolicy(args
[0], False, quiet
= True)
66 test_policy
.recalculate()
67 test_policy
.start_downloading_impls()
68 except autopolicy
.NeedDownload
:
70 print "Need to download; switching to GUI mode"
74 interface_uri
= 'http://0install.net/2005/interfaces/injector-gui'
76 if options
.download_only
:
77 options
.download_only
= False
78 prog_args
.insert(0, '--download-only')
80 options
.refresh
= False
81 prog_args
.insert(0, '--refresh')
83 interface_uri
= args
[0]
86 # Singleton instance used everywhere...
87 policy
= autopolicy
.AutoPolicy(interface_uri
, True,
88 quiet
= bool(options
.quiet
),
89 verbose
= bool(options
.verbose
),
90 download_only
= bool(options
.download_only
))
94 for x
in policy
.walk_interfaces():
95 policy
.begin_iface_download(x
, False)
99 policy
.wait_for_downloads()
100 except model
.SafeException
, ex
:
101 print >>sys
.stderr
, ex
105 policy
.execute(prog_args
)
106 except model
.SafeException
, ex
:
107 if policy
.network_use
!= model
.network_full
:
108 if not options
.quiet
:
109 print >>sys
.stderr
, "Error. Retrying with network use = full"
110 policy
.network_use
= model
.network_full
113 policy
.execute(prog_args
)
114 except model
.SafeException
, ex
:
115 print >>sys
.stderr
, ex
117 print >>sys
.stderr
, ex