1 # vim: ft=tcl foldmethod=marker foldmarker=<<<,>>> ts=4 shiftwidth=4
6 constructor
{backend
info args
} {}
11 method
load {path
{inherited
{}} {datatypes
{}} {inh_info
{}}}
12 method load_only
{path
}
14 method listsub
{path
{immediate
0}}
15 method save
{path configlist
{datatype_list
""}}
17 method
rename {frompath topath
{allsub
0}}
29 body tlc
::Hconfig::constructor {backend
info args
} { #<<<1
35 foreach {sql_obj table
} $info break
36 log debug
"sql_obj: ($sql_obj) ($table)"
40 error "Unsupported backend: ($backend)" "" \
41 [list invalid_backend
$backend]
49 body tlc
::Hconfig::init_db {} { #<<<1
51 if {![$sql_obj table_exists
$table]} {
55 path text unique not null,
58 datatypes text default ''
62 create index ${table}_path_idx on ${table}(path);
68 body tlc
::Hconfig::load {path
{inherited
{}} {datatypes
{}} {inh_info
{}}} { #<<<1
70 set path
[string trim
$path "/ "]
72 if {$inherited != {}} {
75 if {$datatypes != {}} {
79 if {$inh_info != {}} {
80 upvar $inh_info inh_inf
90 # Initialize from root "" <<<
91 set rows
[$sql_obj getlist
"
101 set real
[expr {[llength $rows] == 1}]
102 set raw
[lindex $rows 0]
103 set last
[lindex $raw 0]
104 set leaf
[lindex $raw 1]
105 set types
[lindex $raw 2]
107 #log debug "path: ($p) data: ($last)"
108 array set build
$last
110 # look for this variable's data type in the (should be a list) types var
111 # the default type is text, so if the variable is not found in the types list
112 # then we set to that
113 foreach {idx val
} $last {
118 set inh_inf
(parent
) [array get build
]
119 set inh_inf
(this
) $last
120 set inh_inf
(parent_dt
) [array get dt
]
121 set inh_inf
(this_dt
) $types
122 # Initialize from root "" >>>
124 foreach elem
[split $path /] {
126 set rows
[$sql_obj getlist
"
134 path = '[$sql_obj quote $p]'
136 set real
[expr {[llength $rows] == 1}]
137 set raw
[lindex $rows 0]
138 set last
[lindex $raw 0]
139 set leaf
[lindex $raw 1]
140 set types
[lindex $raw 2]
142 set inh_inf
(parent
) [array get build
]
143 set inh_inf
(this
) $last
144 set inh_inf
(parent_dt
) [array get dt
]
145 set inh_inf
(this_dt
) $types
148 foreach {key val
} $last {
149 if {![info exists dt
($key)]} {
152 switch -- $dt($key) {
154 log debug
"Compositing mergelist: $p, $key, $val"
158 if {![info exists build
($key)]} {
163 switch -- [string index
$item 0] {
165 lappend chopitems
[string range
$item 1 end
]
169 lappend newitems
[string range
$item 1 end
]
173 lappend newitems
$item
179 [lindex [tlc
::intersect3 $build($key) $chopitems] 0]
181 [lsort -unique [concat $chopped $newitems]]
186 log debug
"Compositing mergelist: $p, $key, $val"
191 if {![info exists build
($key)]} {
194 array set tmparr
$build($key)
197 foreach {skey sval
} $val {
198 switch -- [string index
$skey 0] {
200 lappend chopitems
[string range
$skey 1 end
]
205 [string range
$skey 1 end
] \
210 lappend newitems
$skey $sval
215 foreach chopitem
$chopitems {
216 array unset tmparr
$chopitem
218 foreach {skey sval
} $newitems {
219 set tmparr
($skey) $sval
235 if {$leaf == 1} break
237 if {$exact && (($p != $path) ||
!$real)} {
238 error "path not found: ($path) exact: ($exact)" "" \
239 [list not_found
$path]
242 foreach name
[array names build
] {
245 foreach {name value
} $last {
249 return [array get build
]
253 body tlc
::Hconfig::load_only {path
} { #<<<1
255 set path
[string trim
$path "/ "]
264 foreach elem
[split $path /] {
266 set rows
[$sql_obj getlist
"
273 path = '[$sql_obj quote $p]'
275 set real
[expr {[llength $rows] == 1}]
276 set raw
[lindex $rows 0]
277 set last
[lindex $raw 0]
278 set leaf
[lindex $raw 1]
280 if {$leaf == 1} break
282 if {$exact && (($p != $path) ||
!$real)} {
283 error "path not found: ($path) exact: ($exact)" "" \
284 [list path_not_found
$path]
286 array set build
$last
288 return [array get build
]
292 body tlc
::Hconfig::exists {path
} { #<<<1
294 set path
[string trim
$path "/ "]
296 set count
[lindex [lindex [$sql_obj getlist
"
302 path = '[$sql_obj quote $path]'
305 return [expr {$count > 0}]
309 body tlc
::Hconfig::save {path configlist
{datatype_list
""}} { #<<<1
311 set path
[string trim
$path "/ "]
313 if {[catch {array set test
$configlist}]} {
314 error "Badly formatted configlist. Should be result of array get" "" \
318 set id
[lindex [lindex [$sql_obj getlist
"
324 path = '[$sql_obj quote $path]'
334 '[$sql_obj quote $path]',
335 '[$sql_obj quote $configlist]',
336 '[$sql_obj quote $datatype_list]'
340 set row
[lindex [$sql_obj getlist
"
347 path = '[$sql_obj quote $path]'
349 array set build
[lindex $row 0]
350 array set datatypes
[lindex $row 1]
351 array set build
$configlist
352 array set datatypes
$datatype_list
357 data = '[$sql_obj quote [array get build]]',
358 datatypes = '[$sql_obj quote [array get datatypes]]'
360 path = '[$sql_obj quote $path]'
366 body tlc
::Hconfig::trash {path
} { #<<<1
368 set path
[string trim
$path "/ "]
374 path = '[$sql_obj quote $path]'
379 body tlc
::Hconfig::rename {frompath topath
{allsub
0}} { #<<<1
381 set frompath
[string trim
$frompath "/ "]
382 set topath
[string trim
$topath "/ "]
389 path = '[$sql_obj quote $topath]'
391 path = '[$sql_obj quote $frompath]'
394 set subs
[listsub
$frompath 0]
395 $sql_obj getlist
"begin"
397 set from
[join [list $frompath $sub] /]
398 set to
[join [list $topath $sub] /]
403 path = '[$sql_obj quote $to]'
405 path = '[$sql_obj quote $from]'
413 path = '[$sql_obj quote $topath]'
415 path = '[$sql_obj quote $frompath]'
417 $sql_obj getlist
"commit"
422 body tlc
::Hconfig::listsub {path
{immediate
0}} { #<<<1
424 set path
[string trim
$path "/ "]
425 #log debug "listsub of ($path) ($immediate)"
432 set speclen
[string length
$spec]
435 set rows
[$sql_obj getlist
"
441 path like '[$sql_obj quote ${spec}%]'
450 # path like '${spec}%'
454 set subpath
[lindex $row 0]
455 set subpath
[string range
$subpath $speclen end
]
457 if {$subpath == ""} continue
460 set trimpoint
[string first
"/" $subpath]
461 if {$trimpoint == -1} {
462 #log debug "($subpath): no \"/\" - appending as is"
463 lappend build
$subpath
466 #log debug "($subpath): \"/\" at $trimpoint appending ([string range $subpath 0 $trimpoint])"
467 lappend build
[string range
$subpath 0 $trimpoint]
470 lappend build
$subpath
475 set build
[lsort -unique $build]