Add dry run support.

This commit is contained in:
Dominik Pantůček 2025-04-16 21:21:08 +02:00
parent 5f4724874e
commit 37b608ab67
7 changed files with 40 additions and 51 deletions

View file

@ -1,22 +0,0 @@
set terminal pngcairo size 1000,600
set title "Members stats"
set output 'members-base-stats-2023-11.png'
src='members-base-stats-2023-11.data'
set timefmt "%Y-%m"
set xdata time
set format x "%Y-%m"
set xlabel "Month"
set ylabel "Members"
set grid
set key out right
plot[1420066800:][0:] \
src u 1:3 w l lw 2 t 'active', \
src u 1:4 w l t 'suspended', \
src u 1:5 w l t 'students', \
src u 1:6 w l t 'destroyed'

View file

@ -187,8 +187,8 @@ PROGRESS-SOURCES=progress.scm util-time.import.scm
progress.o: progress.import.scm
progress.import.scm: $(PROGRESS-SOURCES)
EXPORT-CARDS-SOURCES=export-cards.scm util-bst-ldict.import.scm \
mbase.import.scm brmember.import.scm
EXPORT-CARDS-SOURCES=export-cards.scm util-bst-ldict.import.scm \
mbase.import.scm brmember.import.scm configuration.import.scm
export-cards.o: export-cards.import.scm
export-cards.import.scm: $(EXPORT-CARDS-SOURCES)

View file

@ -43,6 +43,7 @@
*mailman3-sql*
*mailman3-sql-path*
*notifications-cc*
*dummy-run*
load-configuration!
)
@ -121,6 +122,9 @@
(define *notifications-cc* (make-parameter #f))
(define =notifications-cc= "rada@brmlab.cz")
;; If #t, do not do anything
(define *dummy-run* (make-parameter #f))
(define (load-single-configuration! fname)
(when (file-exists? fname)
(let loop ((lines (read-lines (open-input-file fname))))

View file

@ -38,7 +38,8 @@
(chicken irregex)
util-bst-ldict
mbase
brmember)
brmember
configuration)
;; Prints single card type records.
(define (cards-print/type mb type)
@ -84,7 +85,8 @@
;; Exports cards and desfires to the files specified.
(define (cards-export mb cardsfn desfirefn)
(cards-export/type mb 'card cardsfn)
(cards-export/type mb 'desfire desfirefn))
(when (not (*dummy-run*))
(cards-export/type mb 'card cardsfn)
(cards-export/type mb 'desfire desfirefn)))
)

View file

@ -191,10 +191,11 @@
;; Generates all members in given directory
(define (gen-html-members mb dir)
(ensure-directory dir)
(with-mbase-progress%
mb dir mr
(gen-html-member mr dir))
(clean-members-files mb dir))
(when (not (*dummy-run*))
(ensure-directory dir)
(with-mbase-progress%
mb dir mr
(gen-html-member mr dir))
(clean-members-files mb dir)))
)

View file

@ -116,6 +116,8 @@
(-mailman3-sql-path (path) "Set mailman3 direct SQL access path"
(*mailman3-sql* "1")
(*mailman3-sql-path* path))
(-n () "Do not do anything"
(*dummy-run* #t))
""
"Email options:"
(-from (email) "Sender email address"

View file

@ -94,27 +94,29 @@
;; Adds given email
(define (add-email-to-mailman3-list lst email)
(print "Add " email " to " lst ".")
(let ((result
(mailman3-send/recv
(list "addmembers" "-" (format "~A@brmlab.cz" lst))
email)))
(let loop ((lines result))
(when (not (null? lines))
(print " | " (car lines))
(loop (cdr lines))))))
(print "Add " email " to " lst "." (if (*dummy-run*) " [no-op]" ""))
(when (not (*dummy-run*))
(let ((result
(mailman3-send/recv
(list "addmembers" "-" (format "~A@brmlab.cz" lst))
email)))
(let loop ((lines result))
(when (not (null? lines))
(print " | " (car lines))
(loop (cdr lines)))))))
;; Removes given email from given listname
(define (remove-email-from-mailman3-list lst email)
(print "Remove " email " from " lst ".")
(let ((result
(get-mailman3-output-lines
"delmembers"
"-l" (format "~A@brmlab.cz" lst)
"-m" email)))
(let loop ((lines result))
(when (not (null? lines))
(print " | " (car lines))
(loop (cdr lines))))))
(print "Remove " email " from " lst "." (if (*dummy-run*) " [no-op]" ""))
(when (not (*dummy-run*))
(let ((result
(get-mailman3-output-lines
"delmembers"
"-l" (format "~A@brmlab.cz" lst)
"-m" email)))
(let loop ((lines result))
(when (not (null? lines))
(print " | " (car lines))
(loop (cdr lines)))))))
)