Warn about replaced interfaces in "0install update"
[zeroinstall/solver.git] / zeroinstall / cmd / update.py
blobc4cc4a8d4b18d0fdc312b8bbe96c6cc150da8202
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
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 iface_uri = model.canonical_iface_uri(args[0])
28 old_gui = options.gui
30 # Select once in offline console mode to get the old values
31 options.offline = True
32 options.gui = False
33 options.refresh = False
35 try:
36 old_sels = select.get_selections(config, options, iface_uri,
37 select_only = True, download_only = False, test_callback = None)
38 except SafeException:
39 old_selections = {}
40 else:
41 if old_sels is None:
42 old_selections = {}
43 else:
44 old_selections = old_sels.selections
46 # Download in online mode to get the new values
47 config.network_use = model.network_full
48 options.offline = False
49 options.gui = old_gui
50 options.refresh = True
52 sels = select.get_selections(config, options, iface_uri,
53 select_only = False, download_only = True, test_callback = None)
54 if not sels:
55 sys.exit(1) # Aborted by user
57 changes = False
59 for iface, old_sel in old_selections.iteritems():
60 new_sel = sels.selections.get(iface, None)
61 if new_sel is None:
62 print(_("No longer used: %s") % iface)
63 changes = True
64 elif old_sel.version != new_sel.version:
65 print(_("%s: %s -> %s") % (iface, old_sel.version, new_sel.version))
66 changes = True
68 for iface, new_sel in sels.selections.iteritems():
69 if iface not in old_selections:
70 print(_("%s: new -> %s") % (iface, new_sel.version))
71 changes = True
73 root_sel = sels[iface_uri]
74 root_iface = config.iface_cache.get_interface(iface_uri)
75 latest = max((impl.version, impl) for impl in root_iface.implementations.values())[1]
76 if latest.version > model.parse_version(sels[iface_uri].version):
77 print(_("A later version ({name} {latest}) exists but was not selected. Using {version} instead.").format(
78 latest = latest.get_version(),
79 name = root_iface.get_name(),
80 version = root_sel.version))
81 if not config.help_with_testing and latest.get_stability() < model.stable:
82 print(_('To select "testing" versions, use:\n0install config help_with_testing True'))
83 else:
84 if not changes:
85 print(_("No updates found. Continuing with version {version}.").format(version = root_sel.version))
87 root_feed = config.iface_cache.get_feed(iface_uri)
88 if root_feed:
89 target = root_feed.get_replaced_by()
90 if target is not None:
91 print(_("Warning: interface {old} has been replaced by {new}".format(old = iface_uri, new = target)))