summaryrefslogtreecommitdiff
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:03:53 +0000
commit57c7bf68ed66a56601e1431bb2db750c5742b5ce (patch)
treee623d9c4880dc8093f5afb3846955199dc9d80f7
parent9d474172c47695be1a61538f5b87ca8d9db25fa7 (diff)
downloadopenembedded-core-57c7bf68ed66a56601e1431bb2db750c5742b5ce.tar.gz
openembedded-core-57c7bf68ed66a56601e1431bb2db750c5742b5ce.tar.bz2
openembedded-core-57c7bf68ed66a56601e1431bb2db750c5742b5ce.zip
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. Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
-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 @@
+import json
import oe.maketype
def typed_value(key, d):
@@ -15,3 +16,30 @@ def typed_value(key, d):
return oe.maketype.create(d.getVar(key) or '', var_type, **flags)
except (TypeError, ValueError) as exc:
bb.msg.fatal("Data", "%s: %s" % (key, str(exc)))
+
+def export2json(d, json_file, expand=True):
+ data2export = {}
+ keys2export = []
+
+ for key in d.keys():
+ if key.startswith("_"):
+ continue
+ elif key.startswith("BB"):
+ continue
+ elif key.startswith("B_pn"):
+ continue
+ elif key.startswith("do_"):
+ continue
+ elif d.getVarFlag(key, "func", True):
+ continue
+
+ keys2export.append(key)
+
+ for key in keys2export:
+ try:
+ data2export[key] = d.getVar(key, expand)
+ except bb.data_smart.ExpansionError:
+ data2export[key] = ''
+
+ with open(json_file, "w") as f:
+ json.dump(data2export, f, skipkeys=True, indent=4, sort_keys=True)