2 The B{0install download} command-line interface.
5 # Copyright (C) 2011, Thomas Leonard
6 # See the README file for details, or visit http://0install.net.
8 from __future__
import print_function
12 from zeroinstall
import SafeException
, _
13 from zeroinstall
.injector
import model
, requirements
14 from zeroinstall
.cmd
import UsageError
, select
18 add_options
= select
.add_generic_select_options
20 def handle(config
, options
, args
):
24 assert not options
.offline
28 app
= config
.app_mgr
.lookup_app(args
[0], missing_ok
= True)
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
)
36 iface_uri
= model
.canonical_iface_uri(args
[0])
38 r
= requirements
.Requirements(iface_uri
)
39 r
.parse_options(options
)
41 # Select once in offline console mode to get the old values
42 options
.offline
= True
44 options
.refresh
= False
47 old_sels
= select
.get_selections_for(r
, config
, options
,
48 select_only
= True, download_only
= False, test_callback
= None)
55 old_selections
= old_sels
.selections
57 # Download in online mode to get the new values
58 config
.network_use
= model
.network_full
59 options
.offline
= False
61 options
.refresh
= True
63 sels
= select
.get_selections_for(r
, config
, options
,
64 select_only
= False, download_only
= True, test_callback
= None)
66 sys
.exit(1) # Aborted by user
68 root_feed
= config
.iface_cache
.get_feed(iface_uri
)
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
)))
74 from zeroinstall
.cmd
import whatchanged
75 changes
= whatchanged
.show_changes(old_selections
, sels
.selections
)
77 root_sel
= sels
[iface_uri
]
78 root_iface
= config
.iface_cache
.get_interface(iface_uri
)
79 # Force a reload, since we may have used the GUI to update it
80 for feed
in config
.iface_cache
.get_feeds(root_iface
):
81 config
.iface_cache
.get_feed(feed
, force
= True)
83 root_impls
= config
.iface_cache
.get_implementations(root_iface
)
85 latest
= max((impl
.version
, impl
) for impl
in root_impls
)[1]
86 if latest
.version
> model
.parse_version(sels
[iface_uri
].version
):
87 print(_("A later version ({name} {latest}) exists but was not selected. Using {version} instead.").format(
88 latest
= latest
.get_version(),
89 name
= root_iface
.get_name(),
90 version
= root_sel
.version
))
91 if not config
.help_with_testing
and latest
.get_stability() < model
.stable
:
92 print(_('To select "testing" versions, use:\n0install config help_with_testing True'))
94 from zeroinstall
.support
import xmltools
96 # No obvious changes, but check for more subtle updates.
97 if xmltools
.nodes_equal(sels
.toDOM(), old_sels
.toDOM()):
98 print(_("No updates found. Continuing with version {version}.").format(version
= root_sel
.version
))
101 print(_("Updates to metadata found, but no change to version ({version}).").format(version
= root_sel
.version
))
105 app
.set_selections(sels
)
106 app
.set_requirements(r
)