swc-installation-test-2.py: Add exe_extension for MS Windows compat.
authorW. Trevor King <wking@tremily.us>
Sun, 30 Dec 2012 16:35:03 +0000 (11:35 -0500)
committerW. Trevor King <wking@tremily.us>
Tue, 1 Jan 2013 14:49:46 +0000 (09:49 -0500)
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

index 59b9cc370b1b9e0248d92b6ca90de3808782f628..d07fcc5224ede5f31517d4ece0a4006c03e5ad45 100755 (executable)
@@ -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)]: