diff options
author | Jannis Leidel <jannis@leidel.info> | 2011-04-30 23:20:34 +0200 |
---|---|---|
committer | Jannis Leidel <jannis@leidel.info> | 2011-04-30 23:20:34 +0200 |
commit | b1f2a9fddaa407cfbee6f249a52129e370800bd1 (patch) | |
tree | f41c2246cb66fe1aac134195fe788bd72baf2853 /pip/util.py | |
parent | 6b6f4947c3b9747bef216ccf31f9c20c8bb255a9 (diff) | |
parent | 743124094bb98e73ff47addb1e3886bc9411c1e1 (diff) | |
download | pip-1.0.1.tar.gz |
Merge branch 'release/1.0.1'1.0.1
Diffstat (limited to 'pip/util.py')
-rw-r--r-- | pip/util.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/pip/util.py b/pip/util.py index d2dae97a8..b9c32525b 100644 --- a/pip/util.py +++ b/pip/util.py @@ -7,7 +7,7 @@ import posixpath import pkg_resources import zipfile import tarfile -from pip.exceptions import InstallationError +from pip.exceptions import InstallationError, BadCommand from pip.backwardcompat import WindowsError, string_types, raw_input from pip.locations import site_packages, running_under_virtualenv from pip.log import logger @@ -71,12 +71,12 @@ def backup_dir(dir, ext='.bak'): 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, string_types): 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: @@ -92,9 +92,16 @@ def find_command(cmd, paths=None, pathext=None): return cmd_path_ext if os.path.isfile(cmd_path): return cmd_path - return None + raise BadCommand('Cannot find command %r' % cmd) +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' ]) + pathext = os.environ.get('PATHEXT', default_pathext) + return pathext + def ask(message, options): """Ask the message interactively, with the given possible responses""" while 1: |