summaryrefslogtreecommitdiffstats
path: root/scripts/update_spdx.py
blob: fd615c51ae0aa3ecd3dd1248c0f14d4c50ef3b92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
#
# Copyright (C) 2018 by Michael Olbrich <m.olbrich@pengutronix.de>
#
# 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>
#
# 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()