mirror of
https://git.yoctoproject.org/poky
synced 2026-01-29 21:08:42 +01:00
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>
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
import json
|
|
import oe.maketype
|
|
|
|
def typed_value(key, d):
|
|
"""Construct a value for the specified metadata variable, using its flags
|
|
to determine the type and parameters for construction."""
|
|
var_type = d.getVarFlag(key, 'type')
|
|
flags = d.getVarFlags(key)
|
|
if flags is not None:
|
|
flags = dict((flag, d.expand(value))
|
|
for flag, value in list(flags.items()))
|
|
else:
|
|
flags = {}
|
|
|
|
try:
|
|
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)
|