From: Christopher Larson <kergoth@gmail.com>
To: openembedded-core@lists.openembedded.org
Cc: Christopher Larson <chris_larson@mentor.com>
Subject: [PATCH] oe.types: add 'path' type
Date: Mon, 19 Aug 2013 19:48:00 -0700 [thread overview]
Message-ID: <1376966880-4557-1-git-send-email-kergoth@gmail.com> (raw)
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
next reply other threads:[~2013-08-20 2:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-20 2:48 Christopher Larson [this message]
2013-08-20 15:23 ` [PATCH] oe.types: add 'path' type Otavio Salvador
2013-08-20 15:45 ` Chris Larson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1376966880-4557-1-git-send-email-kergoth@gmail.com \
--to=kergoth@gmail.com \
--cc=chris_larson@mentor.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox