Fixed PATH handling on windows.

This commit is contained in:
Jannis Leidel
2011-05-11 13:31:59 +02:00
parent f0cdbf3f6a
commit 049583f7d5

View File

@@ -59,17 +59,25 @@ def walk(root, topdown=True, onerror=None, followlinks=False):
yield (link_dirpath, link_dirnames, link_filenames)
def get_pathext(default_pathext=None):
"""
Returns the path extensions from environment or a default
"""
if default_pathext is None:
default_pathext = os.pathsep.join(['.COM', '.EXE', '.BAT', '.CMD'])
return os.environ.get('PATHEXT', default_pathext)
def find_command(cmd, paths=None, pathext=None):
"""
Searches the PATH for the given command and returns its path
"""
if paths is None:
paths = os.environ.get('PATH', []).split(os.pathsep)
paths = os.environ.get('PATH', '').split(os.pathsep)
if isinstance(paths, basestring):
paths = [paths]
# check if there are funny path extensions for executables, e.g. Windows
if pathext is None:
pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD')
pathext = get_pathext()
pathext = [ext for ext in pathext.lower().split(os.pathsep)]
# don't use extensions if the command ends with one of them
if os.path.splitext(cmd)[1].lower() in pathext: