From 9a7c461a95e6292b439cc0dfa09e4645b484b9d9 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 21 Nov 2010 14:46:12 +0000 Subject: [PATCH] Added --command option to select the desired command --- zeroinstall/0launch-gui/main.py | 5 +++-- zeroinstall/helpers.py | 6 +++--- zeroinstall/injector/autopolicy.py | 4 ++-- zeroinstall/injector/cli.py | 7 ++++++- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/zeroinstall/0launch-gui/main.py b/zeroinstall/0launch-gui/main.py index b718aaa..3dab03d 100644 --- a/zeroinstall/0launch-gui/main.py +++ b/zeroinstall/0launch-gui/main.py @@ -24,6 +24,7 @@ def run_gui(args): parser.add_option("", "--before", help=_("choose a version before this"), metavar='VERSION') parser.add_option("", "--cpu", help=_("target CPU type"), metavar='CPU') parser.add_option("-c", "--cache", help=_("show the cache"), action='store_true') + parser.add_option("", "--command", help=_("command to select"), metavar='COMMAND') parser.add_option("-d", "--download-only", help=_("fetch but don't run"), action='store_true') parser.add_option("", "--message", help=_("message to display when interacting with user")) parser.add_option("", "--not-before", help=_("minimum version to choose"), metavar='VERSION') @@ -64,7 +65,7 @@ def run_gui(args): if options.version: print "0launch-gui (zero-install) " + gui.version - print "Copyright (C) 2009 Thomas Leonard" + print "Copyright (C) 2010 Thomas Leonard" print _("This program comes with ABSOLUTELY NO WARRANTY," "\nto the extent permitted by law." "\nYou may redistribute copies of this program" @@ -121,7 +122,7 @@ def run_gui(args): widgets = dialog.Template('main') - policy = Policy(interface_uri, handler, src = bool(options.source)) + policy = Policy(interface_uri, handler, src = bool(options.source), command = options.command) policy.target_arch = arch.get_architecture(options.os, options.cpu) root_iface = iface_cache.get_interface(interface_uri) policy.solver.extra_restrictions[root_iface] = restrictions diff --git a/zeroinstall/helpers.py b/zeroinstall/helpers.py index c96ccc3..82b91f6 100644 --- a/zeroinstall/helpers.py +++ b/zeroinstall/helpers.py @@ -99,7 +99,7 @@ def get_selections_gui(iface_uri, gui_args, test_callback = None): return sels -def ensure_cached(uri): +def ensure_cached(uri, command = 'run'): """Ensure that an implementation of uri is cached. If not, it downloads one. It uses the GUI if a display is available, or the console otherwise. @@ -110,12 +110,12 @@ def ensure_cached(uri): """ from zeroinstall.injector import autopolicy, selections - p = autopolicy.AutoPolicy(uri, download_only = True) + p = autopolicy.AutoPolicy(uri, download_only = True, command = command) p.freshness = 0 # Don't check for updates if p.need_download() or not p.ready: if os.environ.get('DISPLAY', None): - return get_selections_gui(uri, []) + return get_selections_gui(uri, ['--command', command]) else: p.recalculate_with_dl() p.start_downloading_impls() diff --git a/zeroinstall/injector/autopolicy.py b/zeroinstall/injector/autopolicy.py index 4954e0c..5529f7f 100644 --- a/zeroinstall/injector/autopolicy.py +++ b/zeroinstall/injector/autopolicy.py @@ -20,13 +20,13 @@ from zeroinstall.injector.handler import Handler class AutoPolicy(policy.Policy): __slots__ = ['download_only'] - def __init__(self, interface_uri, download_only = False, dry_run = False, src = False, handler = None): + def __init__(self, interface_uri, download_only = False, dry_run = False, src = False, handler = None, command = 'run'): """@param handler: (new in 0.30) handler to use, or None to create a L{Handler}""" handler = handler or Handler() if dry_run: info(_("Note: dry_run is deprecated. Pass it to the handler instead!")) handler.dry_run = True - policy.Policy.__init__(self, interface_uri, handler, src = src) + policy.Policy.__init__(self, interface_uri, handler, src = src, command = command) self.download_only = download_only def execute(self, prog_args, main = None, wrapper = None): diff --git a/zeroinstall/injector/cli.py b/zeroinstall/injector/cli.py index b4290e3..e323618 100644 --- a/zeroinstall/injector/cli.py +++ b/zeroinstall/injector/cli.py @@ -160,7 +160,8 @@ def _normal_mode(options, args): policy = autopolicy.AutoPolicy(iface_uri, handler = h, download_only = bool(options.download_only), - src = options.source) + src = options.source, + command = options.command) if options.before or options.not_before: policy.solver.extra_restrictions[root_iface] = [model.VersionRangeRestriction(model.parse_version(options.before), @@ -267,6 +268,9 @@ def _normal_mode(options, args): gui_args += ['--with-store', x] if options.select_only: gui_args.append('--select-only') + if options.command: + gui_args.append('--command') + gui_args.append(options.command) sels = _fork_gui(iface_uri, gui_args, prog_args, options) if not sels: sys.exit(1) # Aborted @@ -369,6 +373,7 @@ def main(command_args): " %prog --import [signed-interface-files]\n" " %prog --feed [interface]")) 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("-c", "--console", help=_("never use GUI"), action='store_false', dest='gui') parser.add_option("", "--cpu", help=_("target CPU type"), metavar='CPU') parser.add_option("-d", "--download-only", help=_("fetch but don't run"), action='store_true') -- 2.11.4.GIT