migrated tiiview and tiix to sqlite3

This commit is contained in:
Luxferre
2024-10-23 21:23:26 +03:00
parent a86bb5a0e6
commit ec47764a55
3 changed files with 47 additions and 79 deletions
+2 -2
View File
@@ -32,8 +32,8 @@ Readiness status
* config.txt (format/fields): ready/tested
* stations.txt (format): ready/tested
* auth.txt (format): ready/tested
* tiix.tcl: work in progress
* Overall status: CLI-ready. work in progress for GUI
* tiix.tcl: ready/testing
* Overall status: basically ready, bugfixing in progress
Usage
-----
+1
View File
@@ -96,6 +96,7 @@ if {$echoname eq ""} { # list the echonames
}
puts "Subj: $msg(subj)"
puts $hdrline
set msg(body) [lmap s $msg(body) {string trimright $s}]
puts "[tiiflow $msg(body) $twidth]\n\n$globalline\n"
}
}
+44 -77
View File
@@ -1,10 +1,11 @@
#!/usr/bin/env tclsh
# tiix: GUI client for ii/idec networks that leverages capabilities
# of tiifetch and tiipost and repimplements the tiiview functionality
# Depends on tiifetch, tiipost, Tcllib and Tk
# Depends on tiifetch, tiipost, Tcllib, SQLite3 and Tk
# Created by Luxferre in 2024, released into public domain
package require Tk
package require sqlite3
set scriptpath [file normalize [info script]]
set appdir [file dirname $scriptpath]
@@ -79,10 +80,8 @@ if {[file exists $authfile]} {
set authmap [readfile $authfile]
}
# get the local DB directory path
set localdbdir [file join $appdir "tiidb"]
set msgdir [file join $localdbdir "msg"]
set echodir [file join $localdbdir "echo"]
# get the local DB file path
set localdb [file join $appdir "tii.db"]
# set default GUI parameters
@@ -95,7 +94,6 @@ set tiix_post_repto ""
set tiix_filter_num 0
set tiix_filter_regex ""
set tiix_filter_rev 0
set tiix_filter_tail 0
set tiix_status Ready
set tiix_entry 0
@@ -126,84 +124,51 @@ proc linkinsert {textw uri is_orig} {
lappend linklist $uri
}
proc tiix_formatmessage {msgdata msgid} {
set globalline [string repeat = 80]
set hdrline [string repeat - 80]
set msglines [lmap s [split $msgdata "\n"] {string trimright $s}]
# parsing according to the spec, first 7 lines are:
# tags, echoarea, timestamp, msgfrom, msgfrom_addr, msgto, subj
# and then an empty line and the message body follows
set tags [split [lindex $msglines 0] "/"]
if {[dict exists $tags repto]} {
set replyto [dict get $tags repto]
} else {set replyto ""}
set echoarea [lindex $msglines 1]
set timestamp [lindex $msglines 2]
set msgfrom [lindex $msglines 3]
set msgfromaddr [lindex $msglines 4]
set msgto [lindex $msglines 5]
set subj [lindex $msglines 6]
set msgbody [join [lrange $msglines 8 end] "\n"]
set tz ""
set renderedts ""
catch { # because some servers don't provide timestamps
set renderedts [clock format $timestamp -format {%Y-%m-%d %H:%M:%S} -timezone $tz]
}
set textw .tabbar.r.content.text
$textw insert end "\[$renderedts\] "
linkinsert $textw $msgid 1
$textw insert end "\n$echoarea - $msgfrom ($msgfromaddr) to $msgto\n"
if {$replyto ne ""} {
$textw insert end "Replied to: "
linkinsert $textw "$replyto" 0
$textw insert end "\n"
}
$textw insert end "Subj: $subj\n$hdrline\n$msgbody\n$globalline\n\n"
}
proc tiix_viewecho {} {
global echodir msgdir linkcount tiix_echoname
global tiix_filter_num tiix_filter_regex tiix_filter_rev tiix_filter_tail
global localdb linkcount tiix_echoname
global tiix_filter_num tiix_filter_regex tiix_filter_rev
if {$tiix_echoname eq ""} {
errmsg "Please select an echo conference to read!"
return
}
set echofile [file join $echodir $tiix_echoname]
set msglist [split [readfile $echofile] "\n"]
set numitems $tiix_filter_num
# perform the element filtering
if {$numitems > 0} {
incr numitems -1
if {$tiix_filter_tail eq 1} {
set msglist [lrange $msglist end-$numitems end]
} else {
set msglist [lrange $msglist 0 $numitems]
}
}
if {$tiix_filter_rev eq 1} {
set msglist [lreverse $msglist]
# open the message db
sqlite3 msgdb $localdb -readonly true
set query {SELECT * FROM `msg` WHERE `echoname` = $tiix_echoname}
if {$tiix_filter_regex ne {}} {
append query { AND (`body` LIKE $tiix_filter_regex OR `subj` LIKE $tiix_filter_regex) }
}
append query { ORDER BY `timestamp` }
if {$tiix_filter_rev eq 1} {append query DESC} else {append query ASC}
if {$tiix_filter_num > 0} {append query { LIMIT $tiix_filter_num}}
append query ";"
set textw .tabbar.r.content.text
$textw configure -state normal
$textw delete 1.0 end
set linkcount 0
set linklist ""
foreach msgid $msglist { # iterate over the list after filtering
set msgid [string trim $msgid]
if {$msgid ne ""} {
set msgfile [file join $msgdir $msgid]
if {[file exists $msgfile]} {
set msgdata [readfile $msgfile]
set pass 1
if {$tiix_filter_regex ne {}} {
set pass [regexp -line -nocase -- $tiix_filter_regex $msgdata]
}
if {$pass eq 1} {tiix_formatmessage $msgdata $msgid}
}
msgdb eval $query msg { # iterate over the list after filtering
set globalline [string repeat = 80]
set hdrline [string repeat - 80]
set tz ""
set renderedts ""
catch { # because some servers don't provide timestamps
set renderedts [clock format $msg(timestamp) -format {%Y-%m-%d %H:%M:%S} -timezone $tz]
}
set textw .tabbar.r.content.text
$textw insert end "\[$renderedts\] "
linkinsert $textw $msg(msgid) 1
$textw insert end "\n$msg(echoname) - $msg(msgfrom) ($msg(msgfromaddr)) to $msg(msgto)\n"
if {$msg(repto) ne ""} {
$textw insert end "Replied to: "
linkinsert $textw "$msg(repto)" 0
$textw insert end "\n"
}
set msg(body) [lmap s $msg(body) {string trimright $s}]
$textw insert end "Subj: $msg(subj)\n$hdrline\n[join $msg(body) \n]\n\n$globalline\n\n"
}
$textw configure -state disabled
# close the message db
msgdb close
}
# fetcher frontend
@@ -216,9 +181,9 @@ proc tiix_fetchecho {echoname} {
no {return}
}
}
global tiix_status localdbdir
global tiix_status localdb
set tiix_status "Fetching echo contents..."
massfetch $echoname $localdbdir 0
massfetch $echoname $localdb 0
set tiix_status Ready
}
@@ -252,20 +217,20 @@ ttk::frame .tabbar.r.addrframe.f
ttk::frame .tabbar.r.addrframe.c
ttk::label .tabbar.r.addrframe.f.el -text "Echo name"
ttk::combobox .tabbar.r.addrframe.f.echo -width 25 -textvariable tiix_echoname -postcommand {
set echonames [lsort [glob -tails -directory $echodir -nocomplain -types f "*.*"]]
sqlite3 msgdb $localdb -readonly true
set echonames [msgdb eval {SELECT DISTINCT `echoname` FROM `msg` ORDER BY `echoname`;}]
msgdb close
.tabbar.r.addrframe.f.echo config -values $echonames
}
ttk::label .tabbar.r.addrframe.c.aml -text "# Messages:"
ttk::entry .tabbar.r.addrframe.c.amt -textvariable tiix_filter_num -width 8
ttk::checkbutton .tabbar.r.addrframe.c.tail -variable tiix_filter_tail -offvalue 0 -onvalue 1 -text "Tail"
ttk::checkbutton .tabbar.r.addrframe.c.rev -variable tiix_filter_rev -offvalue 0 -onvalue 1 -text "Reverse"
grid .tabbar.r.addrframe.c.aml -row 0 -column 0 -sticky nse
grid .tabbar.r.addrframe.c.amt -row 0 -column 1 -sticky w -padx 5
grid .tabbar.r.addrframe.c.rev -row 1 -column 0 -sticky nswe
grid .tabbar.r.addrframe.c.tail -row 1 -column 1 -sticky nswe
grid rowconfigure .tabbar.r.addrframe.c 0 -weight 1
grid rowconfigure .tabbar.r.addrframe.c 1 -weight 1
ttk::label .tabbar.r.addrframe.f.rg -text "Filter regex"
ttk::label .tabbar.r.addrframe.f.rg -text "Search filter"
ttk::entry .tabbar.r.addrframe.f.rgx -textvariable tiix_filter_regex -width 25
ttk::button .tabbar.r.addrframe.go -text "Read messages" -command tiix_viewecho
ttk::button .tabbar.r.addrframe.f.fetchecho -text "Fetch this echo" -command {tiix_fetchecho $tiix_echoname}
@@ -300,7 +265,9 @@ grid rowconfigure .tabbar.r 1 -weight 1
ttk::frame .tabbar.p.addrframe
ttk::label .tabbar.p.addrframe.el -text "Echo name"
ttk::combobox .tabbar.p.addrframe.echo -width 25 -textvariable tiix_post_echoname -postcommand {
set echonames [lsort [glob -tails -directory $echodir -nocomplain -types f "*.*"]]
sqlite3 msgdb $localdb -readonly true
set echonames [msgdb eval {SELECT DISTINCT `echoname` FROM `msg` ORDER BY `echoname`;}]
msgdb close
.tabbar.p.addrframe.echo config -values $echonames
}
ttk::label .tabbar.p.addrframe.stlbl -text "Station "