bb/__init__.py: Improve which function
authorRichard Purdie <rpurdie@linux.intel.com>
Sun, 12 Aug 2007 12:09:59 +0000 (12:09 +0000)
committerRichard Purdie <rpurdie@linux.intel.com>
Sun, 12 Aug 2007 12:09:59 +0000 (12:09 +0000)
lib/bb/__init__.py

index e601eda..1bfecc4 100644 (file)
@@ -345,14 +345,20 @@ def encodeurl(decoded):
 #######################################################################
 
 def which(path, item, direction = 0):
-    """Useful function for locating a file in a PATH"""
-    found = ""
+    """
+    Locate a file in a PATH
+    """
+
+    paths = (path or "").split(':')
+    if direction != 0:
+        paths.reverse()
+
     for p in (path or "").split(':'):
-        if os.path.exists(os.path.join(p, item)):
-            found = os.path.join(p, item)
-            if direction == 0:
-                break
-    return found
+        next = os.path.join(p, item)
+        if os.path.exists(next):
+            return next
+
+    return ""
 
 #######################################################################