From: Christopher Larson Date: Tue, 20 Aug 2013 02:48:00 +0000 (-0700) Subject: oe.types: add 'path' type X-Git-Tag: 2015-4~5396 X-Git-Url: https://code.ossystems.io/gitweb?a=commitdiff_plain;h=a598242197312fa6d43179c283da2d0873de2919;p=openembedded-core.git 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 Signed-off-by: Saul Wold --- 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