summaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2004-04-04 10:40:32 (GMT)
committerSteven Knight <knight@baldmt.com>2004-04-04 10:40:32 (GMT)
commit7c4349c483afaf1c2399025a2850d2b486c20178 (patch)
treeefe6cfb4bc3433988545bf74ded85ebb6b4fc14b /src/engine
parent3a0ca2e66fd1449d3a9b400aabe17fee0eb7f496 (diff)
downloadSCons-7c4349c483afaf1c2399025a2850d2b486c20178.zip
SCons-7c4349c483afaf1c2399025a2850d2b486c20178.tar.gz
SCons-7c4349c483afaf1c2399025a2850d2b486c20178.tar.bz2
Add a reject argument to the env.Whereis() method. (sam th)
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/SCons/Environment.py4
-rw-r--r--src/engine/SCons/EnvironmentTests.py5
-rw-r--r--src/engine/SCons/Util.py30
-rw-r--r--src/engine/SCons/UtilTests.py5
4 files changed, 36 insertions, 8 deletions
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py
index e75ac38..1b85fe8 100644
--- a/src/engine/SCons/Environment.py
+++ b/src/engine/SCons/Environment.py
@@ -833,7 +833,7 @@ class Base:
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:
@@ -850,7 +850,7 @@ class Base:
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
diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py
index 53a6905..3f0aab6 100644
--- a/src/engine/SCons/EnvironmentTests.py
+++ b/src/engine/SCons/EnvironmentTests.py
@@ -1590,6 +1590,11 @@ class EnvironmentTestCase(unittest.TestCase):
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')
diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py
index e07675c..d2e1d73 100644
--- a/src/engine/SCons/Util.py
+++ b/src/engine/SCons/Util.py
@@ -980,7 +980,7 @@ if can_read_reg:
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):
@@ -996,17 +996,23 @@ if sys.platform == 'win32':
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):
@@ -1017,21 +1023,29 @@ elif os.name == 'os2':
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):
@@ -1040,7 +1054,11 @@ else:
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):
diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py
index 098c2d9..5825406 100644
--- a/src/engine/SCons/UtilTests.py
+++ b/src/engine/SCons/UtilTests.py
@@ -1050,6 +1050,11 @@ class UtilTestCase(unittest.TestCase):
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