summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2018-02-12 12:50:49 +0100
committerMichael Olbrich <m.olbrich@pengutronix.de>2018-03-12 08:59:43 +0100
commit6266e44d4f1e1960e06a6ed5d5355bc0228f8c7d (patch)
tree47e7af361bd739ee25bbc0e79f103adbec28de79
parent3917349ea55c500af30c063e29fa66ee08b42312 (diff)
downloadptxdist-6266e44d4f1e1960e06a6ed5d5355bc0228f8c7d.tar.gz
ptxdist-6266e44d4f1e1960e06a6ed5d5355bc0228f8c7d.tar.xz
update_spdx: handle new upstream data format
The source data for the SPDX license data changed to XML. There are also a generated JSON files. Use those to generate our license classification function. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rwxr-xr-xscripts/update_spdx.py62
-rwxr-xr-xscripts/update_spdx.sh109
2 files changed, 62 insertions, 109 deletions
diff --git a/scripts/update_spdx.py b/scripts/update_spdx.py
new file mode 100755
index 000000000..c6e20f970
--- /dev/null
+++ b/scripts/update_spdx.py
@@ -0,0 +1,62 @@
+#!/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 json
+import sys
+from os.path import basename
+
+data = json.load(open(sys.argv[1]))
+ex_data = json.load(open(sys.argv[2]))
+
+outfile = open(sys.argv[3], 'w')
+
+outfile.write("""
+#!/bin/bash
+#
+# 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.
+#
+
+#
+# WARNING: This file is generated with '%s' from
+# '%s' and '%s'.
+#
+# The source files can be found in the SPDX data repository:
+# https://github.com/spdx/license-list-data.git
+
+ptxd_make_spdx() {
+ license="${1}"
+
+ case "${license}" in
+""" % (basename(sys.argv[0]), basename(sys.argv[1]), basename(sys.argv[2])))
+
+for l in data['licenses']:
+ arg = ''
+ if l['isDeprecatedLicenseId']:
+ arg = 'deprecated="true" '
+ elif l['isOsiApproved']:
+ arg = 'osi="true" '
+ outfile.write(" {}) {};;\n".format(l['licenseId'], arg))
+
+for l in ex_data['exceptions']:
+ if l['isDeprecatedLicenseId']:
+ continue
+ outfile.write(" {}) exception=\"true\" ;;\n".format(l['licenseExceptionId']))
+
+outfile.write(""" *) return 1 ;;
+ esac
+}
+export -f ptxd_make_spdx
+""")
+outfile.close()
diff --git a/scripts/update_spdx.sh b/scripts/update_spdx.sh
deleted file mode 100755
index d601b1869..000000000
--- a/scripts/update_spdx.sh
+++ /dev/null
@@ -1,109 +0,0 @@
-#!/bin/bash
-#
-# Copyright (C) 2015 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.
-#
-
-license_file="${1}"
-exception_file="${2}"
-output="$(dirname "$0")/lib/ptxd_make_spdx.sh"
-delim='|'
-
-if [ "${#}" -ne 2 ]; then
- echo "usage: $0 <license-file> <exception-file>"
- exit 1
-fi
-if [ ! -f "${license_file}" ]; then
- echo "license file missing!"
- exit 1
-fi
-if [ ! -f "${exception_file}" ]; then
- echo "exception file missing!"
- exit 1
-fi
-
-export IFS="${delim}"
-
-(
- sed '/^$/q' "$0"
-
- cat <<EOF
-#
-# WARNING: This file is generated with '$(basename "${0}")' from
-# '$(basename "${license_file}")' and '$(basename "${exception_file}")'.
-#
-# To regenerate this file export the license and exception sheets from the
-# original SPDX license list using '${delim}' as field delimiter and run
-# '$(basename "${0}")'.
-
-ptxd_make_spdx() {
- license="\${1}"
-
- case "\${license}" in
-EOF
-
- last=
- cols=0
- echo "parsing license file ..." >&2
- cat "${license_file}" | while read line; do
- line="${last} ${line}"
- last=
- count="$(echo "${line}" | sed "s/[^${delim}]//g" | wc -c)"
- if [ "${cols}" -eq 0 ]; then
- cols="${count}"
- fi
- if [ "${count}" -lt "${cols}" ]; then
- last="${line}"
- continue
- fi
- if [ "${count}" -gt "${cols}" ]; then
- echo "Too many columns: ${count}!" >&2
- exit 1
- fi
- set -- ${line}
- if [ "${2}" = "License Identifier" -o -z "${2}" ]; then
- continue
- fi
- echo -n " ${2}) "
- if [ "${5}" = "YES" ]; then
- echo -n 'osi="true" '
- fi
- echo ";;"
- done
- last=
- cols=0
- echo "parsing exception file ..." >&2
- cat "${exception_file}" | while read line; do
- line="${last} ${line}"
- last=
- count="$(echo "${line}" | sed "s/[^${delim}]//g" | wc -c)"
- if [ "${cols}" -eq 0 ]; then
- cols="${count}"
- fi
- if [ "${count}" -lt "${cols}" ]; then
- last="${line}"
- continue
- fi
- if [ "${count}" -gt "${cols}" ]; then
- echo "Too many columns: ${count}!" >&2
- exit 1
- fi
- set -- ${line}
- if [ "${2}" = "Exception Identifier" -o -z "${2}" ]; then
- continue
- fi
- echo -n " ${2}) exception=\"true\" "
- echo ";;"
- done
-
-cat <<EOF
- *) return 1 ;;
- esac
-}
-export -f ptxd_make_spdx
-EOF
-) > "${output}"