swc-installation-test-2.py: Cache check errors
authorW. Trevor King <wking@tremily.us>
Sun, 30 Dec 2012 16:41:25 +0000 (11:41 -0500)
committerW. Trevor King <wking@tremily.us>
Tue, 1 Jan 2013 14:49:46 +0000 (09:49 -0500)
Avoid running the same check (e.g. 'python') over and over.

swc-installation-test-2.py

index 34daeeca8e7fe7af026a56d2c45f33ad16e2e192..f307e8af8b7496710745f7e7009050c8c0341d8f 100755 (executable)
@@ -118,6 +118,7 @@ class Dependency (object):
         if not or_dependencies:
             or_dependencies = []
         self.or_dependencies = or_dependencies
+        self._check_error = None
 
     def __str__(self):
         return '<{0} {1}>'.format(type(self).__name__, self.name)
@@ -129,8 +130,14 @@ class Dependency (object):
             return '{0} ({1})'.format(self.long_name, self.name)
 
     def check(self):
-        self._check_dependencies()
-        self._check()
+        if self._check_error:
+            raise self._check_error
+        try:
+            self._check_dependencies()
+            self._check()
+        except DependencyError as e:
+            self._check_error = e  # cache for future calls
+            raise
 
     def _check_dependencies(self):
         for dependency in self.and_dependencies: