[oe-commits] [bitbake] 01/02: bb/utils: extend which() so it can look for just executables

git at git.openembedded.org git at git.openembedded.org
Thu Mar 30 15:44:30 UTC 2017


This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch master-next
in repository bitbake.

commit c0b94f02f0cba7a424aaa16cf98c0f7a3f62b889
Author: Ross Burton <ross.burton at intel.com>
AuthorDate: Thu Mar 30 14:34:17 2017 +0100

    bb/utils: extend which() so it can look for just executables
    
    Normally bb.utils.which() is used by the unpack code to find a file in a variety
    of places, but it is useful as a slightly more powerful version of os.which().
    
    Support this by allowing it to only return matches which are executable files,
    instead of just the first filename that matches.
    
    Signed-off-by: Ross Burton <ross.burton at intel.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 lib/bb/utils.py | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index d6bcfa3..077fddc 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -899,11 +899,20 @@ def copyfile(src, dest, newmtime = None, sstat = None):
         newmtime = sstat[stat.ST_MTIME]
     return newmtime
 
-def which(path, item, direction = 0, history = False):
+def which(path, item, direction = 0, history = False, executable=False):
     """
-    Locate a file in a PATH
+    Locate `item` in the list of paths `path` (colon separated string like $PATH).
+    If `direction` is non-zero then the list is reversed.
+    If `history` is True then the list of candidates also returned as result,history.
+    If `executable` is True then the candidate has to be an executable file,
+    otherwise the candidate simply has to exist.
     """
 
+    if executable:
+        is_candidate = lambda p: os.path.isfile(p) and os.access(p, os.X_OK)
+    else:
+        is_candidate = lambda p: os.path.exists(p)
+
     hist = []
     paths = (path or "").split(':')
     if direction != 0:
@@ -912,7 +921,7 @@ def which(path, item, direction = 0, history = False):
     for p in paths:
         next = os.path.join(p, item)
         hist.append(next)
-        if os.path.exists(next):
+        if is_candidate(next):
             if not os.path.isabs(next):
                 next = os.path.abspath(next)
             if history:

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list