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