0install update: reload feed after running the GUI
[zeroinstall/solver.git] / zeroinstall / cmd / update.py
blob001aa8875de1e9d3a3e34125bb3aec9bd8bdd919
1 """
2 The B{0install download} command-line interface.
3 """
5 # Copyright (C) 2011, Thomas Leonard
6 # See the README file for details, or visit http://0install.net.
8 from __future__ import print_function
10 import sys
12 from zeroinstall import SafeException, _
13 from zeroinstall.injector import model, requirements
14 from zeroinstall.cmd import UsageError, select
16 syntax = "URI"
18 add_options = select.add_generic_select_options
20 def handle(config, options, args):
21 if len(args) != 1:
22 raise UsageError()
24 assert not options.offline
26 old_gui = options.gui
28 app = config.app_mgr.lookup_app(args[0], missing_ok = True)
29 if app is not None:
30 old_sels = app.get_selections()
31 old_selections = old_sels.selections
32 iface_uri = old_sels.interface
33 r = app.get_requirements()
34 r.parse_update_options(options)
35 else:
36 iface_uri = model.canonical_iface_uri(args[0])
38 r = requirements.Requirements(iface_uri)
39 r.parse_options(options)
41 # Select once in offline console mode to get the old values
42 options.offline = True
43 options.gui = False
44 options.refresh = False
46 try:
47 old_sels = select.get_selections_for(r, config, options,
48 select_only = True, download_only = False, test_callback = None)
49 except SafeException:
50 old_selections = {}
51 else:
52 if old_sels is None:
53 old_selections = {}
54 else:
55 old_selections = old_sels.selections
57 # Download in online mode to get the new values
58 config.network_use = model.network_full
59 options.offline = False
60 options.gui = old_gui
61 options.refresh = True
63 sels = select.get_selections_for(r, config, options,
64 select_only = False, download_only = True, test_callback = None)
65 if not sels:
66 sys.exit(1) # Aborted by user
68 root_feed = config.iface_cache.get_feed(iface_uri)
69 if root_feed:
70 target = root_feed.get_replaced_by()
71 if target is not None:
72 print(_("Warning: interface {old} has been replaced by {new}".format(old = iface_uri, new = target)))
74 from zeroinstall.cmd import whatchanged
75 changes = whatchanged.show_changes(old_selections, sels.selections)
77 root_sel = sels[iface_uri]
78 root_iface = config.iface_cache.get_interface(iface_uri)
79 # Force a reload, since we may have used the GUI to update it
80 for feed in config.iface_cache.get_feeds(root_iface):
81 config.iface_cache.get_feed(feed, force = True)
83 root_impls = config.iface_cache.get_implementations(root_iface)
85 latest = max((impl.version, impl) for impl in root_impls)[1]
86 if latest.version > model.parse_version(sels[iface_uri].version):
87 print(_("A later version ({name} {latest}) exists but was not selected. Using {version} instead.").format(
88 latest = latest.get_version(),
89 name = root_iface.get_name(),
90 version = root_sel.version))
91 if not config.help_with_testing and latest.get_stability() < model.stable:
92 print(_('To select "testing" versions, use:\n0install config help_with_testing True'))
93 elif not changes:
94 from zeroinstall.support import xmltools
96 # No obvious changes, but check for more subtle updates.
97 if xmltools.nodes_equal(sels.toDOM(), old_sels.toDOM()):
98 print(_("No updates found. Continuing with version {version}.").format(version = root_sel.version))
99 else:
100 changes = True
101 print(_("Updates to metadata found, but no change to version ({version}).").format(version = root_sel.version))
103 if app is not None:
104 if changes:
105 app.set_selections(sels)
106 app.set_requirements(r)