diff options
author | Chris Larson <chris_larson@mentor.com> | 2010-10-05 19:35:23 -0700 |
---|---|---|
committer | Chris Larson <chris_larson@mentor.com> | 2010-10-05 20:59:03 -0700 |
commit | 606fa1fd97cbd47a6a7ebdc7a2e6aa93a8f65cf5 (patch) | |
tree | c44090697b3ca530ad084e8bc1943a07ba3d69af /lib | |
parent | 8d661ce0c303e8d69f17c1d095545d5ed086d1d5 (diff) | |
download | bitbake-606fa1fd97cbd47a6a7ebdc7a2e6aa93a8f65cf5.tar.gz |
Access metadata vars as locals in python snippets
Example:
FOO = "bar"
BAR = "${@FOO + '/baz'}"
${BAR} == "bar/baz"
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bb/data_smart.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/bb/data_smart.py b/lib/bb/data_smart.py index 64fae2d7d..b4dffd548 100644 --- a/lib/bb/data_smart.py +++ b/lib/bb/data_smart.py @@ -43,6 +43,18 @@ __expand_var_regexp__ = re.compile(r"\${[^{}]+}") __expand_python_regexp__ = re.compile(r"\${@.+?}") +class DataDict(dict): + def __init__(self, metadata, **kwargs): + self.metadata = metadata + dict.__init__(self, **kwargs) + + def __missing__(self, key): + value = self.metadata.getVar(key, True) + if value is None: + raise KeyError(key) + else: + return value + class DataSmart(MutableMapping): def __init__(self, special = COWDictBase.copy(), seen = COWDictBase.copy() ): self.dict = {} @@ -68,7 +80,7 @@ class DataSmart(MutableMapping): def python_sub(match): code = match.group()[3:-1] codeobj = compile(code.strip(), varname or "<expansion>", "eval") - value = utils.better_eval(codeobj, {"d": self}) + value = utils.better_eval(codeobj, DataDict(self, d=self)) return str(value) if not isinstance(s, basestring): # sanity check |