~aleteoryx/tclircc

76f60368ef896dcfd80f9bd668171ece03820450 — Aleteoryx 12 days ago d356cce
boot!
4 files changed, 53 insertions(+), 59 deletions(-)

D bin/spdx-gen.tcl
A src/deps.tcl
M src/main.tcl
A src/persist.tcl
D bin/spdx-gen.tcl => bin/spdx-gen.tcl +0 -59
@@ 1,59 0,0 @@
#!/bin/env tclsh
# script to convert the spdx db to a dict
# FIXME: parallelize?

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 normalize [file join $dump_path .. src spdx 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"

A src/deps.tcl => src/deps.tcl +22 -0
@@ 0,0 1,22 @@
set deps {
  Tcl 8.6
  Tk 8.6
  sqlite3 3.47
  tls 1.7
  logger 0.9
}

set missing {}
foreach {dep ver} $deps {
  if [catch {package require $dep $ver}] {
    lappend missing $dep $ver
  }
}

if {$missing != {}} {
  puts stderr "can't boot! missing packages!"
  foreach {dep ver} $missing {
    puts stderr "  need \"$dep\" v$ver+"
  }
  exit -1
}

M src/main.tcl => src/main.tcl +14 -0
@@ 1,2 1,16 @@
#!/bin/env tclsh

set boot_dir [pwd]
cd [file dirname [dict get [info frame [info frame]] file]]

puts "boot_dir=$boot_dir"
puts "pwd=[pwd]"

source persist.tcl
source deps.tcl

set log [logger::init tclircc::main]

sqlite3 core_db [file join $data_dir core.db]

source migrate_core.tcl

A src/persist.tcl => src/persist.tcl +17 -0
@@ 0,0 1,17 @@
switch -- [set tcl_platform(platform)] {
  "windows" {
    set data_dir [file join [set env(APPDATA)] tclircc]
  }
  "unix" {
    if [info exists env(XDG_CONFIG_HOME)] {
      set data_dir [file join [set env(XDG_CONFIG_HOME)] tclircc]
    } elseif [info exists env(HOME)] {
      set data_dir [file join [set env(HOME)] .config tclircc]
    } else {
      return -code error {Missing $HOME or $XDG_CONFIG_HOME, can't store config!}
    }
  }
  default {
    return -code error {Unknown platform, can't store config.}
  }
}