summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorChristopher Larson <chris_larson@mentor.com>2013-08-19 19:48:00 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-08-26 11:42:10 +0100
commita598242197312fa6d43179c283da2d0873de2919 (patch)
tree5638464d047ec7368df38ebe87166c52fbb00c9f /meta/lib
parentc10435025f5c51c4827d71af82a9a517f5f8f6d8 (diff)
downloadopenembedded-core-a598242197312fa6d43179c283da2d0873de2919.tar.gz
openembedded-core-a598242197312fa6d43179c283da2d0873de2919.tar.bz2
openembedded-core-a598242197312fa6d43179c283da2d0873de2919.zip
oe.types: add 'path' type
- 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) Signed-off-by: Christopher Larson <chris_larson@mentor.com> Signed-off-by: Saul Wold <sgw@linux.intel.com>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oe/types.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/meta/lib/oe/types.py b/meta/lib/oe/types.py
index 5dac9de239..7f47c17d0e 100644
--- a/meta/lib/oe/types.py
+++ b/meta/lib/oe/types.py
@@ -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