From 2c66d15bdce1985b64ef11d9bf4628b6f54f58d5 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 30 Dec 2012 11:35:03 -0500 Subject: [PATCH] swc-installation-test-2.py: Add exe_extension for MS Windows compat. Use distutils' new_compiler() to get the appropriate exe_extension for the user's system. This way command names can always be specified in their bare form, and we'll automatically add the right executable extension for other platforms. --- swc-installation-test-2.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 59b9cc3..d07fcc5 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -22,6 +22,7 @@ This script requires at least Python 2.6. You can check the version of Python that you have installed with 'swc-installation-test-1.py'. """ +import distutils.ccompiler as _distutils_ccompiler import importlib as _importlib import logging as _logging import os as _os @@ -201,6 +202,8 @@ CHECKER['python'] = PythonDependency() class CommandDependency (Dependency): + exe_extension = _distutils_ccompiler.new_compiler().exe_extension + def __init__(self, command, version_option='--version', version_regexp=None, version_stream='stdout', **kwargs): if 'name' not in kwargs: @@ -215,22 +218,23 @@ class CommandDependency (Dependency): self.version_stream = version_stream def _get_version_stream(self): + command = self.command + (self.exe_extension or '') try: p = _subprocess.Popen( - [self.command, self.version_option], + [command, self.version_option], stdout=_subprocess.PIPE, stderr=_subprocess.PIPE, close_fds=True, shell=False, universal_newlines=True) except OSError as e: raise DependencyError( checker=self, - message="could not find '{0}' executable".format(self.command), + message="could not find '{0}' executable".format(command), ) from e stdout,stderr = p.communicate() status = p.wait() if status: lines = [ "failed to execute '{0} {1}':".format( - self.command, self.version_option), + command, self.version_option), 'status: {0}'.format(status), ] for name,string in [('stdout', stdout), ('stderr', stderr)]: -- 2.26.2