Re: [OE-core] [PATCH 1/2] image_license.bbclass: Write JSON files containing license data.

2019-05-29 Thread Rob Walton
Requesting review. Thanks.


From: Rob Walton
Sent: 22 May 2019 13:44:33
To: openembedded-core@lists.openembedded.org
Cc: Rob Walton
Subject: [PATCH 1/2] image_license.bbclass: Write JSON files containing license 
data.

For easier machine readability of license manifests, write a
manifest.json containing license data and package info.

Signed-off-by: Rob Walton 
---
 meta/classes/license_image.bbclass | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/meta/classes/license_image.bbclass 
b/meta/classes/license_image.bbclass
index 6750038..6952417 100644
--- a/meta/classes/license_image.bbclass
+++ b/meta/classes/license_image.bbclass
@@ -36,6 +36,7 @@ python license_create_manifest() {
 }

 def write_license_files(d, license_manifest, pkg_dic, rootfs=True):
+import json
 import re
 import stat

@@ -43,6 +44,7 @@ def write_license_files(d, license_manifest, pkg_dic, 
rootfs=True):
 bad_licenses = map(lambda l: canonical_license(d, l), bad_licenses)
 bad_licenses = expand_wildcard_licenses(d, bad_licenses)

+json_data = dict()
 with open(license_manifest, "w") as license_file:
 for pkg in sorted(pkg_dic):
 if bad_licenses:
@@ -63,7 +65,14 @@ def write_license_files(d, license_manifest, pkg_dic, 
rootfs=True):
 license_file.write("PACKAGE VERSION: %s\n" % 
pkg_dic[pkg]["PV"])
 license_file.write("RECIPE NAME: %s\n" % pkg_dic[pkg]["PN"])
 license_file.write("LICENSE: %s\n\n" % pkg_dic[pkg]["LICENSE"])
-
+json_data[pkg] = {
+"RECIPE NAME": pkg_dic[pkg]["PN"],
+"PACKAGE VERSION": pkg_dic[pkg]["PV"],
+"PACKAGE NAME": pkg,
+"LICENSE": pkg_dic[pkg]["LICENSE"],
+"HOMEPAGE": pkg_dic[pkg].get("HOMEPAGE", ""),
+"SUMMARY": pkg_dic[pkg].get("SUMMARY", ""),
+}
 # If the package doesn't contain any file, that is, its size 
is 0, the license
 # isn't relevant as far as the final image is concerned. So 
doing license check
 # doesn't make much sense, skip it.
@@ -75,6 +84,14 @@ def write_license_files(d, license_manifest, pkg_dic, 
rootfs=True):
 license_file.write("VERSION: %s\n" % pkg_dic[pkg]["PV"])
 license_file.write("LICENSE: %s\n" % pkg_dic[pkg]["LICENSE"])
 license_file.write("FILES: %s\n\n" % pkg_dic[pkg]["FILES"])
+json_data[pkg] = {
+"RECIPE NAME": pkg_dic[pkg]["PN"],
+"VERSION": pkg_dic[pkg]["PV"],
+"FILES": pkg_dic[pkg]["FILES"],
+"LICENSE": pkg_dic[pkg]["LICENSE"],
+"HOMEPAGE": pkg_dic[pkg].get("HOMEPAGE", ""),
+"SUMMARY": pkg_dic[pkg].get("SUMMARY", ""),
+}

 for lic in pkg_dic[pkg]["LICENSES"]:
 lic_file = os.path.join(d.getVar('LICENSE_DIRECTORY'),
@@ -89,6 +106,10 @@ def write_license_files(d, license_manifest, pkg_dic, 
rootfs=True):
 "licenses collected for recipe %s"
 % (lic, pkg_dic[pkg]["PN"]))

+# Write a json file containing the license data.
+with open("{}.json".format(license_manifest), "w") as license_file_json:
+license_file_json.write(json.dumps(json_data))
+
 # Two options here:
 # - Just copy the manifest
 # - Copy the manifest and the license directories
--
2.7.4

IMPORTANT NOTICE: The contents of this email and any attachments are 
confidential and may also be privileged. If you are not the intended recipient, 
please notify the sender immediately and do not disclose the contents to any 
other person, use it for any purpose, or store or copy the information in any 
medium. Thank you.
-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core


[OE-core] [PATCH 1/2] image_license.bbclass: Write JSON files containing license data.

2019-05-22 Thread Rob Walton
For easier machine readability of license manifests, write a
manifest.json containing license data and package info.

Signed-off-by: Rob Walton 
---
 meta/classes/license_image.bbclass | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/meta/classes/license_image.bbclass 
b/meta/classes/license_image.bbclass
index 6750038..6952417 100644
--- a/meta/classes/license_image.bbclass
+++ b/meta/classes/license_image.bbclass
@@ -36,6 +36,7 @@ python license_create_manifest() {
 }

 def write_license_files(d, license_manifest, pkg_dic, rootfs=True):
+import json
 import re
 import stat

@@ -43,6 +44,7 @@ def write_license_files(d, license_manifest, pkg_dic, 
rootfs=True):
 bad_licenses = map(lambda l: canonical_license(d, l), bad_licenses)
 bad_licenses = expand_wildcard_licenses(d, bad_licenses)

+json_data = dict()
 with open(license_manifest, "w") as license_file:
 for pkg in sorted(pkg_dic):
 if bad_licenses:
@@ -63,7 +65,14 @@ def write_license_files(d, license_manifest, pkg_dic, 
rootfs=True):
 license_file.write("PACKAGE VERSION: %s\n" % 
pkg_dic[pkg]["PV"])
 license_file.write("RECIPE NAME: %s\n" % pkg_dic[pkg]["PN"])
 license_file.write("LICENSE: %s\n\n" % pkg_dic[pkg]["LICENSE"])
-
+json_data[pkg] = {
+"RECIPE NAME": pkg_dic[pkg]["PN"],
+"PACKAGE VERSION": pkg_dic[pkg]["PV"],
+"PACKAGE NAME": pkg,
+"LICENSE": pkg_dic[pkg]["LICENSE"],
+"HOMEPAGE": pkg_dic[pkg].get("HOMEPAGE", ""),
+"SUMMARY": pkg_dic[pkg].get("SUMMARY", ""),
+}
 # If the package doesn't contain any file, that is, its size 
is 0, the license
 # isn't relevant as far as the final image is concerned. So 
doing license check
 # doesn't make much sense, skip it.
@@ -75,6 +84,14 @@ def write_license_files(d, license_manifest, pkg_dic, 
rootfs=True):
 license_file.write("VERSION: %s\n" % pkg_dic[pkg]["PV"])
 license_file.write("LICENSE: %s\n" % pkg_dic[pkg]["LICENSE"])
 license_file.write("FILES: %s\n\n" % pkg_dic[pkg]["FILES"])
+json_data[pkg] = {
+"RECIPE NAME": pkg_dic[pkg]["PN"],
+"VERSION": pkg_dic[pkg]["PV"],
+"FILES": pkg_dic[pkg]["FILES"],
+"LICENSE": pkg_dic[pkg]["LICENSE"],
+"HOMEPAGE": pkg_dic[pkg].get("HOMEPAGE", ""),
+"SUMMARY": pkg_dic[pkg].get("SUMMARY", ""),
+}

 for lic in pkg_dic[pkg]["LICENSES"]:
 lic_file = os.path.join(d.getVar('LICENSE_DIRECTORY'),
@@ -89,6 +106,10 @@ def write_license_files(d, license_manifest, pkg_dic, 
rootfs=True):
 "licenses collected for recipe %s"
 % (lic, pkg_dic[pkg]["PN"]))

+# Write a json file containing the license data.
+with open("{}.json".format(license_manifest), "w") as license_file_json:
+license_file_json.write(json.dumps(json_data))
+
 # Two options here:
 # - Just copy the manifest
 # - Copy the manifest and the license directories
--
2.7.4

IMPORTANT NOTICE: The contents of this email and any attachments are 
confidential and may also be privileged. If you are not the intended recipient, 
please notify the sender immediately and do not disclose the contents to any 
other person, use it for any purpose, or store or copy the information in any 
medium. Thank you.
-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core