Converted print statements to functions
[zeroinstall.git] / zeroinstall / cmd / update.py
blob553f9c099488db3f09ee27a48ff1f6f3b48508fb
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 if not changes:
74 print(_("No updates found."))