1 # Copyright (C) 2009, 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
, arch
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("", "--cpu", help="target CPU type", metavar
='CPU')
17 parser
.add_option("-c", "--cache", help="show the cache", action
='store_true')
18 parser
.add_option("-d", "--download-only", help="fetch but don't run", action
='store_true')
19 parser
.add_option("", "--message", help="message to display when interacting with user")
20 parser
.add_option("", "--not-before", help="minimum version to choose", metavar
='VERSION')
21 parser
.add_option("", "--os", help="target operation system type", metavar
='OS')
22 parser
.add_option("-r", "--refresh", help="check for updates of all interfaces", action
='store_true')
23 parser
.add_option("-s", "--source", help="select source code", action
='store_true')
24 parser
.add_option("-v", "--verbose", help="more verbose output", action
='count')
25 parser
.add_option("-V", "--version", help="display version information", action
='store_true')
27 parser
.disable_interspersed_args()
29 (options
, args
) = parser
.parse_args(args
)
33 logger
= logging
.getLogger()
34 if options
.verbose
== 1:
35 logger
.setLevel(logging
.INFO
)
37 logger
.setLevel(logging
.DEBUG
)
40 # Must fork before importing gtk, or ATK dies
42 # We exit, so our parent can call waitpid and unblock.
44 # The grandchild continues...
49 print "0launch-gui (zero-install) " + gui
.version
50 print "Copyright (C) 2007 Thomas Leonard"
51 print "This program comes with ABSOLUTELY NO WARRANTY,"
52 print "to the extent permitted by law."
53 print "You may redistribute copies of this program"
54 print "under the terms of the GNU General Public License."
55 print "For more information about these matters, see the file named COPYING."
59 if gtk
.gdk
.get_display() is None:
60 print >>sys
.stderr
, "Failed to connect to display. Aborting."
63 if not hasattr(gtk
, 'combo_box_new_text'):
68 cache_explorer
= cache
.CacheExplorer()
70 cache_explorer
.window
.set_cursor(gtk
.gdk
.Cursor(gtk
.gdk
.WATCH
))
72 cache_explorer
.populate_model()
73 cache_explorer
.window
.set_cursor(None)
81 interface_uri
= args
[0]
87 import mainwindow
, dialog
90 if options
.before
or options
.not_before
:
91 restrictions
.append(model
.VersionRangeRestriction(model
.parse_version(options
.before
),
92 model
.parse_version(options
.not_before
)))
94 widgets
= dialog
.Template('main')
96 handler
= gui
.GUIHandler()
97 policy
= Policy(interface_uri
, handler
, src
= bool(options
.source
))
98 policy
.target_arch
= arch
.get_architecture(options
.os
, options
.cpu
)
99 root_iface
= iface_cache
.get_interface(interface_uri
)
100 policy
.solver
.extra_restrictions
[root_iface
] = restrictions
101 policy
.solver
.record_details
= True
103 window
= mainwindow
.MainWindow(policy
, widgets
, download_only
= bool(options
.download_only
))
104 handler
.mainwindow
= window
107 window
.set_message(options
.message
)
109 root
= iface_cache
.get_interface(policy
.root
)
110 window
.browser
.set_root(root
)
112 window
.window
.connect('destroy', lambda w
: handler
.abort_all_downloads())
116 force_refresh
= bool(options
.refresh
)
118 window
.refresh_button
.set_sensitive(False)
120 solved
= policy
.solve_with_downloads(force
= force_refresh
)
125 window
.refresh_button
.set_sensitive(True)
127 except model
.SafeException
, ex
:
128 dialog
.alert(window
.window
, str(ex
))
129 except Exception, ex
:
131 traceback
.print_exc()
132 dialog
.alert(window
.window
, str(ex
))
134 yield dialog
.ButtonClickedBlocker(window
.refresh_button
)
137 handler
.wait_for_blocker(main())