3 from optparse
import OptionParser
5 from zeroinstall
.injector
import model
, download
, autopolicy
, run
, namespaces
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("-D", "--dry-run", help="just print actions", action
='store_true')
12 parser
.add_option("-g", "--gui", help="show graphical policy editor", action
='store_true')
13 parser
.add_option("-l", "--list", help="list all known interfaces", action
='store_true')
14 parser
.add_option("-q", "--quiet", help="suppress informational messages", action
='store_true')
15 parser
.add_option("-r", "--refresh", help="refresh all used interfaces", action
='store_true')
16 parser
.add_option("-v", "--verbose", help="more verbose output", action
='count')
17 parser
.add_option("-V", "--version", help="display version information", action
='store_true')
18 parser
.disable_interspersed_args()
20 (options
, args
) = parser
.parse_args()
22 if options
.verbose
> 1:
24 from logging
import getLogger
, DEBUG
25 getLogger().setLevel(DEBUG
)
31 match
= args
[0].lower()
35 from zeroinstall
.injector
import reader
36 for i
in reader
.list_all_interfaces():
37 if match
and match
not in i
.lower(): continue
43 print "0launch (zero-install) " + zeroinstall
.version
44 print "Copyright (C) 2005 Thomas Leonard"
45 print "This program comes with ABSOLUTELY NO WARRANTY,"
46 print "to the extent permitted by law."
47 print "You may redistribute copies of this program"
48 print "under the terms of the GNU General Public License."
49 print "For more information about these matters, see the file named COPYING."
56 # Singleton instance used everywhere...
57 policy
= autopolicy
.AutoPolicy(args
[0],
58 quiet
= bool(options
.quiet
),
59 verbose
= bool(options
.verbose
),
60 download_only
= bool(options
.download_only
),
61 dry_run
= options
.dry_run
)
63 if options
.gui
is None and os
.environ
.get('DISPLAY', None):
67 options
.gui
= policy
.need_download()
68 if options
.gui
and not options
.quiet
:
69 print "Need to download; switching to GUI mode"
72 policy
.set_root(namespaces
.injector_gui_uri
)
74 # Options apply to actual program, not GUI
75 if options
.download_only
:
76 policy
.download_only
= False
77 prog_args
.insert(0, '--download-only')
79 options
.refresh
= False
80 prog_args
.insert(0, '--refresh')
85 policy
.download_and_execute(prog_args
, refresh
= bool(options
.refresh
))
86 except model
.SafeException
, ex
:
87 print >>sys
.stderr
, ex
89 except autopolicy
.NeedDownload
, ex
: