summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/data.py
diff options
context:
space:
mode:
authorAníbal Limón <anibal.limon@linux.intel.com>2016-11-25 11:36:06 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-01-23 12:05:18 +0000
commit4054b25d5ec2394fe0ccba349bb90b1845ab6a5d (patch)
tree4c6941da86e016224e7a103e28d11f02f7afa988 /meta/lib/oe/data.py
parent388503c032112259750eda4c14c537ab14bf684d (diff)
downloadpoky-4054b25d5ec2394fe0ccba349bb90b1845ab6a5d.tar.gz
oe/data: Add export2json function
The export2json function export the variables contained in the data store to JSON format, the main usage for now will be to provide test data to QA framework. (From OE-Core rev: 57c7bf68ed66a56601e1431bb2db750c5742b5ce) Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe/data.py')
-rw-r--r--meta/lib/oe/data.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/meta/lib/oe/data.py b/meta/lib/oe/data.py
index 4a67c457b3..39567333f1 100644
--- a/meta/lib/oe/data.py
+++ b/meta/lib/oe/data.py
@@ -1,3 +1,4 @@
1import json
1import oe.maketype 2import oe.maketype
2 3
3def typed_value(key, d): 4def typed_value(key, d):
@@ -15,3 +16,30 @@ def typed_value(key, d):
15 return oe.maketype.create(d.getVar(key) or '', var_type, **flags) 16 return oe.maketype.create(d.getVar(key) or '', var_type, **flags)
16 except (TypeError, ValueError) as exc: 17 except (TypeError, ValueError) as exc:
17 bb.msg.fatal("Data", "%s: %s" % (key, str(exc))) 18 bb.msg.fatal("Data", "%s: %s" % (key, str(exc)))
19
20def export2json(d, json_file, expand=True):
21 data2export = {}
22 keys2export = []
23
24 for key in d.keys():
25 if key.startswith("_"):
26 continue
27 elif key.startswith("BB"):
28 continue
29 elif key.startswith("B_pn"):
30 continue
31 elif key.startswith("do_"):
32 continue
33 elif d.getVarFlag(key, "func", True):
34 continue
35
36 keys2export.append(key)
37
38 for key in keys2export:
39 try:
40 data2export[key] = d.getVar(key, expand)
41 except bb.data_smart.ExpansionError:
42 data2export[key] = ''
43
44 with open(json_file, "w") as f:
45 json.dump(data2export, f, skipkeys=True, indent=4, sort_keys=True)