Large-scale API cleanup
[zeroinstall/zeroinstall-afb.git] / zeroinstall / cmd / update.py
blob7033317e2fc4b1ddf6b0009c78aeab83af3052e3
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 import sys
10 from zeroinstall import SafeException, _
11 from zeroinstall.injector import model
12 from zeroinstall.cmd import UsageError, select
14 syntax = "URI"
16 add_options = select.add_generic_select_options
18 def handle(config, options, args):
19 if len(args) != 1:
20 raise UsageError()
22 assert not options.offline
24 iface_uri = model.canonical_iface_uri(args[0])
26 old_gui = options.gui
28 # Select once in offline console mode to get the old values
29 options.offline = True
30 options.gui = False
31 options.refresh = False
33 try:
34 old_sels = select.get_selections(config, options, iface_uri,
35 select_only = True, download_only = False, test_callback = None)
36 except SafeException:
37 old_selections = {}
38 else:
39 if old_sels is None:
40 old_selections = {}
41 else:
42 old_selections = old_sels.selections
44 # Download in online mode to get the new values
45 config.network_use = model.network_full
46 options.offline = False
47 options.gui = old_gui
48 options.refresh = True
50 sels = select.get_selections(config, options, iface_uri,
51 select_only = False, download_only = True, test_callback = None)
52 if not sels:
53 sys.exit(1) # Aborted by user
55 changes = False
57 for iface, old_sel in old_selections.iteritems():
58 new_sel = sels.selections.get(iface, None)
59 if new_sel is None:
60 print _("No longer used: %s") % iface
61 changes = True
62 elif old_sel.version != new_sel.version:
63 print _("%s: %s -> %s") % (iface, old_sel.version, new_sel.version)
64 changes = True
66 for iface, new_sel in sels.selections.iteritems():
67 if iface not in old_selections:
68 print _("%s: new -> %s") % (iface, new_sel.version)
69 changes = True
71 if not changes:
72 print _("No updates found.")