Add a reject argument to the env.Whereis() method. (sam th)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 4 Apr 2004 10:40:32 +0000 (10:40 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 4 Apr 2004 10:40:32 +0000 (10:40 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@948 fdb21ef1-2011-0410-befe-b5e4ea1792b1

doc/man/scons.1
src/CHANGES.txt
src/engine/SCons/Environment.py
src/engine/SCons/EnvironmentTests.py
src/engine/SCons/Util.py
src/engine/SCons/UtilTests.py
test/WhereIs.py

index 232048b54d71a694e98a828b155071dc80b00fd0..357b829cd7300747e1e332f2a7f1287ae6e6f33f 100644 (file)
@@ -3709,9 +3709,9 @@ env.Config(target = 'package-config', source = Value(prefix))
 
 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 .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,
@@ -3734,6 +3734,11 @@ the calling environment's PATHEXT
 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,
index 8b9c32a93e433b00ce4f590e43ba1a482003b566..e306bd99712a044604571ad9fec7a4fc9cd821ba 100644 (file)
@@ -77,6 +77,9 @@ RELEASE 0.96 - XXX
   - 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
index e75ac38762a313c58d8efc5ead9cc480a2a059d6..1b85fe86cbd63c2f22526cdeae165524f24d6de3 100644 (file)
@@ -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
 
index 53a6905c219c0190a217d65943b49d7ccc998c95..3f0aab6293a19d23b2a17e17e91bb7bee2462992 100644 (file)
@@ -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')
index e07675c7683e8d19b7873a61e904de2950ad4639..d2e1d73c0979e409908aa9136fb98e15c0cd54df 100644 (file)
@@ -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):
index 098c2d92be77770a676a9cdbc86ee64efff1c758..5825406ed49d45a3aced5b7ce77a2b7dc9bca8e8 100644 (file)
@@ -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
index 8347acc707adbe87f0161912cbc3eace95772935..15f44422ea01ba6385fe3cc0ade4603f7b782c51 100644 (file)
@@ -73,11 +73,14 @@ print WhereIs('xxx.exe', %s)
 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, """
@@ -105,6 +108,7 @@ expect = [ test.workpath(sub3_xxx_exe),
            test.workpath(sub4_xxx_exe),
            test.workpath(sub3_xxx_exe),
            test.workpath(sub4_xxx_exe),
+           test.workpath(sub3_xxx_exe),
         ]
 
 test.run(arguments = ".",
@@ -123,6 +127,7 @@ expect = [ test.workpath(sub4_xxx_exe),
            test.workpath(sub4_xxx_exe),
            test.workpath(sub3_xxx_exe),
            test.workpath(sub4_xxx_exe),
+           test.workpath(sub3_xxx_exe),
         ]
 
 test.run(arguments = ".",