migrated tiiview and tiix to sqlite3
This commit is contained in:
@@ -32,8 +32,8 @@ Readiness status
|
|||||||
* config.txt (format/fields): ready/tested
|
* config.txt (format/fields): ready/tested
|
||||||
* stations.txt (format): ready/tested
|
* stations.txt (format): ready/tested
|
||||||
* auth.txt (format): ready/tested
|
* auth.txt (format): ready/tested
|
||||||
* tiix.tcl: work in progress
|
* tiix.tcl: ready/testing
|
||||||
* Overall status: CLI-ready. work in progress for GUI
|
* Overall status: basically ready, bugfixing in progress
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ if {$echoname eq ""} { # list the echonames
|
|||||||
}
|
}
|
||||||
puts "Subj: $msg(subj)"
|
puts "Subj: $msg(subj)"
|
||||||
puts $hdrline
|
puts $hdrline
|
||||||
|
set msg(body) [lmap s $msg(body) {string trimright $s}]
|
||||||
puts "[tiiflow $msg(body) $twidth]\n\n$globalline\n"
|
puts "[tiiflow $msg(body) $twidth]\n\n$globalline\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#!/usr/bin/env tclsh
|
#!/usr/bin/env tclsh
|
||||||
# tiix: GUI client for ii/idec networks that leverages capabilities
|
# tiix: GUI client for ii/idec networks that leverages capabilities
|
||||||
# of tiifetch and tiipost and repimplements the tiiview functionality
|
# 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
|
# Created by Luxferre in 2024, released into public domain
|
||||||
|
|
||||||
package require Tk
|
package require Tk
|
||||||
|
package require sqlite3
|
||||||
|
|
||||||
set scriptpath [file normalize [info script]]
|
set scriptpath [file normalize [info script]]
|
||||||
set appdir [file dirname $scriptpath]
|
set appdir [file dirname $scriptpath]
|
||||||
@@ -79,10 +80,8 @@ if {[file exists $authfile]} {
|
|||||||
set authmap [readfile $authfile]
|
set authmap [readfile $authfile]
|
||||||
}
|
}
|
||||||
|
|
||||||
# get the local DB directory path
|
# get the local DB file path
|
||||||
set localdbdir [file join $appdir "tiidb"]
|
set localdb [file join $appdir "tii.db"]
|
||||||
set msgdir [file join $localdbdir "msg"]
|
|
||||||
set echodir [file join $localdbdir "echo"]
|
|
||||||
|
|
||||||
# set default GUI parameters
|
# set default GUI parameters
|
||||||
|
|
||||||
@@ -95,7 +94,6 @@ set tiix_post_repto ""
|
|||||||
set tiix_filter_num 0
|
set tiix_filter_num 0
|
||||||
set tiix_filter_regex ""
|
set tiix_filter_regex ""
|
||||||
set tiix_filter_rev 0
|
set tiix_filter_rev 0
|
||||||
set tiix_filter_tail 0
|
|
||||||
set tiix_status Ready
|
set tiix_status Ready
|
||||||
set tiix_entry 0
|
set tiix_entry 0
|
||||||
|
|
||||||
@@ -126,84 +124,51 @@ proc linkinsert {textw uri is_orig} {
|
|||||||
lappend linklist $uri
|
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 {} {
|
proc tiix_viewecho {} {
|
||||||
global echodir msgdir linkcount tiix_echoname
|
global localdb linkcount tiix_echoname
|
||||||
global tiix_filter_num tiix_filter_regex tiix_filter_rev tiix_filter_tail
|
global tiix_filter_num tiix_filter_regex tiix_filter_rev
|
||||||
if {$tiix_echoname eq ""} {
|
if {$tiix_echoname eq ""} {
|
||||||
errmsg "Please select an echo conference to read!"
|
errmsg "Please select an echo conference to read!"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
set echofile [file join $echodir $tiix_echoname]
|
# open the message db
|
||||||
set msglist [split [readfile $echofile] "\n"]
|
sqlite3 msgdb $localdb -readonly true
|
||||||
set numitems $tiix_filter_num
|
set query {SELECT * FROM `msg` WHERE `echoname` = $tiix_echoname}
|
||||||
# perform the element filtering
|
if {$tiix_filter_regex ne {}} {
|
||||||
if {$numitems > 0} {
|
append query { AND (`body` LIKE $tiix_filter_regex OR `subj` LIKE $tiix_filter_regex) }
|
||||||
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]
|
|
||||||
}
|
}
|
||||||
|
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
|
set textw .tabbar.r.content.text
|
||||||
$textw configure -state normal
|
$textw configure -state normal
|
||||||
$textw delete 1.0 end
|
$textw delete 1.0 end
|
||||||
set linkcount 0
|
set linkcount 0
|
||||||
set linklist ""
|
set linklist ""
|
||||||
foreach msgid $msglist { # iterate over the list after filtering
|
msgdb eval $query msg { # iterate over the list after filtering
|
||||||
set msgid [string trim $msgid]
|
set globalline [string repeat = 80]
|
||||||
if {$msgid ne ""} {
|
set hdrline [string repeat - 80]
|
||||||
set msgfile [file join $msgdir $msgid]
|
set tz ""
|
||||||
if {[file exists $msgfile]} {
|
set renderedts ""
|
||||||
set msgdata [readfile $msgfile]
|
catch { # because some servers don't provide timestamps
|
||||||
set pass 1
|
set renderedts [clock format $msg(timestamp) -format {%Y-%m-%d %H:%M:%S} -timezone $tz]
|
||||||
if {$tiix_filter_regex ne {}} {
|
|
||||||
set pass [regexp -line -nocase -- $tiix_filter_regex $msgdata]
|
|
||||||
}
|
|
||||||
if {$pass eq 1} {tiix_formatmessage $msgdata $msgid}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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
|
$textw configure -state disabled
|
||||||
|
# close the message db
|
||||||
|
msgdb close
|
||||||
}
|
}
|
||||||
|
|
||||||
# fetcher frontend
|
# fetcher frontend
|
||||||
@@ -216,9 +181,9 @@ proc tiix_fetchecho {echoname} {
|
|||||||
no {return}
|
no {return}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
global tiix_status localdbdir
|
global tiix_status localdb
|
||||||
set tiix_status "Fetching echo contents..."
|
set tiix_status "Fetching echo contents..."
|
||||||
massfetch $echoname $localdbdir 0
|
massfetch $echoname $localdb 0
|
||||||
set tiix_status Ready
|
set tiix_status Ready
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,20 +217,20 @@ ttk::frame .tabbar.r.addrframe.f
|
|||||||
ttk::frame .tabbar.r.addrframe.c
|
ttk::frame .tabbar.r.addrframe.c
|
||||||
ttk::label .tabbar.r.addrframe.f.el -text "Echo name"
|
ttk::label .tabbar.r.addrframe.f.el -text "Echo name"
|
||||||
ttk::combobox .tabbar.r.addrframe.f.echo -width 25 -textvariable tiix_echoname -postcommand {
|
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
|
.tabbar.r.addrframe.f.echo config -values $echonames
|
||||||
}
|
}
|
||||||
ttk::label .tabbar.r.addrframe.c.aml -text "# Messages:"
|
ttk::label .tabbar.r.addrframe.c.aml -text "# Messages:"
|
||||||
ttk::entry .tabbar.r.addrframe.c.amt -textvariable tiix_filter_num -width 8
|
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"
|
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.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.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.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 0 -weight 1
|
||||||
grid rowconfigure .tabbar.r.addrframe.c 1 -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::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.go -text "Read messages" -command tiix_viewecho
|
||||||
ttk::button .tabbar.r.addrframe.f.fetchecho -text "Fetch this echo" -command {tiix_fetchecho $tiix_echoname}
|
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::frame .tabbar.p.addrframe
|
||||||
ttk::label .tabbar.p.addrframe.el -text "Echo name"
|
ttk::label .tabbar.p.addrframe.el -text "Echo name"
|
||||||
ttk::combobox .tabbar.p.addrframe.echo -width 25 -textvariable tiix_post_echoname -postcommand {
|
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
|
.tabbar.p.addrframe.echo config -values $echonames
|
||||||
}
|
}
|
||||||
ttk::label .tabbar.p.addrframe.stlbl -text "Station "
|
ttk::label .tabbar.p.addrframe.stlbl -text "Station "
|
||||||
|
|||||||
Reference in New Issue
Block a user