~aleteoryx/tclircc

ref: 2f663e09384d7d90974294e1bfe71f12b9f895c8 tclircc/spdx/lib.tcl -rw-r--r-- 1.1 KiB
2f663e09aleteoryx update main a month ago
                                                                                
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
namespace eval spdx {
  set log [logger::init spdx]

  variable db

  proc load {} {
    variable log
    variable db

    if {[array exists db]} { return }

    ${log}::debug "loading database..."

    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]

    set dump [open $dump_path]
    zlib push gunzip $dump
    set data [read $dump]
    close $dump
    unset dump
    unset dump_path

    foreach {name info} $data {
      set db($name) $info
    }
    unset data

    ${log}::debug "database loaded with [array size db] licenses!"
  }

  proc exists {id} {
    variable db
    ::spdx::load
    expr {$id in [array names db -exact $id]}
  }
  proc get_name {id} {
    variable db
    ::spdx::load
    dict get [set db($id)] name
  }
  proc get_text {id} {
    variable db
    ::spdx::load
    dict get [set db($id)] text
  }
  proc get_spdx_url {id} {
    variable db
    ::spdx::load
    dict get [set db($id)] spdx_url
  }
  proc get_see_also {id} {
    variable db
    ::spdx::load
    dict get [set db($id)] see_also
  }
}