From a30920d88f29a1eb37c41b93a244be16200991da Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 8 Jan 2011 19:23:05 +0000 Subject: [PATCH] Added '0install update' sub-command --- 0install.1 | 2 +- zeroinstall/cmd/update.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 zeroinstall/cmd/update.py diff --git a/0install.1 b/0install.1 index 6166069..8801312 100644 --- a/0install.1 +++ b/0install.1 @@ -238,7 +238,7 @@ Check for updates to the program and download them if found. This is similar to whether any changes were found. .PP -The options are the same as for `download'. +The options are the same as for `select'. .SS 0install import FEED diff --git a/zeroinstall/cmd/update.py b/zeroinstall/cmd/update.py new file mode 100644 index 0000000..a5181c6 --- /dev/null +++ b/zeroinstall/cmd/update.py @@ -0,0 +1,73 @@ +""" +The B{0install download} command-line interface. +""" + +# Copyright (C) 2011, Thomas Leonard +# See the README file for details, or visit http://0install.net. + +from optparse import OptionParser +import os, sys +import logging + +from zeroinstall import cmd, SafeException, _ +from zeroinstall.injector import model +from zeroinstall.cmd import UsageError, select + +syntax = "URI" + +add_options = select.add_generic_select_options + +def handle(options, args): + if len(args) != 1: + raise UsageError() + + assert not options.offline + + iface_uri = model.canonical_iface_uri(args[0]) + + old_gui = options.gui + + # Select once in offline console mode to get the old values + options.offline = True + options.gui = False + options.refresh = False + + try: + old_sels = select.get_selections(options, iface_uri, + select_only = True, download_only = False, test_callback = None) + except SafeException, ex: + old_selections = {} + else: + if old_sels is None: + old_selections = {} + else: + old_selections = old_sels.selections + + # Download in online mode to get the new values + options.offline = False + options.gui = old_gui + options.refresh = True + + sels = select.get_selections(options, iface_uri, + select_only = False, download_only = True, test_callback = None) + if not sels: + sys.exit(1) # Aborted by user + + changes = False + + for iface, old_sel in old_selections.iteritems(): + new_sel = sels.selections.get(iface, None) + if new_sel is None: + print _("No longer used: %s") % iface + changes = True + elif old_sel.version != new_sel.version: + print _("%s: %s -> %s") % (iface, old_sel.version, new_sel.version) + changes = True + + for iface, new_sel in sels.selections.iteritems(): + if iface not in old_selections: + print _("%s: new -> %s") % (iface, new_sel.version) + changes = True + + if not changes: + print _("No updates found.") -- 2.11.4.GIT