Perform GUI downloads in the main window.
[zeroinstall/zeroinstall-rsl.git] / zeroinstall / 0launch-gui / 0launch-gui
blob68002bef10ac7e50856ab3555fc331c8ec547fd6
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 options.verbose = 1
32 if options.verbose:
33 import logging
34 logger = logging.getLogger()
35 if options.verbose == 1:
36 logger.setLevel(logging.INFO)
37 else:
38 logger.setLevel(logging.DEBUG)
40 if options.cache:
41 # Must fork before importing gtk, or ATK dies
42 if os.fork():
43 # We exit, so our parent can call waitpid and unblock.
44 sys.exit(0)
45 # The grandchild continues...
47 import gui
49 if options.version:
50 print "0launch-gui (zero-install) " + gui.version
51 print "Copyright (C) 2007 Thomas Leonard"
52 print "This program comes with ABSOLUTELY NO WARRANTY,"
53 print "to the extent permitted by law."
54 print "You may redistribute copies of this program"
55 print "under the terms of the GNU General Public License."
56 print "For more information about these matters, see the file named COPYING."
57 sys.exit(0)
59 import gtk
60 if gtk.gdk.get_display() is None:
61 print >>sys.stderr, "Failed to connect to display. Aborting."
62 sys.exit(1)
64 if not hasattr(gtk, 'combo_box_new_text'):
65 import combo_compat
67 if options.cache:
68 import cache
69 cache_explorer = cache.CacheExplorer()
70 cache_explorer.show()
71 cache_explorer.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
72 gtk.gdk.flush()
73 cache_explorer.populate_model()
74 cache_explorer.window.set_cursor(None)
75 gtk.main()
76 sys.exit(0)
78 if len(args) < 1:
79 parser.print_help()
80 sys.exit(1)
82 interface_uri = args[0]
84 if len(args) > 1:
85 parser.print_help()
86 sys.exit(1)
88 from zeroinstall.injector import model, autopolicy, namespaces
89 from zeroinstall.support import tasks
91 restrictions = []
92 if options.before or options.not_before:
93 restrictions.append(model.Restriction(model.parse_version(options.before),
94 model.parse_version(options.not_before)))
96 policy = gui.GUIPolicy(interface_uri,
97 download_only = bool(options.download_only),
98 refresh = bool(options.refresh),
99 src = options.source,
100 restrictions = restrictions)
101 main = tasks.Task(policy.main(), "main")
102 policy.handler.wait_for_blocker(main.finished)