| 1 | # bMotion: admin plugin file for abstracts |
|---|
| 2 | # |
|---|
| 3 | # $Id$ |
|---|
| 4 | # |
|---|
| 5 | |
|---|
| 6 | ############################################################################### |
|---|
| 7 | # This is a bMotion plugin |
|---|
| 8 | # Copyright (C) James Michael Seward 2000-2002 |
|---|
| 9 | # |
|---|
| 10 | # This program is covered by the GPL, please refer the to LICENCE file in the |
|---|
| 11 | # distribution; further information can be found in the headers of the scripts |
|---|
| 12 | # in the modules directory. |
|---|
| 13 | ############################################################################### |
|---|
| 14 | |
|---|
| 15 | proc bMotion_plugin_admin_abstract { handle { arg "" }} { |
|---|
| 16 | |
|---|
| 17 | #abstract show <name> |
|---|
| 18 | if [regexp -nocase {show ([^ ]+)} $arg matches name] { |
|---|
| 19 | set result [bMotion_abstract_all $name] |
|---|
| 20 | bMotion_putadmin "Abstract $name has [llength $result] items." |
|---|
| 21 | set i 0 |
|---|
| 22 | foreach a $result { |
|---|
| 23 | bMotion_putadmin "$i: $a" |
|---|
| 24 | incr i |
|---|
| 25 | } |
|---|
| 26 | return 0 |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | #abstract gc |
|---|
| 30 | if [regexp -nocase {gc} $arg matches] { |
|---|
| 31 | bMotion_putadmin "Garbage collecting..." |
|---|
| 32 | bMotion_abstract_gc |
|---|
| 33 | return 0 |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | #status |
|---|
| 37 | if [regexp -nocase {status} $arg] { |
|---|
| 38 | global bMotion_abstract_contents bMotion_abstract_timestamps bMotion_abstract_max_age |
|---|
| 39 | global bMotion_abstract_ondisk |
|---|
| 40 | |
|---|
| 41 | set mem 0 |
|---|
| 42 | set disk 0 |
|---|
| 43 | |
|---|
| 44 | set handles [array names bMotion_abstract_contents] |
|---|
| 45 | bMotion_putadmin "bMotion abstract info info:\r" |
|---|
| 46 | foreach handle $handles { |
|---|
| 47 | set diff [expr [clock seconds]- $bMotion_abstract_timestamps($handle)] |
|---|
| 48 | bMotion_putadmin "$handle: [llength [bMotion_abstract_all $handle]] items, $diff seconds since used" |
|---|
| 49 | incr mem |
|---|
| 50 | } |
|---|
| 51 | foreach handle $bMotion_abstract_ondisk { |
|---|
| 52 | bMotion_putadmin "$handle: on disk" |
|---|
| 53 | incr disk |
|---|
| 54 | } |
|---|
| 55 | bMotion_putadmin "[expr $mem + $disk] total abstracts, $mem loaded, $disk on disk" |
|---|
| 56 | return 0 |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | if [regexp -nocase {info (.+)} $arg matches name] { |
|---|
| 60 | set result [bMotion_abstract_all $name] |
|---|
| 61 | bMotion_putadmin "Abstract $name has [llength $result] items.\r" |
|---|
| 62 | return 0 |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | if [regexp -nocase {delete (.+) (.+)} $arg matches name index] { |
|---|
| 66 | bMotion_putadmin "Deleting element $index from abstract $name...\r" |
|---|
| 67 | bMotion_abstract_delete $name $index |
|---|
| 68 | return 0 |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | if [regexp -nocase {purge ([^ ]+) (.+)} $arg matches name re] { |
|---|
| 72 | bMotion_putadmin "Purging abstract $name for elements matching /$re/" |
|---|
| 73 | bMotion_abstract_filter $name $re |
|---|
| 74 | return 0 |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | if [regexp -nocase "flush" $arg] { |
|---|
| 78 | bMotion_abstract_flush |
|---|
| 79 | bMotion_putadmin "Flushing all abstracts to disk..." |
|---|
| 80 | return 0 |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | if [regexp -nocase "diagnose" $arg] { |
|---|
| 84 | bMotion_diagnostic_parsing |
|---|
| 85 | return 0 |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | if [regexp -nocase "reset (.+)" $arg matches name] { |
|---|
| 89 | bMotion_putadmin "Removing all entries from $name" |
|---|
| 90 | bMotion_abstract_reset $name |
|---|
| 91 | return 0 |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | if [regexp -nocase "filter (\[a-z\]+)( (\[^ \]+)( .+)?)?" $arg matches cmd parms abstract filter] { |
|---|
| 95 | switch $cmd { |
|---|
| 96 | "list" { |
|---|
| 97 | global bMotion_abstract_filters |
|---|
| 98 | set filternames [array names bMotion_abstract_filters] |
|---|
| 99 | foreach f $filternames { |
|---|
| 100 | if {$f == "dummy"} { |
|---|
| 101 | continue |
|---|
| 102 | } |
|---|
| 103 | bMotion_putadmin "$f: $bMotion_abstract_filters($f)" |
|---|
| 104 | } |
|---|
| 105 | return |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | "purge" { |
|---|
| 109 | bMotion_abstract_flush_filters |
|---|
| 110 | bMotion_putadmin "Flushed all filters." |
|---|
| 111 | return |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | "add" { |
|---|
| 115 | if {$abstract == ""} { |
|---|
| 116 | bMotion_putadmin "Missing abstract" |
|---|
| 117 | return |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | if {$filter == ""} { |
|---|
| 121 | bMotion_putadmin "Missing filter" |
|---|
| 122 | return |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | set filter [string trim $filter] |
|---|
| 126 | |
|---|
| 127 | bMotion_abstract_add_filter $abstract $filter |
|---|
| 128 | bMotion_putadmin "Added filter /$filter/ for abstract $abstract" |
|---|
| 129 | return |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | "apply" { |
|---|
| 133 | if {$abstract == ""} { |
|---|
| 134 | bMotion_putadmin "Missing abstract name" |
|---|
| 135 | return |
|---|
| 136 | } |
|---|
| 137 | bMotion_putadmin "Applying filter for $abstract (if one exists)" |
|---|
| 138 | bMotion_abstract_apply_filter $abstract |
|---|
| 139 | return |
|---|
| 140 | } |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | #all else fails, list help |
|---|
| 145 | bMotion_putadmin "Try .bmotion help abstract" |
|---|
| 146 | return 0 |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | proc bMotion_plugin_admin_abstract_help { } { |
|---|
| 150 | bMotion_putadmin "Manage abstracts in bMotion." |
|---|
| 151 | bMotion_putadmin " .bmotion abstract info <abstract>" |
|---|
| 152 | bMotion_putadmin " Find out info about an abstract" |
|---|
| 153 | bMotion_putadmin " .bmotion abstract show <abstract>" |
|---|
| 154 | bMotion_putadmin " List the contents of an abstract (Potentially much output!)" |
|---|
| 155 | bMotion_putadmin " .bmotion abstract gc" |
|---|
| 156 | bMotion_putadmin " Force a garbage collection of abstracts (pages out unused ones)" |
|---|
| 157 | bMotion_putadmin " .bmotion abstract status" |
|---|
| 158 | bMotion_putadmin " List all abstracts and their status (Much ouput!)" |
|---|
| 159 | bMotion_putadmin " .bmotion abstract delete <abstract> <index>" |
|---|
| 160 | bMotion_putadmin " Delete an element from an abstract" |
|---|
| 161 | bMotion_putadmin " Index is 0-based; use the show command to find entries" |
|---|
| 162 | bMotion_putadmin " .bmotion abstract purge <abstract> <regexp>" |
|---|
| 163 | bMotion_putadmin " Remove all matching elements from an abstract (dangerous)" |
|---|
| 164 | bMotion_putadmin " .bmotion abstract flush" |
|---|
| 165 | bMotion_putadmin " Force all abstracts to be flushed to disk" |
|---|
| 166 | bMotion_putadmin " .bmotion abstract filter add <abstract> <regexp>" |
|---|
| 167 | bMotion_putadmin " Add a filter to an abstract" |
|---|
| 168 | bMotion_putadmin " .bmotion abstract filter list" |
|---|
| 169 | bMotion_putadmin " List all abstract filters" |
|---|
| 170 | bMotion_putadmin " .bmotion abstract filter purge" |
|---|
| 171 | bMotion_putadmin " Purge all filters" |
|---|
| 172 | bMotion_putadmin " .bmotion abstract filter apply <abstract>" |
|---|
| 173 | bMotion_putadmin " For an abstract to be filtered now" |
|---|
| 174 | bMotion_putadmin " .bmotion abstract diagnose" |
|---|
| 175 | bMotion_putadmin " Test all abstracts for parsability and report any broken ones" |
|---|
| 176 | bMotion_putadmin " .bmotion abstract reset <abstract>" |
|---|
| 177 | bMotion_putadmin " Remove everything from an abstract and save it" |
|---|
| 178 | return 0 |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | # register the plugin |
|---|
| 183 | bMotion_plugin_add_management "abstract" "^abstract" n "bMotion_plugin_admin_abstract" "any" "bMotion_plugin_admin_abstract_help" |
|---|