Removed GUI object.
[zeroinstall.git] / zeroinstall / 0launch-gui / 0launch-gui
blob323b83bec4a38b680371df640cea153d8b9cd07a
1 #!/usr/bin/env python
2 import os, sys
4 # This is for pycentral on Debian-type systems. 0launch-gui is a symlink to the
5 # copy in the pycentral source directory. Python does a realpath() on this
6 # before adding the containing directory to sys.path, which means we don't see
7 # the .pyc files. If run as root, this also causes .pyc files to be created in
8 # the source directory, leaving a mess when the package is removed.
9 sys.path.insert(0, os.path.dirname(__file__))
11 from optparse import OptionParser
12 import pygtk; pygtk.require('2.0')
14 __builtins__._ = lambda x: x
16 parser = OptionParser(usage="usage: %prog [options] interface")
17 parser.add_option("", "--before", help="choose a version before this", metavar='VERSION')
18 parser.add_option("-c", "--cache", help="show the cache", action='store_true')
19 parser.add_option("-d", "--download-only", help="fetch but don't run", action='store_true')
20 parser.add_option("", "--not-before", help="minimum version to choose", metavar='VERSION')
21 parser.add_option("-r", "--refresh", help="check for updates of all interfaces", action='store_true')
22 parser.add_option("-s", "--source", help="select source code", action='store_true')
23 parser.add_option("-v", "--verbose", help="more verbose output", action='count')
24 parser.add_option("-V", "--version", help="display version information", action='store_true')
26 parser.disable_interspersed_args()
28 (options, args) = parser.parse_args()
30 if options.verbose:
31 import logging
32 logger = logging.getLogger()
33 if options.verbose == 1:
34 logger.setLevel(logging.INFO)
35 else:
36 logger.setLevel(logging.DEBUG)
38 if options.cache:
39 # Must fork before importing gtk, or ATK dies
40 if os.fork():
41 # We exit, so our parent can call waitpid and unblock.
42 sys.exit(0)
43 # The grandchild continues...
45 import gui
47 if options.version:
48 print "0launch-gui (zero-install) " + gui.version
49 print "Copyright (C) 2007 Thomas Leonard"
50 print "This program comes with ABSOLUTELY NO WARRANTY,"
51 print "to the extent permitted by law."
52 print "You may redistribute copies of this program"
53 print "under the terms of the GNU General Public License."
54 print "For more information about these matters, see the file named COPYING."
55 sys.exit(0)
57 import gtk
58 if gtk.gdk.get_display() is None:
59 print >>sys.stderr, "Failed to connect to display. Aborting."
60 sys.exit(1)
62 if not hasattr(gtk, 'combo_box_new_text'):
63 import combo_compat
65 if options.cache:
66 import cache
67 cache_explorer = cache.CacheExplorer()
68 cache_explorer.show()
69 cache_explorer.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
70 gtk.gdk.flush()
71 cache_explorer.populate_model()
72 cache_explorer.window.set_cursor(None)
73 gtk.main()
74 sys.exit(0)
76 if len(args) < 1:
77 parser.print_help()
78 sys.exit(1)
80 interface_uri = args[0]
82 if len(args) > 1:
83 parser.print_help()
84 sys.exit(1)
86 from zeroinstall.injector import model, autopolicy, namespaces
87 from zeroinstall.injector.policy import Policy
88 from zeroinstall.injector.iface_cache import iface_cache
89 from zeroinstall.support import tasks
90 import mainwindow, dialog
92 restrictions = []
93 if options.before or options.not_before:
94 restrictions.append(model.Restriction(model.parse_version(options.before),
95 model.parse_version(options.not_before)))
97 widgets = dialog.Template('main')
99 handler = gui.GUIHandler()
100 policy = Policy(interface_uri, handler, src = bool(options.source))
101 root_iface = iface_cache.get_interface(interface_uri)
102 policy.solver.extra_restrictions[root_iface] = restrictions
103 policy.solver.record_details = True
105 window = mainwindow.MainWindow(policy, widgets, download_only = bool(options.download_only))
106 handler.mainwindow = window
108 root = iface_cache.get_interface(policy.root)
109 window.browser.set_root(root)
111 def abort_all_downloads():
112 for dl in policy.handler.monitored_downloads.values():
113 dl.abort()
114 window.window.connect('destroy', lambda w: abort_all_downloads())
116 @tasks.async
117 def main():
118 solved = policy.solve_with_downloads(force = bool(options.refresh))
120 window.show()
121 yield solved
122 try:
123 tasks.check(solved)
124 except Exception, ex:
125 import traceback
126 traceback.print_exc()
127 dialog.alert(window.window, str(ex))
128 yield []
130 handler.wait_for_blocker(main())