Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH] oe.types: add 'path' type
@ 2013-08-20  2:48 Christopher Larson
  2013-08-20 15:23 ` Otavio Salvador
  0 siblings, 1 reply; 3+ messages in thread
From: Christopher Larson @ 2013-08-20  2:48 UTC (permalink / raw)
  To: openembedded-core; +Cc: Christopher Larson

From: Christopher Larson <chris_larson@mentor.com>

- 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>
---
 meta/lib/oe/types.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/meta/lib/oe/types.py b/meta/lib/oe/types.py
index 5dac9de..7f47c17 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
-- 
1.8.3.4



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-08-20 15:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-20  2:48 [PATCH] oe.types: add 'path' type Christopher Larson
2013-08-20 15:23 ` Otavio Salvador
2013-08-20 15:45   ` Chris Larson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox