summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2018-07-03 11:15:35 +0200
committerMichael Olbrich <m.olbrich@pengutronix.de>2018-07-03 11:54:38 +0200
commitaa773b84ed85040f13db19fe7cbfd0f8047c7547 (patch)
treedbf066dfd1500df2d42aa23a65a764680f43eab1 /scripts
parenta02b3cb8d3d1d143e3b298de09e21fc6ea28eaea (diff)
downloadptxdist-aa773b84ed85040f13db19fe7cbfd0f8047c7547.tar.gz
ptxdist-aa773b84ed85040f13db19fe7cbfd0f8047c7547.tar.xz
license: generate yaml output
And add a converter to create CSV from the yaml data. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/ptxd_make_license_report.sh32
-rw-r--r--scripts/lib/ptxd_make_world_license.sh34
-rwxr-xr-xscripts/license-yaml2csv.py66
3 files changed, 129 insertions, 3 deletions
diff --git a/scripts/lib/ptxd_make_license_report.sh b/scripts/lib/ptxd_make_license_report.sh
index a6410d10d..7cb393298 100644
--- a/scripts/lib/ptxd_make_license_report.sh
+++ b/scripts/lib/ptxd_make_license_report.sh
@@ -263,7 +263,7 @@ ptxd_make_license_compliance_footer() {
}
export -f ptxd_make_license_compliance_footer
-ptxd_make_license_compliance() {
+ptxd_make_license_compliance_pdf() {
local -a ptxd_reply
local ptx_license_target_tex pkg_lic pkg
local -A ptxd_package_license_association
@@ -293,5 +293,33 @@ ptxd_make_license_compliance() {
ptxd_make_license_report_build &&
cp "${ptx_license_target_tex%.tex}.pdf" "${ptx_license_target}"
}
-export -f ptxd_make_license_compliance
+export -f ptxd_make_license_compliance_pdf
+
+ptxd_make_license_compliance_yaml() {
+ local -a ptxd_reply
+ local ptx_license_target_tex pkg_lic pkg
+ local -A ptxd_package_license_association
+
+ # regenerate license info and sort out unused packages
+ for pkg in $(cat "${ptx_report_dir}/package.list"); do
+ ptxd_package_license_association[$(basename ${pkg})]=$(dirname ${pkg})
+ done
+
+#
+# combine all package related info into one document
+#
+ (
+ for pkg in ${@}; do
+ pkg_lic="${ptxd_package_license_association[${pkg}]}"
+ if [ -z "${pkg_lic}" ]; then
+ continue
+ fi
+ pkg_lic="${pkg_lic}/${pkg}"
+ echo "${pkg}:"
+ sed 's/^/ /' "${ptx_report_dir}/${pkg_lic}/license-report.yaml"
+ done
+ ) > "${ptx_license_target}.tmp" &&
+ mv "${ptx_license_target}.tmp" "${ptx_license_target}"
+}
+export -f ptxd_make_license_compliance_yaml
diff --git a/scripts/lib/ptxd_make_world_license.sh b/scripts/lib/ptxd_make_world_license.sh
index 5c40ca97b..6922044f1 100644
--- a/scripts/lib/ptxd_make_world_license.sh
+++ b/scripts/lib/ptxd_make_world_license.sh
@@ -209,6 +209,33 @@ ptxd_make_world_license_write() {
}
export -f ptxd_make_world_license_write
+ptxd_make_world_license_yaml() {
+ cat << EOF
+flags: ${!pkg_license_flags[@]}
+licenses: ${pkg_license}
+md5: ${pkg_md5}
+name: ${pkg_label}
+section: ${pkg_section}
+url: ${pkg_url}
+version: ${pkg_version}
+license-files:
+EOF
+ local guess="no"
+ for license in "${pkg_license_texts[@]}" - "${pkg_license_texts_guessed[@]}"; do
+ if [ "${license}" = "-" ]; then
+ guess="yes"
+ continue
+ fi
+ cat << EOF
+ $(basename "${license}"):
+ guessed: ${guess}
+ file: ${license}
+ md5: $(sed -n "s/\(.*\) $(basename "${license}")\$/\1/p" "${pkg_license_dir}/license/MD5SUM")
+EOF
+ done
+}
+export -f ptxd_make_world_license_yaml
+
# Copy all patches according to the series file
# $1 full path to the series file
# $2 source directory
@@ -449,7 +476,10 @@ checksum of license file '$(ptxd_print_path "${file}")'
changed: ${md5} -> $(md5sum "${lic}" | sed 's/ .*//')
"
fi &&
- echo "${md5} $(basename ${lic})" >> "${pkg_license_dir}/license/MD5SUM" &&
+ (
+ cd "${pkg_license_dir}/license" &&
+ md5sum `basename ${lic}` >> MD5SUM 2>/dev/null
+ ) &&
if [ -z "${guess}" ]; then
pkg_license_texts[${#pkg_license_texts[@]}]="${lic}"
else
@@ -462,6 +492,8 @@ changed: ${md5} -> $(md5sum "${lic}" | sed 's/ .*//')
sed -e 's/%/\\%/g' > "${pkg_license_dir}/license-report.tex" &&
check_pipe_status &&
+ ptxd_make_world_license_yaml > "${pkg_license_dir}/license-report.yaml" &&
+
echo "${pkg_license}" > "${pkg_license_dir}/license-name" &&
if [ "${#pkg_license_flags[@]}" -gt 0 ]; then
echo "${!pkg_license_flags[@]}" > "${pkg_license_dir}/license-flags"
diff --git a/scripts/license-yaml2csv.py b/scripts/license-yaml2csv.py
new file mode 100755
index 000000000..1c8be2119
--- /dev/null
+++ b/scripts/license-yaml2csv.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2018 by Michael Olbrich <m.olbrich@pengutronix.de>
+#
+# See CREDITS for details about who has contributed to this project.
+#
+# For further information about the PTXdist project and license conditions
+# see the README file.
+#
+
+import argparse
+import sys
+import yaml
+
+def parse_separator(arg):
+ if len(arg) != 1:
+ raise argparse.ArgumentTypeError('field separator must be a single character')
+ else:
+ return arg
+
+def parse_input(arg):
+ if arg == '-':
+ return sys.stdin
+ try:
+ return open(arg)
+ except:
+ raise argparse.ArgumentTypeError('cannot access input file "{}"'.format(arg))
+
+def parse_fields(arg):
+ tmp = arg.split(',')
+ fields = []
+ for field in tmp:
+ field = field.strip()
+ if field:
+ fields.append(field)
+ if not fields:
+ raise argparse.ArgumentTypeError('at least on field must be specified')
+ return fields
+
+parser = argparse.ArgumentParser()
+parser.add_argument('-s', '--separator', type=parse_separator, default=',',
+ help='field separator [,]')
+parser.add_argument('-f', '--fields', type=parse_fields,
+ default=['name', 'version', 'section', 'licenses', 'flags'],
+ help='field list [name,version,section,licenses,flags]')
+parser.add_argument('input', nargs='?', type=parse_input,
+ default=sys.stdin, help='license yaml file [stdin]')
+
+args = parser.parse_args()
+
+for (_, record) in yaml.load(args.input.read(), Loader=yaml.loader.BaseLoader).items():
+ line = ""
+ for field in args.fields:
+ if line:
+ line += args.separator
+ value = record.get(field, None)
+ if not value:
+ value = ''
+ quote = args.separator in value or '"' in value
+ if quote:
+ line += '"'
+ line += value.replace('"', '""')
+ if quote:
+ line += '"'
+ line += "\n"
+ sys.stdout.write(line)