def do_exec_binding(self, binding, iface): assert iface is not None name = binding.name if '/' in name or name.startswith('.') or "'" in name: raise SafeException("Invalid <executable> name '%s'" % name) exec_dir = basedir.save_cache_path(namespaces.config_site, namespaces.config_prog, 'executables', name) exec_path = os.path.join(exec_dir, name + ".exe" if os.name == "nt" else name) if not self._checked_runenv: self._check_runenv() if not os.path.exists(exec_path): if os.name == "nt": # Copy runenv.cli.template to ~/.cache/0install.net/injector/executables/$name/$name import shutil shutil.copyfile(os.environ['ZEROINSTALL_CLI_TEMPLATE'], exec_path) else: # Symlink ~/.cache/0install.net/injector/executables/$name/$name to runenv.py os.symlink('../../runenv.py', exec_path) os.chmod(exec_dir, 0o500) if binding.in_path: path = os.environ["PATH"] = exec_dir + os.pathsep + os.environ["PATH"] logger.info("PATH=%s", path) else: os.environ[name] = exec_path logger.info("%s=%s", name, exec_path) args = self.build_command(iface, binding.command) if os.name == "nt": os.environ["0install-runenv-file-" + name + ".exe"] = args[0] os.environ["0install-runenv-args-" + name + ".exe"] = support.windows_args_escape(args[1:]) else: import json os.environ["0install-runenv-" + name] = json.dumps(args)
def do_exec_binding(self, binding, iface): assert iface is not None name = binding.name if '/' in name or name.startswith('.') or "'" in name: raise SafeException("Invalid <executable> name '%s'" % name) exec_dir = basedir.save_cache_path(namespaces.config_site, namespaces.config_prog, 'executables', name) exec_path = os.path.join(exec_dir, name + ".exe" if os.name == "nt" else name) if not self._checked_runenv: self._check_runenv() if not os.path.exists(exec_path): if os.name == "nt": # Copy runenv.cli.template to ~/.cache/0install.net/injector/executables/$name/$name import shutil shutil.copyfile(os.path.join(os.path.dirname(__file__), "runenv.cli.template"), exec_path) else: # Symlink ~/.cache/0install.net/injector/executables/$name/$name to runenv.py os.symlink('../../runenv.py', exec_path) os.chmod(exec_dir, 0o500) if binding.in_path: path = os.environ["PATH"] = exec_dir + os.pathsep + os.environ["PATH"] logger.info("PATH=%s", path) else: os.environ[name] = exec_path logger.info("%s=%s", name, exec_path) args = self.build_command(iface, binding.command) if os.name == "nt": os.environ["0install-runenv-file-" + name + ".exe"] = args[0] os.environ["0install-runenv-args-" + name + ".exe"] = support.windows_args_escape(args[1:]) else: import json os.environ["0install-runenv-" + name] = json.dumps(args)
def testWindowsSupport(self): self.assertEqual("foo bar", windows_args_escape(["foo", "bar"])) self.assertEqual('"foo bar"', windows_args_escape(["foo bar"])) self.assertEqual(r'"foo \"bar\""', windows_args_escape(['foo "bar"'])) self.assertEqual(r'"foo \\\"bar\""', windows_args_escape(['foo \\"bar"']))