From 76f60368ef896dcfd80f9bd668171ece03820450 Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Sat, 28 Dec 2024 01:33:32 -0500 Subject: [PATCH] boot! --- bin/spdx-gen.tcl | 59 ------------------------------------------------ src/deps.tcl | 22 ++++++++++++++++++ src/main.tcl | 14 ++++++++++++ src/persist.tcl | 17 ++++++++++++++ 4 files changed, 53 insertions(+), 59 deletions(-) delete mode 100755 bin/spdx-gen.tcl create mode 100644 src/deps.tcl create mode 100644 src/persist.tcl diff --git a/bin/spdx-gen.tcl b/bin/spdx-gen.tcl deleted file mode 100755 index 4191f1b..0000000 --- a/bin/spdx-gen.tcl +++ /dev/null @@ -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" diff --git a/src/deps.tcl b/src/deps.tcl new file mode 100644 index 0000000..0b32aed --- /dev/null +++ b/src/deps.tcl @@ -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 +} diff --git a/src/main.tcl b/src/main.tcl index 63b5948..72cf0c5 100755 --- a/src/main.tcl +++ b/src/main.tcl @@ -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 diff --git a/src/persist.tcl b/src/persist.tcl new file mode 100644 index 0000000..f9597b3 --- /dev/null +++ b/src/persist.tcl @@ -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.} + } +} -- 2.45.2