poky/meta/lib/oe/data.py
Richard Purdie ce08cf4825 lib: Add copyright statements to files without one
Where there isn't a copyright statement, add one to make it explicit.
Also add license identifiers as MIT if there isn't one.

(From OE-Core rev: bb731d1f3d2a1d50ec0aed864dbca54cf795b040)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2022-08-12 12:00:43 +01:00

54 lines
1.5 KiB
Python

#
# Copyright OpenEmbedded Contributors
#
# SPDX-License-Identifier: GPL-2.0-only
#
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, searchString="",replaceString=""):
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"):
continue
keys2export.append(key)
for key in keys2export:
try:
data2export[key] = d.getVar(key, expand).replace(searchString,replaceString)
except bb.data_smart.ExpansionError:
data2export[key] = ''
except AttributeError:
pass
with open(json_file, "w") as f:
json.dump(data2export, f, skipkeys=True, indent=4, sort_keys=True)