def _prependToEnvVar(self, newVal, envVar):
path = self._getEnvVarAsList(envVar)
foundValue = False
for entry in path:
# Search to determine if the new value is already in the path
try:
if os.path.samefile(entry, newVal):
# The value is already in the path
foundValue = True
break
except OSError:
# If we can't find concrete files to compare, fall back to string compare
if entry == newVal:
# The value is already in the path
foundValue = True
break
if not foundValue:
# The value does not already exist
if os.environ.has_key(envVar):
newpath = newVal+os.path.pathsep + os.getenv(envVar)+os.path.pathsep
else:
newpath = newVal+os.path.pathsep
os.putenv(envVar, newpath)
os.environ[envVar] = newpath
评论列表
文章目录