(Boeing r1774)
added which() function to search full PATH for executable; use it in checkexec()
This commit is contained in:
parent
3e2e8f77b2
commit
454d17a245
1 changed files with 20 additions and 3 deletions
|
@ -15,11 +15,28 @@ import subprocess, os, ast
|
|||
|
||||
def checkexec(execlist):
|
||||
for bin in execlist:
|
||||
# note that os.access() uses real uid/gid; that should be okay
|
||||
# here
|
||||
if not os.access(bin, os.X_OK):
|
||||
if which(bin) is None:
|
||||
raise EnvironmentError, "executable not found: %s" % bin
|
||||
|
||||
def which(program):
|
||||
''' From: http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
|
||||
'''
|
||||
def is_exe(fpath):
|
||||
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
|
||||
|
||||
fpath, fname = os.path.split(program)
|
||||
if fpath:
|
||||
if is_exe(program):
|
||||
return program
|
||||
else:
|
||||
for path in os.environ["PATH"].split(os.pathsep):
|
||||
path = path.strip('"')
|
||||
exe_file = os.path.join(path, program)
|
||||
if is_exe(exe_file):
|
||||
return exe_file
|
||||
|
||||
return None
|
||||
|
||||
def ensurepath(pathlist):
|
||||
searchpath = os.environ["PATH"].split(":")
|
||||
for p in set(pathlist):
|
||||
|
|
Loading…
Reference in a new issue