oe.types: add 'path' type
authorChristopher Larson <chris_larson@mentor.com>
Tue, 20 Aug 2013 02:48:00 +0000 (19:48 -0700)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 26 Aug 2013 10:47:18 +0000 (11:47 +0100)
- path normalization ('normalize' flag, defaults to enabled)
- existence verification for paths we know should exist ('mustexist' flag)
- supports clean handling of relative paths ('relativeto' flag)

(From OE-Core rev: a598242197312fa6d43179c283da2d0873de2919)

Signed-off-by: Christopher Larson <chris_larson@mentor.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oe/types.py

index 5dac9de..7f47c17 100644 (file)
@@ -1,4 +1,7 @@
+import errno
 import re
+import os
+
 
 class OEList(list):
     """OpenEmbedded 'list' type
@@ -133,3 +136,18 @@ def float(value, fromhex='false'):
         return _float.fromhex(value)
     else:
         return _float(value)
+
+def path(value, relativeto='', normalize='true', mustexist='false'):
+    value = os.path.join(relativeto, value)
+
+    if boolean(normalize):
+        value = os.path.normpath(value)
+
+    if boolean(mustexist):
+        try:
+            open(value, 'r')
+        except IOError as exc:
+            if exc.errno == errno.ENOENT:
+                raise ValueError("{0}: {1}".format(value, os.strerror(errno.ENOENT)))
+
+    return value