From 6fef5fa4db6a01bc398a6768b94a266da47cbdef Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 1 Jan 2013 09:13:18 -0500 Subject: [PATCH] swc-installation-test-2.py: Convert .version_option to .version_options I'm about to implement a version check for 'make' where a single option doesn't cut it. For version of Python before 3.3, shlex.quote() doesn't exist [1], so use pipes.quote() instead [2]. [1]: http://docs.python.org/3/library/shlex.html#shlex.quote [2]: http://bugs.python.org/issue9723 --- swc-installation-test-2.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 373230d..df173e7 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -32,10 +32,17 @@ import logging as _logging import os as _os import platform as _platform import re as _re +import shlex as _shlex import subprocess as _subprocess import sys as _sys +if not hasattr(_shlex, 'quote'): # Python versions older than 3.3 + # Use the undocumented pipes.quote() + import pipes as _pipes + _shlex.quote = _pipes.quote + + __version__ = '0.1' # Comment out any entries you don't need @@ -241,13 +248,13 @@ CHECKER['python'] = PythonDependency() class CommandDependency (Dependency): exe_extension = _distutils_ccompiler.new_compiler().exe_extension - def __init__(self, command, version_option='--version', + def __init__(self, command, version_options=('--version',), version_regexp=None, version_stream='stdout', **kwargs): if 'name' not in kwargs: kwargs['name'] = command super(CommandDependency, self).__init__(**kwargs) self.command = command - self.version_option = version_option + self.version_options = version_options if not version_regexp: regexp = r'([\d][\d{0}]*[\d])'.format(self.version_delimiter) version_regexp = _re.compile(regexp) @@ -258,7 +265,7 @@ class CommandDependency (Dependency): command = self.command + (self.exe_extension or '') try: p = _subprocess.Popen( - [command, self.version_option], + [command] + list(self.version_options), stdout=_subprocess.PIPE, stderr=_subprocess.PIPE, close_fds=True, shell=False, universal_newlines=True) except OSError as e: @@ -270,8 +277,10 @@ class CommandDependency (Dependency): status = p.wait() if status not in expect: lines = [ - "failed to execute '{0} {1}':".format( - command, self.version_option), + "failed to execute: {0} {1}".format( + command, + ' '.join(_shlex.quote(arg) + for arg in self.version_options)), 'status: {0}'.format(status), ] for name,string in [('stdout', stdout), ('stderr', stderr)]: -- 2.26.2