Use which instead of type to check if a binary exists

For example if mvn is a defined shell function but mvn is
not installed the method ensure_exists will return True even
mvn is not installed.

% type mvn
mvn is a shell function

% which mvn
/usr/bin/which: no mvn in (...)

Change-Id: Ic751660c030e687ca6bc53656fd49c5563cfc71f
This commit is contained in:
Christian Berendt 2014-08-11 21:44:19 +02:00
parent 483122f1fd
commit 23aed8f012
1 changed files with 2 additions and 2 deletions

View File

@ -723,8 +723,8 @@ def publish_book(publish_path, book):
def ensure_exists(program):
"""Check that program exists, abort if not."""
retcode = subprocess.call("type " + program, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
retcode = subprocess.call(['which', program], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
if retcode != 0:
print("Program '%s' does not exist, please install!" % program)
sys.exit(1)