From 9cc405df08b3d35c11e08841ff980e5104fa2e16 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 8 Jan 2011 18:51:02 +0000 Subject: [PATCH] Added '0install run' sub-command --- zeroinstall/cmd/download.py | 1 - zeroinstall/cmd/run.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ zeroinstall/cmd/select.py | 8 ++++++-- 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 zeroinstall/cmd/run.py diff --git a/zeroinstall/cmd/download.py b/zeroinstall/cmd/download.py index d60eeb5..4685688 100644 --- a/zeroinstall/cmd/download.py +++ b/zeroinstall/cmd/download.py @@ -23,7 +23,6 @@ def add_options(parser): 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, diff --git a/zeroinstall/cmd/run.py b/zeroinstall/cmd/run.py new file mode 100644 index 0000000..5ab9d77 --- /dev/null +++ b/zeroinstall/cmd/run.py @@ -0,0 +1,44 @@ +""" +The B{0install run} 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 [ARGS]" + +def add_options(parser): + select.add_generic_select_options(parser) + parser.add_option("-m", "--main", help=_("name of the file to execute")) + parser.add_option("-w", "--wrapper", help=_("execute program using a debugger, etc"), metavar='COMMAND') + parser.disable_interspersed_args() + +def handle(options, args): + if len(args) < 1: + raise UsageError() + iface_uri = model.canonical_iface_uri(args[0]) + prog_args = args[1:] + + def test_callback(sels): + from zeroinstall.injector import run + return run.test_selections(sels, prog_args, + False, # dry-run + options.main) + + sels = select.get_selections(options, iface_uri, + select_only = False, download_only = False, + test_callback = test_callback) + if not sels: + sys.exit(1) # Aborted by user + + from zeroinstall.injector import run + run.execute_selections(sels, prog_args, main = options.main, wrapper = options.wrapper) diff --git a/zeroinstall/cmd/select.py b/zeroinstall/cmd/select.py index bb1fb0d..8500659 100644 --- a/zeroinstall/cmd/select.py +++ b/zeroinstall/cmd/select.py @@ -16,7 +16,8 @@ from zeroinstall.injector.iface_cache import iface_cache syntax = "URI" -def add_options(parser): +def add_generic_select_options(parser): + """All options for selecting.""" parser.add_option("", "--before", help=_("choose a version before this"), metavar='VERSION') parser.add_option("", "--command", help=_("command to select"), metavar='COMMAND') parser.add_option("", "--cpu", help=_("target CPU type"), metavar='CPU') @@ -26,6 +27,10 @@ def add_options(parser): parser.add_option("", "--os", help=_("target operation system type"), metavar='OS') parser.add_option("-r", "--refresh", help=_("refresh all used interfaces"), action='store_true') parser.add_option("-s", "--source", help=_("select source code"), action='store_true') + +def add_options(parser): + """Options for 'select' and 'download' (but not 'run')""" + add_generic_select_options(parser) parser.add_option("", "--xml", help=_("write selected versions as XML"), action='store_true') def get_selections(options, iface_uri, select_only, download_only, test_callback): @@ -161,7 +166,6 @@ def get_selections(options, iface_uri, select_only, download_only, test_callback def handle(options, args): if len(args) != 1: raise UsageError() - uri = args[0] iface_uri = model.canonical_iface_uri(args[0]) sels = get_selections(options, iface_uri, -- 2.11.4.GIT