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)

(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>
This commit is contained in:
Christopher Larson 2013-08-19 19:48:00 -07:00 committed by Richard Purdie
parent 78012a289a
commit 66eac2df0c
1 changed files with 18 additions and 0 deletions

View 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