3 from optparse
import OptionParser
5 from zeroinstall
.injector
import model
, autopolicy
, namespaces
6 from zeroinstall
.injector
.policy
import Policy
7 from zeroinstall
.injector
.iface_cache
import iface_cache
8 from zeroinstall
.support
import tasks
11 parser
= OptionParser(usage
="usage: %prog [options] interface")
12 parser
.add_option("", "--before", help="choose a version before this", metavar
='VERSION')
13 parser
.add_option("-c", "--cache", help="show the cache", action
='store_true')
14 parser
.add_option("-d", "--download-only", help="fetch but don't run", action
='store_true')
15 parser
.add_option("", "--not-before", help="minimum version to choose", metavar
='VERSION')
16 parser
.add_option("-r", "--refresh", help="check for updates of all interfaces", action
='store_true')
17 parser
.add_option("-s", "--source", help="select source code", action
='store_true')
18 parser
.add_option("-v", "--verbose", help="more verbose output", action
='count')
19 parser
.add_option("-V", "--version", help="display version information", action
='store_true')
21 parser
.disable_interspersed_args()
23 (options
, args
) = parser
.parse_args(args
)
27 logger
= logging
.getLogger()
28 if options
.verbose
== 1:
29 logger
.setLevel(logging
.INFO
)
31 logger
.setLevel(logging
.DEBUG
)
34 # Must fork before importing gtk, or ATK dies
36 # We exit, so our parent can call waitpid and unblock.
38 # The grandchild continues...
43 print "0launch-gui (zero-install) " + gui
.version
44 print "Copyright (C) 2007 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."
53 if gtk
.gdk
.get_display() is None:
54 print >>sys
.stderr
, "Failed to connect to display. Aborting."
57 if not hasattr(gtk
, 'combo_box_new_text'):
62 cache_explorer
= cache
.CacheExplorer()
64 cache_explorer
.window
.set_cursor(gtk
.gdk
.Cursor(gtk
.gdk
.WATCH
))
66 cache_explorer
.populate_model()
67 cache_explorer
.window
.set_cursor(None)
75 interface_uri
= args
[0]
81 import mainwindow
, dialog
84 if options
.before
or options
.not_before
:
85 restrictions
.append(model
.VersionRangeRestriction(model
.parse_version(options
.before
),
86 model
.parse_version(options
.not_before
)))
88 widgets
= dialog
.Template('main')
90 handler
= gui
.GUIHandler()
91 policy
= Policy(interface_uri
, handler
, src
= bool(options
.source
))
92 root_iface
= iface_cache
.get_interface(interface_uri
)
93 policy
.solver
.extra_restrictions
[root_iface
] = restrictions
94 policy
.solver
.record_details
= True
96 window
= mainwindow
.MainWindow(policy
, widgets
, download_only
= bool(options
.download_only
))
97 handler
.mainwindow
= window
99 root
= iface_cache
.get_interface(policy
.root
)
100 window
.browser
.set_root(root
)
102 window
.window
.connect('destroy', lambda w
: handler
.abort_all_downloads())
106 force_refresh
= bool(options
.refresh
)
108 window
.refresh_button
.set_sensitive(False)
110 solved
= policy
.solve_with_downloads(force
= force_refresh
)
115 window
.refresh_button
.set_sensitive(True)
117 except model
.SafeException
, ex
:
118 dialog
.alert(window
.window
, str(ex
))
119 except Exception, ex
:
121 traceback
.print_exc()
122 dialog
.alert(window
.window
, str(ex
))
124 yield dialog
.ButtonClickedBlocker(window
.refresh_button
)
127 handler
.wait_for_blocker(main())