Changeset 461
- Timestamp:
- 03/29/04 13:38:44 (8 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 1 deleted
- 8 edited
-
bMotion.tcl (modified) (1 diff)
-
modules/abstract.tcl (modified) (14 diffs)
-
modules/abstracts (added)
-
modules/abstracts.tcl (deleted)
-
modules/abstracts/en (added)
-
modules/abstracts/en/abstracts.tcl (added)
-
plugins/action_complex.tcl (modified) (2 diffs)
-
plugins/admin.tcl (modified) (2 diffs)
-
plugins/admin_language.tcl (modified) (3 diffs)
-
plugins/complex.tcl (modified) (2 diffs)
-
plugins/irc_event.tcl (modified) (2 diffs)
-
plugins/simple.tcl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bMotion.tcl
r460 r461 83 83 source "$bMotionModules/abstract.tcl" 84 84 85 # load abstracts file (formerly randoms)86 if {$bMotion_testing == 1} {87 putlog "... loading abstracts"88 }89 source "$bMotionModules/abstracts.tcl"90 91 85 # load settings 92 86 if {$bMotion_testing == 1} { -
trunk/modules/abstract.tcl
r460 r461 65 65 # NOTE: This module should be loaded before plugins as they will need it to register abstracts 66 66 # 67 # The abstracts will be stored in ./abstracts/< abstract name>.txt in the bMotion directory. The67 # The abstracts will be stored in ./abstracts/<language>/<abstract name>.txt in the bMotion directory. The 68 68 # fileformat is simply one per line. 69 69 … … 76 76 if {![info exists bMotion_abstract_contents]} { 77 77 set bMotion_abstract_contents(dummy) "" 78 set bMotion_abstract_languages(dummy) "en" 78 79 set bMotion_abstract_timestamps(dummy) 1 79 80 set bMotion_abstract_ondisk [list] … … 90 91 global bMotion_abstract_contents bMotion_abstract_timestamps 91 92 global bMotion_abstract_max_age bMotion_abstract_ondisk 93 global bMotionInfo bMotion_abstract_languages 94 set lang $bMotionInfo(language) 92 95 93 96 bMotion_putloglev 2 * "Garbage collecting abstracts..." … … 102 105 103 106 foreach abstract $abstracts { 104 if {($bMotion_abstract_timestamps($abstract) < $limit) && ($bMotion_abstract_timestamps($abstract) > 0) } {107 if {($bMotion_abstract_timestamps($abstract) < $limit) && ($bMotion_abstract_timestamps($abstract) > 0) || $bMotion_abstract_languages($abstract) != $lang } { 105 108 append expiredList "$abstract " 106 109 incr expiredCount 107 110 unset bMotion_abstract_contents($abstract) 111 unset bMotion_abstract_languages($abstract) 108 112 set bMotion_abstract_timestamps($abstract) 0 109 113 lappend bMotion_abstract_ondisk $abstract … … 121 125 global bMotion_abstract_contents bMotion_abstract_timestamps 122 126 global bMotionModules bMotion_testing bMotion_loading 127 global bMotionInfo bMotion_abstract_languages 123 128 124 129 #set timestamp to now 125 130 set bMotion_abstract_timestamps($abstract) [clock seconds] 131 set lang $bMotionInfo(language) 126 132 127 133 #load any existing abstracts 128 if [file exists "[pwd]/$bMotionModules/abstracts/$ {abstract}.txt"] {134 if [file exists "[pwd]/$bMotionModules/abstracts/$lang/${abstract}.txt"] { 129 135 bMotion_abstract_load $abstract 130 136 } else { 137 # check that the language directory exists while we're at it 138 set dir "$bMotionModules/abstracts/$lang" 139 if { ![file exists $dir] } { 140 [file mkdir "$bMotionModules/abstracts/$lang"] 141 } 131 142 #file doesn't exist - create an empty one 132 143 #create blank array for it 133 144 set bMotion_abstract_contents($abstract) [list] 145 set bMotion_abstract_languages($abstract) "$lang" 134 146 bMotion_putloglev 1 * "Creating new abstract file for $abstract" 135 set fileHandle [open "[pwd]/$bMotionModules/abstracts/$ {abstract}.txt" "w"]147 set fileHandle [open "[pwd]/$bMotionModules/abstracts/$lang/${abstract}.txt" "w"] 136 148 puts $fileHandle " " 137 149 } … … 146 158 global bMotionModules bMotion_abstract_ondisk 147 159 global bMotion_loading bMotion_testing 148 149 bMotion_putloglev 1 * "Attempting to load $bMotionModules/abstracts/${abstract}.txt" 150 151 if {![file exists "$bMotionModules/abstracts/${abstract}.txt"]} { 160 global bMotionInfo bMotion_abstract_languages 161 set lang $bMotionInfo(language) 162 163 bMotion_putloglev 1 * "Attempting to load $bMotionModules/abstracts/$lang/${abstract}.txt" 164 165 if {![file exists "$bMotionModules/abstracts/$lang/${abstract}.txt"]} { 152 166 return 153 167 } … … 155 169 #create blank array for it 156 170 set bMotion_abstract_contents($abstract) [list] 171 set bMotion_abstract_languages($abstract) "$lang" 157 172 158 173 #set timestamp to now … … 167 182 set bMotion_abstract_ondisk [lreplace $bMotion_abstract_ondisk $index $index] 168 183 169 set fileHandle [open "$bMotionModules/abstracts/$ {abstract}.txt" "r"]184 set fileHandle [open "$bMotionModules/abstracts/$lang/${abstract}.txt" "r"] 170 185 set line [gets $fileHandle] 171 186 set needReSave 0 … … 200 215 proc bMotion_abstract_add { abstract text {save 1} } { 201 216 global bMotion_abstract_contents bMotion_abstract_timestamps bMotion_abstract_max_age 202 global bMotionModules 217 global bMotionModules bMotionInfo 218 set lang $bMotionInfo(language) 203 219 204 220 bMotion_putloglev 2 * "Adding '$text' to abstract '$abstract'" … … 212 228 bMotion_putloglev 2 * "updating abstracts '$abstract' on disk" 213 229 if {$save} { 214 set fileHandle [open "[pwd]/$bMotionModules/abstracts/$ {abstract}.txt" "a+"]230 set fileHandle [open "[pwd]/$bMotionModules/abstracts/$lang/${abstract}.txt" "a+"] 215 231 puts $fileHandle $text 216 232 close $fileHandle … … 223 239 if {$save} { 224 240 bMotion_putloglev 2 * "updating abstracts '$abstract' on disk and in memory" 225 set fileHandle [open "[pwd]/$bMotionModules/abstracts/$ {abstract}.txt" "a+"]241 set fileHandle [open "[pwd]/$bMotionModules/abstracts/$lang/${abstract}.txt" "a+"] 226 242 puts $fileHandle $text 227 243 close $fileHandle … … 233 249 global bMotion_abstract_contents 234 250 global bMotionModules bMotion_testing bMotion_loading 235 global bMotion_abstract_max_number 251 global bMotion_abstract_max_number bMotionInfo bMotion_abstract_languages 252 set lang $bMotionInfo(language) 253 254 if {$lang != $bMotion_abstract_languages($abstract) } { 255 bMotion_putloglev 1 * "Did not save '$abstract' to disk (wrong language)" 256 return 0 257 } 236 258 237 259 set tidy 0 … … 246 268 bMotion_putloglev 1 * "Saving abstracts '$abstract' to disk" 247 269 248 set fileHandle [open "[pwd]/$bMotionModules/abstracts/$ {abstract}.txt" "w"]270 set fileHandle [open "[pwd]/$bMotionModules/abstracts/$lang/${abstract}.txt" "w"] 249 271 set number [llength $bMotion_abstract_contents($abstract)] 250 272 if {$number > $bMotion_abstract_max_number} { … … 320 342 } 321 343 344 # flush all of the abstracts to disk 345 # this was created for changing languages on the fly. If you're using this 346 # for some other reason, then you might want to be sure. 347 proc bMotion_abstract_flush { } { 348 global bMotionInfo bMotion_abstract_contents 349 global bMotion_abstract_languages 350 set lang $bMotionInfo(language) 351 set abstracts [array names bMotion_abstract_contents] 352 foreach abstract $abstracts { 353 set storedLang $bMotion_abstract_languages($abstract) 354 if { $abstract != "dummy" && $storedLang == $lang } { 355 bMotion_abstract_save $abstract 356 unset bMotion_abstract_contents($abstract) 357 unset bMotion_abstract_languages($abstract) 358 } 359 } 360 set bMotion_abstract_contents(dummy) "" 361 set bMotion_abstract_languages(dummy) "" 362 set bMotion_abstract_timestamps(dummy) 1 363 set bMotion_abstract_ondisk [list] 364 } 365 366 # this loads language abstracts for the current language in bMotionInfo 367 proc bMotion_abstract_revive_language { } { 368 global bMotionSettings bMotionInfo bMotionModules 369 global bMotion_abstract_contents 370 371 set lang $bMotionInfo(language) 372 373 bMotion_putloglev 2 * "bMotion: reviving language ($lang) abstracts" 374 set languages [split $bMotionSettings(languages) ","] 375 # just check if it's ok to use this language 376 set ok 0 377 foreach language $languages { 378 if { $lang == $language } { 379 set ok 1 380 } 381 } 382 if { $ok != 1 } { 383 bMotion_putloglev 2 * "bMotion: language not found, cannot revive" 384 return -1 385 } 386 # if the default abstracts exists, use it first 387 if { [file exists "$bMotionModules/abstracts/$lang/abstracts.tcl"] } { 388 catch { 389 source "$bMotionModules/abstracts/$lang/abstracts.tcl" 390 } 391 } else { 392 bMotion_putloglev 2 * "bMotion: language default abstracts not found" 393 } 394 # then we need to load any others 395 set files [glob -nocomplain "$bMotionModules/abstracts/$lang/*.txt"] 396 if { [llength $files] == 0} { 397 return 0 398 } 399 foreach f $files { 400 set pos [expr [string last "/" $f] + 1] 401 set dot [expr [string last ".txt" $f] - 1] 402 set abstract [string range $f $pos $dot] 403 bMotion_putloglev 2 * "checking $abstract" 404 set len 0 405 catch { set len [llength $bMotion_abstract_contents($abstract)] } val 406 if { $val != "$len" } { 407 bMotion_abstract_load $abstract 408 } 409 } 410 } 411 412 # this is to update people from the old abstracts to the new abstracts. 413 # it only needs to be run once, and should be removed afterwards 414 proc bMotion_abstract_check { } { 415 global bMotionInfo bMotionModules 416 set lang $bMotionInfo(language) 417 set dir "$bMotionModules/abstracts/$lang" 418 if { ![file exists $dir] } { 419 [file mkdir $dir] 420 } 421 set files [glob -nocomplain "$bMotionModules/abstracts/*.txt"] 422 if { [llength $files] == 0} { 423 return 0 424 } 425 foreach f $files { 426 catch { 427 [file rename -force -- $f "${dir}/"] 428 } 429 } 430 } 431 322 432 bind time - "* * * * *" bMotion_abstract_auto_gc 433 434 # the check has to be run to update old systems 435 bMotion_abstract_check 436 # we have to revive at least one language 437 bMotion_abstract_revive_language -
trunk/plugins/action_complex.tcl
r460 r461 13 13 ############################################################################### 14 14 15 set currentlang $bMotionInfo(language) 15 16 set languages [split $bMotionSettings(languages) ","] 16 17 foreach language $languages { 18 set bMotionInfo(language) $language 17 19 bMotion_putloglev 2 * "bMotion: loading complex action plugins language = $language" 18 20 set files [glob -nocomplain "$bMotionPlugins/$language/action_complex_*.tcl"] … … 24 26 } 25 27 } 28 set bMotionInfo(language) $currentlang 29 unset currentlang -
trunk/plugins/admin.tcl
r460 r461 13 13 ############################################################################### 14 14 15 set currentlang $bMotionInfo(language) 15 16 set languages [split $bMotionSettings(languages) ","] 16 17 foreach language $languages { 18 set bMotionInfo(language) $language 17 19 bMotion_putloglev 2 * "bMotion: loading admin plugins language = $language" 18 20 set files [glob -nocomplain "$bMotionPlugins/$language/admin_*.tcl"] … … 24 26 } 25 27 } 28 set bMotionInfo(language) $currentlang 29 unset currentlang 26 30 27 31 # load default admin stuff regardless -
trunk/plugins/admin_language.tcl
r460 r461 15 15 proc bMotion_plugin_management_language { handle { arg "" }} { 16 16 global bMotionSettings 17 global bMotionInfo 17 18 18 19 if [regexp -nocase {remove (.+)} $arg matches lang] { 20 if { $lang == $bMotionInfo(language) } { 21 bMotion_putadmin "Cannot remove current language" 22 return 0 23 } 19 24 bMotion_putadmin "Removing language $lang..." 20 25 set langs [split $bMotionSettings(languages) ","] … … 39 44 40 45 if [regexp -nocase {add (.+)} $arg matches lang] { 46 set langs [split $bMotionSettings(languages) ","] 47 foreach language $langs { 48 if {$lang == $language} { 49 bMotion_putadmin "Cannot add language already in list" 50 return 0 51 } 52 } 41 53 bMotion_putadmin "Adding language $lang..." 42 54 append bMotionSettings(languages) ",$lang" … … 48 60 bMotion_putadmin "Switching languages to $lang..." 49 61 if [regexp $lang $bMotionSettings(languages)] { 50 global bMotionInfo 62 # step 1: flush the abstracts 63 bMotion_abstract_flush 64 # step 2: change the language in info 51 65 set bMotionInfo(language) $lang 66 # step 3: load the new abstracts 67 bMotion_abstract_revive_language 52 68 } else { 53 69 bMotion_putadmin "Error! Language $lang not loaded" -
trunk/plugins/complex.tcl
r460 r461 13 13 ############################################################################### 14 14 15 set currentlang $bMotionInfo(language) 15 16 set languages [split $bMotionSettings(languages) ","] 16 17 foreach language $languages { 18 set bMotionInfo(language) $language 17 19 bMotion_putloglev 2 * "bMotion: loading complex plugins language = $language" 18 20 set files [glob -nocomplain "$bMotionPlugins/$language/complex_*.tcl"] … … 24 26 } 25 27 } 28 set bMotionInfo(language) $currentlang 29 unset currentlang -
trunk/plugins/irc_event.tcl
r460 r461 13 13 ############################################################################### 14 14 15 set currentlang $bMotionInfo(language) 15 16 set languages [split $bMotionSettings(languages) ","] 16 17 foreach language $languages { 18 set bMotionInfo(language) $language 17 19 bMotion_putloglev 2 * "bMotion: loading irc event plugins language = $language" 18 20 set files [glob -nocomplain "$bMotionPlugins/$language/irc_*.tcl"] … … 24 26 } 25 27 } 28 set bMotionInfo(language) $currentlang 29 unset currentlang -
trunk/plugins/simple.tcl
r460 r461 13 13 ############################################################################### 14 14 15 set currentlang $bMotionInfo(language) 15 16 set languages [split $bMotionSettings(languages) ","] 16 17 foreach language $languages { 18 set bMotionInfo(language) $language 17 19 bMotion_putloglev 2 * "bMotion: loading simple plugins language = $language" 18 20 set files [glob -nocomplain "$bMotionPlugins/$language/simple_*.tcl"] … … 24 26 } 25 27 } 28 set bMotionInfo(language) $currentlang 29 unset currentlang
Note: See TracChangeset
for help on using the changeset viewer.
