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()
32 logger
= logging
.getLogger()
33 if options
.verbose
== 1:
34 logger
.setLevel(logging
.INFO
)
36 logger
.setLevel(logging
.DEBUG
)
39 # Must fork before importing gtk, or ATK dies
41 # We exit, so our parent can call waitpid and unblock.
43 # The grandchild continues...
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."
58 if gtk
.gdk
.get_display() is None:
59 print >>sys
.stderr
, "Failed to connect to display. Aborting."
62 if not hasattr(gtk
, 'combo_box_new_text'):
67 cache_explorer
= cache
.CacheExplorer()
69 cache_explorer
.window
.set_cursor(gtk
.gdk
.Cursor(gtk
.gdk
.WATCH
))
71 cache_explorer
.populate_model()
72 cache_explorer
.window
.set_cursor(None)
80 interface_uri
= args
[0]
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
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():
114 window
.window
.connect('destroy', lambda w
: abort_all_downloads())
118 solved
= policy
.solve_with_downloads(force
= bool(options
.refresh
))
124 except Exception, ex
:
126 traceback
.print_exc()
127 dialog
.alert(window
.window
, str(ex
))
130 handler
.wait_for_blocker(main())