From 2f47d72cf663b7abf56fb7231af5672713f87a27 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Fri, 10 Dec 2010 20:48:49 +0000 Subject: [PATCH] Allow command_name to be None In this case, we select any implementation (as in 0launch < 0.51), and the Selections document contains no elements. From the command-line, --command="" selects this behaviour. --- zeroinstall/injector/cli.py | 11 ++++++++--- zeroinstall/injector/policy.py | 4 ++-- zeroinstall/injector/solver.py | 38 +++++++++++++++++++++----------------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/zeroinstall/injector/cli.py b/zeroinstall/injector/cli.py index 4b494fc..e1089d9 100644 --- a/zeroinstall/injector/cli.py +++ b/zeroinstall/injector/cli.py @@ -157,11 +157,16 @@ def _normal_mode(options, args): h = handler.Handler() h.dry_run = bool(options.dry_run) + command_name = options.command + if command_name is None: + command_name = 'run' + elif command_name == '': + command_name = None policy = autopolicy.AutoPolicy(iface_uri, handler = h, download_only = bool(options.download_only), src = options.source, - command = options.command) + command = command_name) if options.before or options.not_before: policy.solver.extra_restrictions[root_iface] = [model.VersionRangeRestriction(model.parse_version(options.before), @@ -268,9 +273,9 @@ def _normal_mode(options, args): gui_args += ['--with-store', x] if options.select_only: gui_args.append('--select-only') - if options.command: + if command_name is not None: gui_args.append('--command') - gui_args.append(options.command) + gui_args.append(command_name) sels = _fork_gui(iface_uri, gui_args, prog_args, options) if not sels: sys.exit(1) # Aborted diff --git a/zeroinstall/injector/policy.py b/zeroinstall/injector/policy.py index 4db437d..a4c6634 100644 --- a/zeroinstall/injector/policy.py +++ b/zeroinstall/injector/policy.py @@ -64,7 +64,7 @@ class Policy(object): ready = property(lambda self: self.solver.ready) - def __init__(self, root, handler = None, src = False, command = None): + def __init__(self, root, handler = None, src = False, command = -1): """ @param root: The URI of the root interface (the program we want to run). @param handler: A handler for main-loop integration. @@ -77,7 +77,7 @@ class Policy(object): self.watchers = [] self.src = src # Root impl must be a "src" machine type self.stale_feeds = set() - if command is None: + if command == -1: if src: command = 'compile' else: diff --git a/zeroinstall/injector/solver.py b/zeroinstall/injector/solver.py index 66ce9dd..c3da95e 100644 --- a/zeroinstall/injector/solver.py +++ b/zeroinstall/injector/solver.py @@ -110,7 +110,7 @@ class Solver(object): @param root_arch: the desired target architecture @type root_arch: L{arch.Architecture} @param command_name: which element to select - @type command_name: str + @type command_name: str | None @postcondition: self.ready, self.selections and self.feeds_used are updated""" raise NotImplementedError("Abstract") @@ -466,24 +466,27 @@ class SATSolver(Solver): return var_names - commands = add_command_iface(root_interface, root_arch, command_name) - if commands: - problem.add_clause(commands) # At least one - group_clause_for_command[(root_interface, command_name)] = problem.at_most_one(commands) + if command_name is None: + add_iface(root_interface, root_arch) else: - # (note: might be because we haven't cached it yet) - info("No %s in %s", command_name, root_interface) - - impls = impls_for_iface[self.iface_cache.get_interface(root_interface)] - if impls == [] or (len(impls) == 1 and isinstance(impls[0], _DummyImpl)): - # There were no candidates at all. - self._failure_reason = _("Interface '%s' has no usable implementations") % root_interface + commands = add_command_iface(root_interface, root_arch, command_name) + if commands: + problem.add_clause(commands) # At least one + group_clause_for_command[(root_interface, command_name)] = problem.at_most_one(commands) else: - # We had some candidates implementations, but none for the command we need - self._failure_reason = _("Interface '%s' cannot be executed directly; it is just a library " - "to be used by other programs (or missing '%s' command)") % (root_interface, command_name) + # (note: might be because we haven't cached it yet) + info("No %s in %s", command_name, root_interface) + + impls = impls_for_iface[self.iface_cache.get_interface(root_interface)] + if impls == [] or (len(impls) == 1 and isinstance(impls[0], _DummyImpl)): + # There were no candidates at all. + self._failure_reason = _("Interface '%s' has no usable implementations") % root_interface + else: + # We had some candidates implementations, but none for the command we need + self._failure_reason = _("Interface '%s' cannot be executed directly; it is just a library " + "to be used by other programs (or missing '%s' command)") % (root_interface, command_name) - problem.impossible() + problem.impossible() # Require m to be true if we select an implementation in that group m_groups = [] @@ -595,7 +598,8 @@ class SATSolver(Solver): # TODO: allow depending on other commands, besides 'run'? add_command(runner.metadata['interface'], 'run') - add_command(root_interface, command_name) + if command_name is not None: + add_command(root_interface, command_name) def get_failure_reason(self): """Return an exception explaining why the solve failed.""" -- 2.11.4.GIT