swc-installation-test-2.py: Also look for extension-less paths
authorW. Trevor King <wking@tremily.us>
Thu, 21 Mar 2013 16:18:23 +0000 (12:18 -0400)
committerW. Trevor King <wking@tremily.us>
Thu, 21 Mar 2013 16:18:23 +0000 (12:18 -0400)
Before this commit, CommandDependency checked self.command (with an
optional extension determined by distutils).  If that check failed to
produce a version stream, we cycled through a list of additional
hard-coded paths.  For example:  Notepad++ used:

  self.command = 'notepad++'
  self.paths = [
      _os.path.join(
          _ROOT_PATH, 'Program Files', 'Notepad++', 'notepad++.exe'),
      ]

Because some MS Windows commands lack the expected '.exe' extension,
but are still present and detected by a number of shells, we should
also look for the extension-less version of the command.

I consolidated the _get_version_stream() logic to build a single list
of paths and loop through it looking for success (and accumulating
errors).  This makes the handling of self.paths less of a special
case, and sets us up for any additional path mangling we may need to
support other poorly standardized OSes ;).

setup/swc-installation-test-2.py

index 3c1fc090beacd90291eacb14691a1b4302b73c90..3778d7f11830c8abf3293455a246e8276bb95e66 100755 (executable)
@@ -455,25 +455,22 @@ class CommandDependency (Dependency):
         raise NotImplementedError(self.version_stream)
 
     def _get_version_stream(self, **kwargs):
-        try:
-            return self._get_command_version_stream(**kwargs)
-        except DependencyError as e:
-            if self.paths:
-                or_errors = [e]
-                for path in self.paths:
-                    try:
-                        return self._get_command_version_stream(
-                            command=path, **kwargs)
-                    except DependencyError as e:
-                        print('a')
-                        or_errors.append(e)
-                raise DependencyError(
-                    checker=self,
-                    message='errors finding {0} version'.format(
-                        self.full_name()),
-                    causes=or_errors)
-            else:
-                raise
+        paths = [self.command + (self.exe_extension or '')]
+        if self.exe_extension:
+            paths.append(self.command)  # also look at the extension-less path
+        if self.paths:
+            paths.extend(self.paths)
+        or_errors = []
+        for path in paths:
+            try:
+                return self._get_command_version_stream(command=path, **kwargs)
+            except DependencyError as e:
+                or_errors.append(e)
+        raise DependencyError(
+            checker=self,
+            message='errors finding {0} version'.format(
+                self.full_name()),
+            causes=or_errors)
 
     def _get_version(self):
         version_stream = self._get_version_stream()