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
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
26 iface_uri
= model
.canonical_iface_uri(args
[0])
30 # Select once in offline console mode to get the old values
31 options
.offline
= True
33 options
.refresh
= False
36 old_sels
= select
.get_selections(config
, options
, iface_uri
,
37 select_only
= True, download_only
= False, test_callback
= None)
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
50 options
.refresh
= True
52 sels
= select
.get_selections(config
, options
, iface_uri
,
53 select_only
= False, download_only
= True, test_callback
= None)
55 sys
.exit(1) # Aborted by user
59 for iface
, old_sel
in old_selections
.iteritems():
60 new_sel
= sels
.selections
.get(iface
, None)
62 print(_("No longer used: %s") % iface
)
64 elif old_sel
.version
!= new_sel
.version
:
65 print(_("%s: %s -> %s") % (iface
, old_sel
.version
, new_sel
.version
))
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
))
73 root_sel
= sels
[iface_uri
]
74 root_iface
= config
.iface_cache
.get_interface(iface_uri
)
75 latest
= max((impl
.version
, impl
) for impl
in root_iface
.implementations
.values())[1]
76 if latest
.version
> model
.parse_version(sels
[iface_uri
].version
):
77 print(_("A later version ({name} {latest}) exists but was not selected. Using {version} instead.").format(
78 latest
= latest
.get_version(),
79 name
= root_iface
.get_name(),
80 version
= root_sel
.version
))
81 if not config
.help_with_testing
and latest
.get_stability() < model
.stable
:
82 print(_('To select "testing" versions, use:\n0install config help_with_testing True'))
85 print(_("No updates found. Continuing with version {version}.").format(version
= root_sel
.version
))
87 root_feed
= config
.iface_cache
.get_feed(iface_uri
)
89 target
= root_feed
.get_replaced_by()
90 if target
is not None:
91 print(_("Warning: interface {old} has been replaced by {new}".format(old
= iface_uri
, new
= target
)))