summarize-guile-TODO.scm 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. ;;; summarize-guile-TODO --- Display Guile TODO list in various ways
  2. ;; Copyright (C) 2002, 2006, 2010, 2011 Free Software Foundation, Inc.
  3. ;;
  4. ;; This program is free software; you can redistribute it and/or
  5. ;; modify it under the terms of the GNU Lesser General Public License
  6. ;; as published by the Free Software Foundation; either version 3, or
  7. ;; (at your option) any later version.
  8. ;;
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ;; Lesser General Public License for more details.
  13. ;;
  14. ;; You should have received a copy of the GNU Lesser General Public
  15. ;; License along with this software; see the file COPYING.LESSER. If
  16. ;; not, write to the Free Software Foundation, Inc., 51 Franklin
  17. ;; Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. ;;; Author: Thien-Thi Nguyen <ttn@gnu.org>
  19. ;;; Commentary:
  20. ;; Usage: summarize-guile-TODO TODOFILE
  21. ;;
  22. ;; The TODOFILE is typically Guile's (see workbook/tasks/README)
  23. ;; presumed to serve as our signal to ourselves (lest we want real
  24. ;; bosses hassling us) wrt to the overt message "items to do" as well as
  25. ;; the messages that can be inferred from its structure.
  26. ;;
  27. ;; This program reads TODOFILE and displays interpretations on its
  28. ;; structure, including registered markers and ownership, in various
  29. ;; ways.
  30. ;;
  31. ;; A primary interest in any task is its parent task. The output
  32. ;; summarization by default lists every item and its parent chain.
  33. ;; Top-level parents are not items. You can use these command-line
  34. ;; options to modify the selection and display (selection criteria
  35. ;; are ANDed together):
  36. ;;
  37. ;; -i, --involved USER -- select USER-involved items
  38. ;; -p, --personal USER -- select USER-responsible items
  39. ;; -t, --todo -- select unfinished items (status "-")
  40. ;; -d, --done -- select finished items (status "+")
  41. ;; -r, --review -- select review items (marker "R")
  42. ;;
  43. ;; -w, --who -- also show who is associated w/ the item
  44. ;; -n, --no-parent -- do not show parent chain
  45. ;;
  46. ;;
  47. ;; Usage from a Scheme program:
  48. ;; (summarize-guile-TODO . args) ; uses first arg only
  49. ;;
  50. ;;
  51. ;; Bugs: (1) Markers are scanned in sequence: D R X N%. This means "XD"
  52. ;; and the like are completely dropped. However, such strings
  53. ;; are unlikely to be used if the markers are chosen to be
  54. ;; somewhat exclusive, which is currently the case for D R X.
  55. ;; N% used w/ these needs to be something like: "D25%" (this
  56. ;; means discussion accounts for 1/4 of the task).
  57. ;;
  58. ;; TODO: Implement more various ways. (Patches welcome.)
  59. ;; Add support for ORing criteria.
  60. ;;; Code:
  61. (debug-enable 'backtrace)
  62. (define-module (scripts summarize-guile-TODO)
  63. :use-module (scripts read-text-outline)
  64. :use-module (ice-9 getopt-long)
  65. :autoload (srfi srfi-13) (string-tokenize) ; string library
  66. :autoload (srfi srfi-14) (char-set) ; string library
  67. :autoload (ice-9 common-list) (remove-if-not)
  68. :export (summarize-guile-TODO))
  69. (define %include-in-guild-list #f)
  70. (define %summary "A quaint relic of the past.")
  71. (define put set-object-property!)
  72. (define get object-property)
  73. (define (as-leaf x)
  74. (cond ((get x 'who)
  75. => (lambda (who)
  76. (put x 'who
  77. (map string->symbol
  78. (string-tokenize who (char-set #\:)))))))
  79. (cond ((get x 'pct-done)
  80. => (lambda (pct-done)
  81. (put x 'pct-done (string->number pct-done)))))
  82. x)
  83. (define (hang-by-the-leaves trees)
  84. (let ((leaves '()))
  85. (letrec ((hang (lambda (tree parent)
  86. (if (list? tree)
  87. (begin
  88. (put (car tree) 'parent parent)
  89. (for-each (lambda (child)
  90. (hang child (car tree)))
  91. (cdr tree)))
  92. (begin
  93. (put tree 'parent parent)
  94. (set! leaves (cons (as-leaf tree) leaves)))))))
  95. (for-each (lambda (tree)
  96. (hang tree #f))
  97. trees))
  98. leaves))
  99. (define (read-TODO file)
  100. (hang-by-the-leaves
  101. ((make-text-outline-reader
  102. "(([ ][ ])*)([-+])(D*)(R*)(X*)(([0-9]+)%)* *([^[]*)(\\[(.*)\\])*"
  103. '((level-substring-divisor . 2)
  104. (body-submatch-number . 9)
  105. (extra-fields . ((status . 3)
  106. (design? . 4)
  107. (review? . 5)
  108. (extblock? . 6)
  109. (pct-done . 8)
  110. (who . 11)))))
  111. (open-file file "r"))))
  112. (define (select-items p items)
  113. (let ((sub '()))
  114. (cond ((option-ref p 'involved #f)
  115. => (lambda (u)
  116. (let ((u (string->symbol u)))
  117. (set! sub (cons
  118. (lambda (x)
  119. (and (get x 'who)
  120. (memq u (get x 'who))))
  121. sub))))))
  122. (cond ((option-ref p 'personal #f)
  123. => (lambda (u)
  124. (let ((u (string->symbol u)))
  125. (set! sub (cons
  126. (lambda (x)
  127. (cond ((get x 'who)
  128. => (lambda (ls)
  129. (eq? (car (reverse ls))
  130. u)))
  131. (else #f)))
  132. sub))))))
  133. (for-each (lambda (pair)
  134. (cond ((option-ref p (car pair) #f)
  135. (set! sub (cons (cdr pair) sub)))))
  136. `((todo . ,(lambda (x) (string=? (get x 'status) "-")))
  137. (done . ,(lambda (x) (string=? (get x 'status) "+")))
  138. (review . ,(lambda (x) (get x 'review?)))))
  139. (let loop ((sub (reverse sub)) (items items))
  140. (if (null? sub)
  141. (reverse items)
  142. (loop (cdr sub) (remove-if-not (car sub) items))))))
  143. (define (make-display-item show-who? show-parent?)
  144. (let ((show-who
  145. (if show-who?
  146. (lambda (item)
  147. (cond ((get item 'who)
  148. => (lambda (who) (format #f " ~A" who)))
  149. (else "")))
  150. (lambda (item) "")))
  151. (show-parents
  152. (if show-parent?
  153. (lambda (item)
  154. (let loop ((parent (get item 'parent)) (indent 2))
  155. (and parent
  156. (begin
  157. (format #t "under : ~A~A\n"
  158. (make-string indent #\space)
  159. parent)
  160. (loop (get parent 'parent) (+ 2 indent))))))
  161. (lambda (item) #t))))
  162. (lambda (item)
  163. (format #t "status: ~A~A~A~A~A~A\nitem : ~A\n"
  164. (get item 'status)
  165. (if (get item 'design?) "D" "")
  166. (if (get item 'review?) "R" "")
  167. (if (get item 'extblock?) "X" "")
  168. (cond ((get item 'pct-done)
  169. => (lambda (pct-done)
  170. (format #f " ~A%" pct-done)))
  171. (else ""))
  172. (show-who item)
  173. item)
  174. (show-parents item))))
  175. (define (display-items p items)
  176. (let ((display-item (make-display-item (option-ref p 'who #f)
  177. (not (option-ref p 'no-parent #f))
  178. )))
  179. (for-each display-item items)))
  180. (define (summarize-guile-TODO . args)
  181. (let ((p (getopt-long (cons "summarize-guile-TODO" args)
  182. '((who (single-char #\w))
  183. (no-parent (single-char #\n))
  184. (involved (single-char #\i)
  185. (value #t))
  186. (personal (single-char #\p)
  187. (value #t))
  188. (todo (single-char #\t))
  189. (done (single-char #\d))
  190. (review (single-char #\r))
  191. ;; Add options here.
  192. ))))
  193. (display-items p (select-items p (read-TODO (car (option-ref p '() #f))))))
  194. #t) ; exit val
  195. (define main summarize-guile-TODO)
  196. ;;; summarize-guile-TODO ends here