1 # Copyright (C) 2008, Thomas Leonard
2 # See the README file for details, or visit http://0install.net.
6 from optparse
import OptionParser
8 from zeroinstall
.injector
import model
, autopolicy
, namespaces
9 from zeroinstall
.injector
.policy
import Policy
10 from zeroinstall
.injector
.iface_cache
import iface_cache
11 from zeroinstall
.support
import tasks
14 parser
= OptionParser(usage
="usage: %prog [options] interface")
15 parser
.add_option("", "--before", help="choose a version before this", metavar
='VERSION')
16 parser
.add_option("-c", "--cache", help="show the cache", action
='store_true')
17 parser
.add_option("-d", "--download-only", help="fetch but don't run", action
='store_true')
18 parser
.add_option("", "--not-before", help="minimum version to choose", metavar
='VERSION')
19 parser
.add_option("-r", "--refresh", help="check for updates of all interfaces", action
='store_true')
20 parser
.add_option("-s", "--source", help="select source code", action
='store_true')
21 parser
.add_option("-v", "--verbose", help="more verbose output", action
='count')
22 parser
.add_option("-V", "--version", help="display version information", action
='store_true')
24 parser
.disable_interspersed_args()
26 (options
, args
) = parser
.parse_args(args
)
30 logger
= logging
.getLogger()
31 if options
.verbose
== 1:
32 logger
.setLevel(logging
.INFO
)
34 logger
.setLevel(logging
.DEBUG
)
37 # Must fork before importing gtk, or ATK dies
39 # We exit, so our parent can call waitpid and unblock.
41 # The grandchild continues...
46 print "0launch-gui (zero-install) " + gui
.version
47 print "Copyright (C) 2007 Thomas Leonard"
48 print "This program comes with ABSOLUTELY NO WARRANTY,"
49 print "to the extent permitted by law."
50 print "You may redistribute copies of this program"
51 print "under the terms of the GNU General Public License."
52 print "For more information about these matters, see the file named COPYING."
56 if gtk
.gdk
.get_display() is None:
57 print >>sys
.stderr
, "Failed to connect to display. Aborting."
60 if not hasattr(gtk
, 'combo_box_new_text'):
65 cache_explorer
= cache
.CacheExplorer()
67 cache_explorer
.window
.set_cursor(gtk
.gdk
.Cursor(gtk
.gdk
.WATCH
))
69 cache_explorer
.populate_model()
70 cache_explorer
.window
.set_cursor(None)
78 interface_uri
= args
[0]
84 import mainwindow
, dialog
87 if options
.before
or options
.not_before
:
88 restrictions
.append(model
.VersionRangeRestriction(model
.parse_version(options
.before
),
89 model
.parse_version(options
.not_before
)))
91 widgets
= dialog
.Template('main')
93 handler
= gui
.GUIHandler()
94 policy
= Policy(interface_uri
, handler
, src
= bool(options
.source
))
95 root_iface
= iface_cache
.get_interface(interface_uri
)
96 policy
.solver
.extra_restrictions
[root_iface
] = restrictions
97 policy
.solver
.record_details
= True
99 window
= mainwindow
.MainWindow(policy
, widgets
, download_only
= bool(options
.download_only
))
100 handler
.mainwindow
= window
102 root
= iface_cache
.get_interface(policy
.root
)
103 window
.browser
.set_root(root
)
105 window
.window
.connect('destroy', lambda w
: handler
.abort_all_downloads())
109 force_refresh
= bool(options
.refresh
)
111 window
.refresh_button
.set_sensitive(False)
113 solved
= policy
.solve_with_downloads(force
= force_refresh
)
118 window
.refresh_button
.set_sensitive(True)
120 except model
.SafeException
, ex
:
121 dialog
.alert(window
.window
, str(ex
))
122 except Exception, ex
:
124 traceback
.print_exc()
125 dialog
.alert(window
.window
, str(ex
))
127 yield dialog
.ButtonClickedBlocker(window
.refresh_button
)
130 handler
.wait_for_blocker(main())