|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# Script to make entering and progressing issues easier. |
| 4 | +# |
| 5 | +# The issues are contained in an issues.db file, as a sequence of lines of |
| 6 | +# tab-separated fields: |
| 7 | +# |
| 8 | +# - one-line description |
| 9 | +# - resolution |
| 10 | +# - reference mail thread (preferrably a URL) |
| 11 | +# - raised on (date) |
| 12 | +# - resolved on (date) |
| 13 | +# - specification up-to-date? |
| 14 | +# - issue number |
| 15 | +# |
| 16 | + |
| 17 | +USAGE="issues-db <issues-db> <html-src>" |
| 18 | + |
| 19 | +if [ $# -ne 2 ] |
| 20 | +then |
| 21 | + echo $USAGE; exit 1; |
| 22 | +fi |
| 23 | + |
| 24 | +ISSUES=`dirname $0`/../$1; shift |
| 25 | +HTML=`dirname $0`/../$2; shift |
| 26 | +#DATEFRM="+%d %b %Y" |
| 27 | +DATEFRM="+%Y-%m-%d" |
| 28 | +TMP=${TMPDIR:-/tmp}/issue.$$ |
| 29 | +ARCH=`uname` |
| 30 | +PAGER=${PAGER:-more} |
| 31 | + |
| 32 | + |
| 33 | +pr () |
| 34 | +{ |
| 35 | + if [ $ARCH = "Linux" ]; then |
| 36 | + echo -e "$*" |
| 37 | + else |
| 38 | + echo "$*" |
| 39 | + fi |
| 40 | +} |
| 41 | + |
| 42 | +prn () |
| 43 | +{ |
| 44 | + if [ $ARCH = "Linux" ]; then |
| 45 | + echo -e "$* \c" |
| 46 | + else |
| 47 | + echo "$*\c" |
| 48 | + fi |
| 49 | +} |
| 50 | + |
| 51 | + |
| 52 | +quick_help () |
| 53 | +{ |
| 54 | + pr |
| 55 | + pr "\tThis program updates $ISSUES and $HTML" |
| 56 | + pr |
| 57 | + pr "\tTo see the issues (plain text): issues -l" |
| 58 | + pr "\tTo see the issues (HTML table): issues -g" |
| 59 | + pr "\tTo see the unresolved issues: issues -t" |
| 60 | + pr "\tTo see issues yet to be updated: issues -y" |
| 61 | + pr "\tTo enter a new issue: issues -a [reference [description]]" |
| 62 | + pr "\tTo resolve an issue: issues -r [number [resolution-text]]" |
| 63 | + pr "\tTo mark the spec as up-to-date: issues -u [number]" |
| 64 | + pr "\tTo be prompted for all arguments: issue" |
| 65 | + pr "\tTo get quick help: issues -?" |
| 66 | + pr |
| 67 | + pr "\tYou'll be prompted for all missing arguments" |
| 68 | + pr |
| 69 | +} |
| 70 | + |
| 71 | +list_issues () |
| 72 | +{ |
| 73 | + ( |
| 74 | + IFS=' ' |
| 75 | + #num=0 |
| 76 | + while read desc res ref date1 date2 spec num; do |
| 77 | + #num=`expr $num + 1` |
| 78 | + pr "Number : $num" |
| 79 | + pr "Description : $desc" |
| 80 | + pr "Resolution : $res" |
| 81 | + pr "Reference : $ref" |
| 82 | + pr "Archived on : $date1" |
| 83 | + pr "Resolved on : $date2" |
| 84 | + pr "Spec up-to-date : $spec" |
| 85 | + pr |
| 86 | + done |
| 87 | + ) < $ISSUES |
| 88 | +} |
| 89 | + |
| 90 | +list_unresolved () |
| 91 | +{ |
| 92 | + ( |
| 93 | + IFS=' ' |
| 94 | + #num=0 |
| 95 | + while read desc res ref date1 date2 spec num; do |
| 96 | + #num=`expr $num + 1` |
| 97 | + if [ "$res" = "-" ]; then |
| 98 | + pr "Number : $num" |
| 99 | + pr "Description : $desc" |
| 100 | + pr "Resolution : $res" |
| 101 | + pr "Reference : $ref" |
| 102 | + pr "Archived on : $date1" |
| 103 | + pr "Resolved on : $date2" |
| 104 | + pr "Spec up-to-date : $spec" |
| 105 | + pr |
| 106 | + fi |
| 107 | + done |
| 108 | + ) < $ISSUES |
| 109 | +} |
| 110 | + |
| 111 | +list_to_be_updated () |
| 112 | +{ |
| 113 | + ( |
| 114 | + IFS=' ' |
| 115 | + #num=0 |
| 116 | + while read desc res ref date1 date2 spec num; do |
| 117 | + #num=`expr $num + 1` |
| 118 | + if [ "$spec" = "no" ]; then |
| 119 | + pr "Number : $num" |
| 120 | + pr "Description : $desc" |
| 121 | + pr "Resolution : $res" |
| 122 | + pr "Reference : $ref" |
| 123 | + pr "Archived on : $date1" |
| 124 | + pr "Resolved on : $date2" |
| 125 | + pr "Spec up-to-date : $spec" |
| 126 | + pr |
| 127 | + fi |
| 128 | + done |
| 129 | + ) < $ISSUES |
| 130 | +} |
| 131 | + |
| 132 | +generate_html () |
| 133 | +{ |
| 134 | + echo "<table border>" |
| 135 | + echo "<tr>" |
| 136 | + echo " <th>#" |
| 137 | + echo " <th>Description" |
| 138 | + echo " <th>Resolution" |
| 139 | + echo " <th>Reference" |
| 140 | + echo " <th>Archived on" |
| 141 | + echo " <th>Resolved on" |
| 142 | + echo " <th>Spec up-to-date?" |
| 143 | + sort -r -t ' ' -k 5,6 -k 7,8nr $ISSUES | |
| 144 | + ( |
| 145 | + IFS=' ' |
| 146 | + #i=0 |
| 147 | + while read desc res ref date1 date2 spec i; do |
| 148 | + #i=`expr $i + 1` |
| 149 | + if [ "$res" = "-" ]; then |
| 150 | + class=unresolved |
| 151 | + else |
| 152 | + class=resolved |
| 153 | + fi |
| 154 | + echo "<tr valign=baseline class=$class>" |
| 155 | + echo " <td>$i" |
| 156 | + echo " <td>$desc" |
| 157 | + echo " <td>$res" |
| 158 | + case "$ref" in |
| 159 | + http:* | ftp:*) echo " <td><a href='$ref'>here</a>";; |
| 160 | + *) echo " <td>$ref";; |
| 161 | + esac |
| 162 | + |
| 163 | + echo " <td>$date1" |
| 164 | + echo " <td>$date2" |
| 165 | + echo " <td>$spec" |
| 166 | + done |
| 167 | + ) |
| 168 | + pr "</table>" |
| 169 | + pr "<p>Last update: "`ls -l $ISSUES | cut -c 42-48`\ |
| 170 | + " (HTML version generated: "`date "$DATEFRM"`")" |
| 171 | + |
| 172 | +} |
| 173 | + |
| 174 | +add_issue () |
| 175 | +{ |
| 176 | + if [ -z "$ref" ]; then |
| 177 | + prn "Reference (URL): " |
| 178 | + read ref |
| 179 | + fi |
| 180 | + if [ -z "$desc" ]; then |
| 181 | + prn "Description: " |
| 182 | + read desc |
| 183 | + fi |
| 184 | + ref=`echo $ref | tr "& " " "` |
| 185 | + desc=`echo $desc | tr "& " " "` |
| 186 | + num=`wc -l $ISSUES|cut -c -8` |
| 187 | + num=`expr $num + 1` |
| 188 | + pr "$desc - $ref "`date "$DATEFRM"`" not yet no $num" >>$ISSUES |
| 189 | + generate_html >$HTML |
| 190 | +} |
| 191 | + |
| 192 | +resolve_issue () |
| 193 | +{ |
| 194 | + if [ -z "$num" ]; then |
| 195 | + prn "Number: " |
| 196 | + read num |
| 197 | + fi |
| 198 | + case "$num" in |
| 199 | + [0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9]) ;; |
| 200 | + *) pr "Error: not a valid issue number: $num" >&2; return 2;; |
| 201 | + esac |
| 202 | + if [ -z "$res" ]; then |
| 203 | + prn "Resolution: " |
| 204 | + read res |
| 205 | + fi |
| 206 | + res=`echo $res | tr "& " " "` |
| 207 | + date=`date "$DATEFRM"` |
| 208 | + ( |
| 209 | + IFS=' ' |
| 210 | + #i=0 |
| 211 | + while read desc h1 ref date1 h2 spec i; do |
| 212 | + #i=`expr $i + 1` |
| 213 | + if [ $i = "$num" ]; then |
| 214 | + echo "$desc $res $ref $date1 $date $spec $i" |
| 215 | + else |
| 216 | + echo "$desc $h1 $ref $date1 $h2 $spec $i" |
| 217 | + fi |
| 218 | + done < $ISSUES >$TMP |
| 219 | + ) |
| 220 | + mv $TMP $ISSUES |
| 221 | + generate_html >$HTML |
| 222 | +} |
| 223 | + |
| 224 | +update_issue () |
| 225 | +{ |
| 226 | + if [ -z "$num" ]; then |
| 227 | + prn "Number: " |
| 228 | + read num |
| 229 | + fi |
| 230 | + case "$num" in |
| 231 | + [0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9]) ;; |
| 232 | + *) pr "Error: not a valid issue number: $num" >&2; return 2;; |
| 233 | + esac |
| 234 | + ( |
| 235 | + IFS=' ' |
| 236 | + #i=0 |
| 237 | + while read desc res ref date1 date2 spec i; do |
| 238 | + #i=`expr $i + 1` |
| 239 | + if [ $i != "$num" ]; then |
| 240 | + echo "$desc $res $ref $date1 $date2 $spec $i" |
| 241 | + elif [ "$res" = "-" ]; then |
| 242 | + pr "Error: cannot update; the issue must be resolved first" >&2 |
| 243 | + echo "$desc $res $ref $date1 $date2 $spec $i" |
| 244 | + else |
| 245 | + echo "$desc $res $ref $date1 $date2 yes $i" |
| 246 | + fi |
| 247 | + done < $ISSUES >$TMP |
| 248 | + ) |
| 249 | + mv $TMP $ISSUES |
| 250 | + generate_html >$HTML |
| 251 | +} |
| 252 | + |
| 253 | +interactive () |
| 254 | +{ |
| 255 | + while [ "$reply" != 'q' ]; do |
| 256 | + reply= |
| 257 | + pr |
| 258 | + pr "Choose one of:" |
| 259 | + while [ "$reply" = "" ]; do |
| 260 | + pr " l list the issues" |
| 261 | + pr " t list only unresolved issues" |
| 262 | + pr " y list issues to be updated in the spec" |
| 263 | + pr " a add an issue" |
| 264 | + pr " r mark an issue as resolved" |
| 265 | + pr " u mark the spec as up-to-date w.r.t. an issue" |
| 266 | + pr " g generate HTML page with the issues" |
| 267 | + pr " q quit" |
| 268 | + prn "? " |
| 269 | + read reply |
| 270 | + case "$reply" in |
| 271 | + l) list_issues | $PAGER;; |
| 272 | + a) ref=; desc=; add_issue;; |
| 273 | + r) num=; res=; resolve_issue;; |
| 274 | + u) num=; update_issue;; |
| 275 | + g) generate_html;; |
| 276 | + t) list_unresolved | $PAGER ;; |
| 277 | + y) list_to_be_updated | $PAGER;; |
| 278 | + q) ;; |
| 279 | + *) pr "Not understood, please try again"; reply=;; |
| 280 | + esac |
| 281 | + done |
| 282 | + done |
| 283 | +} |
| 284 | + |
| 285 | +if [ $# = 0 ]; then |
| 286 | + interactive |
| 287 | +else |
| 288 | + case "$1" in |
| 289 | + -l) list_issues;; |
| 290 | + -a) ref=$2; shift 2; desc="$*"; add_issue;; |
| 291 | + -r) num=$2; shift 2; res="$*"; resolve_issue;; |
| 292 | + -u) num=$2; update_issue;; |
| 293 | + -g) generate_html;; |
| 294 | + -t) list_unresolved;; |
| 295 | + -y) list_to_be_updated;; |
| 296 | + -?) quick_help;; |
| 297 | + *) quick_help; exit 1;; |
| 298 | + esac |
| 299 | +fi |
| 300 | + |
0 commit comments