'\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.TP
-.RI WhereIs( program ", [" path ", [" pathext ]])
+.RI WhereIs( program ", [" path ", " pathext ", " reject ])
.TP
-.RI env.WhereIs( program ", [" path ", [" pathext ]])
+.RI env.WhereIs( program ", [" path ", " pathext ", " reject ])
Searches for the specified executable
.I program,
or the user's current PATHEXT
(os.environ['PATHEXT'])
by default.
+Will not select any
+path name or names
+in the specified
+.I reject
+list, if any.
.SS SConscript Variables
In addition to the global functions and methods,
- Allow SConf.CheckLib() to search a list of libraries, like the
Autoconf AC_SEARCH_LIBS macro.
+ - Allow the env.WhereIs() method to take a "reject" argument to
+ let it weed out specific path names.
+
RELEASE 0.95 - Mon, 08 Mar 2004 06:43:20 -0600
tool = self.subst(tool)
return SCons.Tool.Tool(tool, map(self.subst, toolpath))(self)
- def WhereIs(self, prog, path=None, pathext=None):
+ def WhereIs(self, prog, path=None, pathext=None, reject=[]):
"""Find prog in the path.
"""
if path is None:
pass
elif SCons.Util.is_String(pathext):
pathext = self.subst(pathext)
- path = SCons.Util.WhereIs(prog, path, pathext)
+ path = SCons.Util.WhereIs(prog, path, pathext, reject)
if path: return path
return None
wi = env.WhereIs('xxx.exe', string.join(pathdirs_1243, os.pathsep))
assert wi == test.workpath(sub4_xxx_exe), wi
+ wi = env.WhereIs('xxx.exe', reject = sub3_xxx_exe)
+ assert wi == test.workpath(sub4_xxx_exe), wi
+ wi = env.WhereIs('xxx.exe', pathdirs_1243, reject = sub3_xxx_exe)
+ assert wi == test.workpath(sub4_xxx_exe), wi
+
path = string.join(pathdirs_1243, os.pathsep)
env = Environment(ENV = {'PATH' : path})
wi = env.WhereIs('xxx.exe')
if sys.platform == 'win32':
- def WhereIs(file, path=None, pathext=None):
+ def WhereIs(file, path=None, pathext=None, reject=[]):
if path is None:
path = os.environ['PATH']
if is_String(path):
if string.lower(ext) == string.lower(file[-len(ext):]):
pathext = ['']
break
+ if not is_List(reject):
+ reject = [reject]
for dir in path:
f = os.path.join(dir, file)
for ext in pathext:
fext = f + ext
if os.path.isfile(fext):
- return os.path.normpath(fext)
+ try:
+ reject.index(fext)
+ except ValueError:
+ return os.path.normpath(fext)
+ continue
return None
elif os.name == 'os2':
- def WhereIs(file, path=None, pathext=None):
+ def WhereIs(file, path=None, pathext=None, reject=[]):
if path is None:
path = os.environ['PATH']
if is_String(path):
if string.lower(ext) == string.lower(file[-len(ext):]):
pathext = ['']
break
+ if not is_List(reject):
+ reject = [reject]
for dir in path:
f = os.path.join(dir, file)
for ext in pathext:
fext = f + ext
if os.path.isfile(fext):
- return os.path.normpath(fext)
+ try:
+ reject.index(fext)
+ except ValueError:
+ return os.path.normpath(fext)
+ continue
return None
else:
- def WhereIs(file, path=None, pathext=None):
+ def WhereIs(file, path=None, pathext=None, reject=[]):
if path is None:
path = os.environ['PATH']
if is_String(path):
path = string.split(path, os.pathsep)
+ if not is_List(reject):
+ reject = [reject]
for dir in path:
f = os.path.join(dir, file)
if os.path.isfile(f):
except OSError:
continue
if stat.S_IMODE(st[stat.ST_MODE]) & 0111:
- return os.path.normpath(f)
+ try:
+ reject.index(f)
+ except ValueError:
+ return os.path.normpath(f)
+ continue
return None
def PrependPath(oldpath, newpath, sep = os.pathsep):
wi = WhereIs('xxx.exe', string.join(pathdirs_1243, os.pathsep))
assert wi == test.workpath(sub4_xxx_exe), wi
+ wi = WhereIs('xxx.exe',reject = sub3_xxx_exe)
+ assert wi == test.workpath(sub4_xxx_exe), wi
+ wi = WhereIs('xxx.exe', pathdirs_1243, reject = sub3_xxx_exe)
+ assert wi == test.workpath(sub4_xxx_exe), wi
+
os.environ['PATH'] = string.join(pathdirs_1243, os.pathsep)
wi = WhereIs('xxx.exe')
assert wi == test.workpath(sub4_xxx_exe), wi
print env.WhereIs('xxx.exe', %s)
print WhereIs('xxx.exe', %s)
print WhereIs('xxx.exe', %s)
+print WhereIs('xxx.exe', %s, reject=%s)
""" % (subdir_SConscript,
repr(string.join(pathdirs_1234, os.pathsep)),
repr(string.join(pathdirs_1243, os.pathsep)),
repr(pathdirs_1234),
repr(pathdirs_1243),
+ repr(pathdirs_1243),
+ repr(sub4_xxx_exe)
))
test.write(subdir_SConscript, """
test.workpath(sub4_xxx_exe),
test.workpath(sub3_xxx_exe),
test.workpath(sub4_xxx_exe),
+ test.workpath(sub3_xxx_exe),
]
test.run(arguments = ".",
test.workpath(sub4_xxx_exe),
test.workpath(sub3_xxx_exe),
test.workpath(sub4_xxx_exe),
+ test.workpath(sub3_xxx_exe),
]
test.run(arguments = ".",