diff options
Diffstat (limited to 'compressor/utils/__init__.py')
| -rw-r--r-- | compressor/utils/__init__.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/compressor/utils/__init__.py b/compressor/utils/__init__.py index 699e37d..766943c 100644 --- a/compressor/utils/__init__.py +++ b/compressor/utils/__init__.py @@ -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: |
