Skip to contentSkip to conversation

oe.types: add 'path' type

PATCH In review Christopher Larson 2 participants 3 messages Aug 20, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 oe.types: add 'path' type

From: Christopher Larson <[email protected]>

- 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)

---
 meta/lib/oe/types.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
meta/lib/oe/types.py +18 -0
index 5dac9de..7f47c17 100644
@@ -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
Signature · 1 line
1.8.3.4
#1 lore raw
Quoted 7 lines · Christopher Larson

From: Christopher Larson <[email protected]>

- 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)

Great addition :-)

meta/lib/oe/types.py line 4

Quoted 13 lines
---
 meta/lib/oe/types.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
meta/lib/oe/types.py +3 -0
index 5dac9de..7f47c17 100644
@@ -1,4 +1,7 @@
+import errno
 import re
+import os
+

No need for another new and empty line here.

Rest of code looks alright :-)

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
#2 lore raw
Quoted 29 lines · Otavio Salvador
Quoted 4 lines · Christopher Larson

From: Christopher Larson <[email protected]>

- path normalization ('normalize' flag, defaults to enabled)
- existence verification for paths we know should exist ('mustexist'

flag)

Quoted 3 lines

- supports clean handling of relative paths ('relativeto' flag)

Great addition :-)

meta/lib/oe/types.py line 4

Quoted 13 lines
---
 meta/lib/oe/types.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
meta/lib/oe/types.py +3 -0
index 5dac9de..7f47c17 100644
@@ -1,4 +1,7 @@
+import errno
 import re
+import os
+

No need for another new and empty line here.

Quoted 1 line

Rest of code looks alright :-)

Good call, will tweak slightly and re-submit. Thanks for the review.

Signature · 5 lines
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics