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
#!/bin/env tclsh
# script to convert the spdx db to a dict
package require http
package require json
package require tls
tls::init -autoservername true
http::register https 443 ::tls::socket
set dump_path [dict get [info frame [info frame]] file]
set dump_path [file dirname $dump_path]
set dump_path [file join $dump_path dump.tcldict.gz]
puts "will save to $dump_path"
set tok [http::geturl "https://spdx.org/licenses/licenses.json"]
if {[http::ncode $tok] != 200} {
puts stderr "got [http::code $tok] downloading index: [http::data $tok]"
exit -1
}
set licenses [json::json2dict [http::data $tok]]
unset $tok
set licenses [dict get $licenses licenses]
set dump {}
set lcount [llength $licenses]
puts "downloading $lcount licenses"
set progress 0
foreach license $licenses {
set tok [http::geturl [dict get $license detailsUrl]]
if {[http::ncode $tok] != 200} {
puts stderr "got [http::code $tok] downloading license [dict get $license licenseId]: [http::data $tok]"
exit -2
}
set details [json::json2dict [http::data $tok]]
unset $tok
dict set dump [dict get $license licenseId] \
[list name [dict get $license name] \
spdx_uri [dict get $license reference] \
see_also [dict get $license seeAlso] \
text [dict get $details licenseText]]
incr progress
puts -nonewline "downloaded $progress / $lcount\r"
flush stdout
}
puts "downloaded $lcount licenses"
set dumpfd [open $dump_path w]
zlib push gzip $dumpfd -level 9
puts $dumpfd $dump
flush $dumpfd
close $dumpfd
puts "saved to $dump_path"