pyflakes
[zeroinstall.git] / zeroinstall / cmd / update.py
blobec7c69e842aaf5bb1b5f1d27f2add27410955365
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 options.offline = False
46 options.gui = old_gui
47 options.refresh = True
49 sels = select.get_selections(config, options, iface_uri,
50 select_only = False, download_only = True, test_callback = None)
51 if not sels:
52 sys.exit(1) # Aborted by user
54 changes = False
56 for iface, old_sel in old_selections.iteritems():
57 new_sel = sels.selections.get(iface, None)
58 if new_sel is None:
59 print _("No longer used: %s") % iface
60 changes = True
61 elif old_sel.version != new_sel.version:
62 print _("%s: %s -> %s") % (iface, old_sel.version, new_sel.version)
63 changes = True
65 for iface, new_sel in sels.selections.iteritems():
66 if iface not in old_selections:
67 print _("%s: new -> %s") % (iface, new_sel.version)
68 changes = True
70 if not changes:
71 print _("No updates found.")