1 """
2 The B{0install download} command-line interface.
3 """
4
5
6
7
8 from __future__ import print_function
9
10 import sys
11
12 from zeroinstall import SafeException, _
13 from zeroinstall.injector import model, requirements
14 from zeroinstall.cmd import UsageError, select
15
16 syntax = "APP | URI"
17
18 add_options = select.add_generic_select_options
19
20 -def handle(config, options, args):
21 if len(args) != 1:
22 raise UsageError()
23
24 assert not options.offline
25
26 old_gui = options.gui
27
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])
37
38 r = requirements.Requirements(iface_uri)
39 r.parse_options(options)
40
41
42 options.offline = True
43 options.gui = False
44 options.refresh = False
45
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
56
57
58 config.network_use = model.network_full
59 options.offline = False
60 options.gui = old_gui
61 options.refresh = True
62
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)
67
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)))
73
74 from zeroinstall.cmd import whatchanged
75 changes = whatchanged.show_changes(old_selections, sels.selections)
76 root_sel = sels[iface_uri]
77
78 if not changes:
79 from zeroinstall.support import xmltools
80
81 if not xmltools.nodes_equal(sels.toDOM(), old_sels.toDOM()):
82 changes = True
83 print(_("Updates to metadata found, but no change to version ({version}).").format(version = root_sel.version))
84
85 root_iface = config.iface_cache.get_interface(iface_uri)
86
87 for feed in config.iface_cache.get_feeds(root_iface):
88 config.iface_cache.get_feed(feed, force = True)
89
90 root_impls = config.iface_cache.get_implementations(root_iface)
91
92 latest = max((impl.version, impl) for impl in root_impls)[1]
93 if latest.version > model.parse_version(sels[iface_uri].version):
94 print(_("A later version ({name} {latest}) exists but was not selected. Using {version} instead.").format(
95 latest = latest.get_version(),
96 name = root_iface.get_name(),
97 version = root_sel.version))
98 if not config.help_with_testing and latest.get_stability() < model.stable:
99 print(_('To select "testing" versions, use:\n0install config help_with_testing True'))
100 elif not changes:
101 print(_("No updates found. Continuing with version {version}.").format(version = root_sel.version))
102
103 if app is not None:
104 if changes:
105 app.set_selections(sels)
106 app.set_requirements(r)
107
108 complete = select.complete
109