+ def setEnv(self, name, val):
+ '''Set the given environment variable, return old value'''
+ oldVal = os.getenv(name)
+ os.putenv(name, val)
+ return oldVal
+
+ def prependDirToEnv(self, name, dir, default):
+ '''Prepends the given directory to the environment variable. If the variable is empty, dir isprepended to the default.
+ Returns the old value.'''
+ oldVal = os.getenv(name)
+ oldPaths = default if oldVal is None else oldVal
+ os.putenv(name, dir+':'+oldPaths)
+ return oldVal
+
+ def restoreEnv(self, name, oldVal):
+ '''Restore environment variable to previous value'''
+ if oldVal is None:
+ os.unsetenv(name)
+ else:
+ os.putenv(name, oldVal)
+