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
import _
9 from zeroinstall
.injector
import requirements
10 from zeroinstall
.injector
.policy
import Policy
11 from zeroinstall
.injector
.config
import load_config
12 from zeroinstall
.support
import tasks
14 _recalculate
= tasks
.Blocker('recalculate')
17 """Ask the mainloop to recalculate. If we're already recalculating, wait for that to finish
18 and then do it again."""
20 _recalculate
.trigger()
21 _recalculate
= tasks
.Blocker('recalculate')
24 parser
= OptionParser(usage
=_("usage: %prog [options] interface"))
25 parser
.add_option("", "--before", help=_("choose a version before this"), metavar
='VERSION')
26 parser
.add_option("", "--cpu", help=_("target CPU type"), metavar
='CPU')
27 parser
.add_option("", "--command", help=_("command to select"), metavar
='COMMAND')
28 parser
.add_option("-d", "--download-only", help=_("fetch but don't run"), action
='store_true')
29 parser
.add_option("", "--message", help=_("message to display when interacting with user"))
30 parser
.add_option("", "--not-before", help=_("minimum version to choose"), metavar
='VERSION')
31 parser
.add_option("", "--os", help=_("target operation system type"), metavar
='OS')
32 parser
.add_option("-r", "--refresh", help=_("check for updates of all interfaces"), action
='store_true')
33 parser
.add_option("", "--select-only", help=_("only download the feeds"), action
='store_true')
34 parser
.add_option("-s", "--source", help=_("select source code"), action
='store_true')
35 parser
.add_option("", "--systray", help=_("download in the background"), action
='store_true')
36 parser
.add_option("-v", "--verbose", help=_("more verbose output"), action
='count')
37 parser
.add_option("-V", "--version", help=_("display version information"), action
='store_true')
38 parser
.add_option("", "--with-store", help=_("add an implementation cache"), action
='append', metavar
='DIR')
40 parser
.disable_interspersed_args()
42 (options
, args
) = parser
.parse_args(args
)
46 logger
= logging
.getLogger()
47 if options
.verbose
== 1:
48 logger
.setLevel(logging
.INFO
)
50 logger
.setLevel(logging
.DEBUG
)
55 print "0launch-gui (zero-install) " + gui
.version
56 print "Copyright (C) 2010 Thomas Leonard"
57 print _("This program comes with ABSOLUTELY NO WARRANTY,"
58 "\nto the extent permitted by law."
59 "\nYou may redistribute copies of this program"
60 "\nunder the terms of the GNU Lesser General Public License."
61 "\nFor more information about these matters, see the file named COPYING.")
65 if gtk
.gdk
.get_display() is None:
66 print >>sys
.stderr
, "Failed to connect to display. Aborting."
69 handler
= gui
.GUIHandler()
71 config
= load_config(handler
)
73 if options
.with_store
:
74 from zeroinstall
import zerostore
75 for x
in options
.with_store
:
76 config
.stores
.stores
.append(zerostore
.Store(os
.path
.abspath(x
)))
80 box
= preferences
.show_preferences(config
)
81 box
.connect('destroy', gtk
.main_quit
)
85 interface_uri
= args
[0]
91 import mainwindow
, dialog
93 r
= requirements
.Requirements(interface_uri
)
94 r
.parse_options(options
)
96 widgets
= dialog
.Template('main')
98 policy
= Policy(config
= config
, requirements
= r
)
99 root_iface
= config
.iface_cache
.get_interface(interface_uri
)
100 policy
.solver
.record_details
= True
102 window
= mainwindow
.MainWindow(policy
, widgets
, download_only
= bool(options
.download_only
), select_only
= bool(options
.select_only
))
103 handler
.mainwindow
= window
106 window
.set_message(options
.message
)
108 root
= config
.iface_cache
.get_interface(policy
.root
)
109 window
.browser
.set_root(root
)
111 window
.window
.connect('destroy', lambda w
: handler
.abort_all_downloads())
114 window
.use_systray_icon()
118 force_refresh
= bool(options
.refresh
)
120 window
.refresh_button
.set_sensitive(False)
121 window
.browser
.set_update_icons(force_refresh
)
123 solved
= policy
.solve_with_downloads(force
= force_refresh
, update_local
= True)
125 if not window
.systray_icon
:
129 window
.refresh_button
.set_sensitive(True)
130 window
.browser
.highlight_problems()
132 except Exception, ex
:
133 window
.report_exception(ex
)
135 if window
.systray_icon
and window
.systray_icon
.get_visible() and \
136 window
.systray_icon
.is_embedded():
138 window
.systray_icon
.set_tooltip(_('Downloading updates for %s') % root_iface
.get_name())
139 window
.run_button
.set_active(True)
141 # Should already be reporting an error, but
142 # blink it again just in case
143 window
.systray_icon
.set_blinking(True)
145 refresh_clicked
= dialog
.ButtonClickedBlocker(window
.refresh_button
)
146 yield refresh_clicked
, _recalculate
148 if refresh_clicked
.happened
:
151 tasks
.wait_for_blocker(main())