Skip to content

Commit af30dbf

Browse files
committed
Add salmonella-log-inquirer
1 parent 6b05593 commit af30dbf

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

salmonella-log-inquirer.scm

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
(module salmonella-log-inquirer ()
2+
3+
(import chicken scheme)
4+
(use data-structures files extras)
5+
(use salmonella salmonella-log-parser)
6+
(include "salmonella-version.scm")
7+
(include "salmonella-common.scm")
8+
9+
(define valid-actions '(fetch install check-version test meta-data))
10+
(define valid-parts '(message status duration))
11+
12+
(define (query-action log-data egg action part)
13+
(log-get egg
14+
action
15+
(case part
16+
((message) report-message)
17+
((status) report-status)
18+
((duration) report-duration)
19+
(else (error 'query-action "Invalid part" part)))
20+
log-data))
21+
22+
(define (log-statistics log-data)
23+
#<#EOF
24+
=== Summary
25+
Total eggs: #(count-total-eggs log-data)
26+
27+
==== Installation
28+
Ok: #(count-install-ok log-data)
29+
Failed: #(count-install-fail log-data)
30+
31+
==== Tests
32+
Ok: #(count-test-ok log-data)
33+
Failed: #(count-test-fail log-data)
34+
No tests: #(count-no-test log-data)
35+
36+
==== Documentation
37+
Documented: #(count-documented log-data)
38+
Undocumented: #(count-undocumented log-data)
39+
40+
==== Total run time
41+
#(prettify-time (inexact->exact (total-time log-data)))
42+
EOF
43+
)
44+
45+
(define (read-log args)
46+
(let ((log-file (last args)))
47+
(read-log-file log-file)))
48+
49+
(define (usage #!optional exit-code)
50+
(let ((this (pathname-strip-directory (program-name)))
51+
(port (if (and exit-code (not (zero? exit-code)))
52+
(current-error-port)
53+
(current-output-port))))
54+
(display #<#EOF
55+
#this [ -h | --help ]
56+
#this --version
57+
#this --log-info <log-file>
58+
#this --statistics <log-file>
59+
#this --list-eggs <log file>
60+
#this --action=<action> --egg=<egg> [ --part=<part> ] <log file>
61+
62+
<action>s:
63+
#(string-intersperse (map symbol->string valid-actions) "\n")
64+
65+
<part>s (the default part is "message"):
66+
#(string-intersperse (map symbol->string valid-parts) "\n")
67+
EOF
68+
port)
69+
(newline)
70+
(when exit-code (exit exit-code))))
71+
72+
73+
(let ((args (command-line-arguments)))
74+
(cond
75+
((null? args)
76+
(usage 1))
77+
((or (member "-h" args)
78+
(member "-help" args)
79+
(member "--help" args))
80+
(usage 0))
81+
((member "--version" args)
82+
(print salmonella-version))
83+
((null? (cdr args)) ;; from now on we require the log file
84+
(usage 1))
85+
((member "--list-eggs" args)
86+
(for-each print (log-eggs (read-log args))))
87+
((member "--log-info" args)
88+
(print (salmonella-info (read-log args))))
89+
((member "--statistics" args)
90+
(print (log-statistics (read-log args))))
91+
(else
92+
(let ((action-str (cmd-line-arg '--action args))
93+
(egg-str (cmd-line-arg '--egg args))
94+
(part-str (cmd-line-arg '--part args)))
95+
(unless action-str
96+
(die "Missing --action=<action>"))
97+
(unless egg-str
98+
(die "Missing --egg=<egg>"))
99+
(let ((action (string->symbol action-str))
100+
(egg (string->symbol egg-str))
101+
(part (if part-str
102+
(string->symbol part-str)
103+
'message)))
104+
(unless (memq action valid-actions)
105+
(die "Invalid action: " action))
106+
(unless (memq part valid-parts)
107+
(die "Invalid part: " part))
108+
(let ((printer (if (eq? action 'meta-data)
109+
pp
110+
print)))
111+
(printer (query-action (read-log args) egg action part)))))))
112+
)
113+
) ;; end module

salmonella-log-parser.scm

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131
;; misc
3232
prettify-time sort-eggs log-version
33+
34+
;; low level stuff
35+
log-get
3336
)
3437

3538
(import scheme chicken)

salmonella.setup

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
(compile ,@csc-args salmonella-epidemy.scm -o salmonella-epidemy)
2424
(compile ,@csc-args salmonella-log-viewer.scm -o salmonella-log-viewer)
2525
(compile ,@csc-args salmonella-log-merger.scm -o salmonella-log-merger)
26+
(compile ,@csc-args salmonella-log-inquirer.scm -o salmonella-log-inquirer)
2627

2728
(install-extension 'salmonella
2829
'("salmonella.so" "salmonella.import.so")
@@ -45,6 +46,10 @@
4546
'("salmonella-log-merger")
4647
`((version ,salmonella-version)))
4748

49+
(install-program 'salmonella-log-inquirer
50+
'("salmonella-log-inquirer")
51+
`((version ,salmonella-version)))
52+
4853
(install-program 'salmonella-epidemy
4954
'("salmonella-epidemy")
5055
`((version ,salmonella-version)))

0 commit comments

Comments
 (0)