From 52e8c22e4fcbb16afcff2e032d59c19a07321d34 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 8 Jan 2011 18:33:37 +0000 Subject: [PATCH] Added "0install download" --- zeroinstall/cmd/download.py | 37 +++++++++++++++++++++ zeroinstall/cmd/select.py | 78 ++++++++++++++++++++++++--------------------- 2 files changed, 79 insertions(+), 36 deletions(-) create mode 100644 zeroinstall/cmd/download.py diff --git a/zeroinstall/cmd/download.py b/zeroinstall/cmd/download.py new file mode 100644 index 0000000..d60eeb5 --- /dev/null +++ b/zeroinstall/cmd/download.py @@ -0,0 +1,37 @@ +""" +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.cmd import UsageError, select +from zeroinstall.injector import model, autopolicy, selections, handler +from zeroinstall.injector.iface_cache import iface_cache + +syntax = "URI" + +def add_options(parser): + select.add_options(parser) + parser.add_option("", "--show", help=_("show where components are installed"), action='store_true') + +def handle(options, args): + if len(args) != 1: + raise UsageError() + uri = args[0] + iface_uri = model.canonical_iface_uri(args[0]) + + 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 + + if options.xml: + select.show_xml(sels) + if options.show: + select.show_human(sels) diff --git a/zeroinstall/cmd/select.py b/zeroinstall/cmd/select.py index c071b1e..bb1fb0d 100644 --- a/zeroinstall/cmd/select.py +++ b/zeroinstall/cmd/select.py @@ -170,43 +170,49 @@ def handle(options, args): sys.exit(1) # Aborted by user if options.xml: - doc = sels.toDOM() - doc.writexml(sys.stdout) - sys.stdout.write('\n') + show_xml(sels) else: - from zeroinstall import zerostore - done = set() # detect cycles - def print_node(uri, command, indent): - if uri in done: return - done.add(uri) - impl = sels.selections.get(uri, None) - print indent + "- URI:", uri - if impl: - print indent + " Version:", impl.version - try: - if impl.id.startswith('package:'): - path = "(" + impl.id + ")" + show_human(sels) + +def show_xml(sels): + doc = sels.toDOM() + doc.writexml(sys.stdout) + sys.stdout.write('\n') + +def show_human(sels): + from zeroinstall import zerostore + done = set() # detect cycles + def print_node(uri, command, indent): + if uri in done: return + done.add(uri) + impl = sels.selections.get(uri, None) + print indent + "- URI:", uri + if impl: + print indent + " Version:", impl.version + try: + if impl.id.startswith('package:'): + path = "(" + impl.id + ")" + else: + path = impl.local_path or iface_cache.stores.lookup_any(impl.digests) + except zerostore.NotStored: + path = "(not cached)" + print indent + " Path:", path + indent += " " + deps = impl.dependencies + if command is not None: + deps += sels.commands[command].requires + for child in deps: + if isinstance(child, model.InterfaceDependency): + if child.qdom.name == 'runner': + child_command = command + 1 else: - path = impl.local_path or iface_cache.stores.lookup_any(impl.digests) - except zerostore.NotStored: - path = "(not cached)" - print indent + " Path:", path - indent += " " - deps = impl.dependencies - if command is not None: - deps += sels.commands[command].requires - for child in deps: - if isinstance(child, model.InterfaceDependency): - if child.qdom.name == 'runner': - child_command = command + 1 - else: - child_command = None - print_node(child.interface, child_command, indent) - else: - print indent + " No selected version" + child_command = None + print_node(child.interface, child_command, indent) + else: + print indent + " No selected version" - if sels.commands: - print_node(sels.interface, 0, "") - else: - print_node(sels.interface, None, "") + if sels.commands: + print_node(sels.interface, 0, "") + else: + print_node(sels.interface, None, "") -- 2.11.4.GIT