Rename and add installation target.
This commit is contained in:
parent
164cfa83c2
commit
759aa9b98d
3 changed files with 35 additions and 12 deletions
303
src/bbstool.scm
303
src/bbstool.scm
|
@ -1,303 +0,0 @@
|
|||
;;
|
||||
;; bbstool.scm
|
||||
;;
|
||||
;; Brmburo system - members management tool.
|
||||
;;
|
||||
|
||||
(import (chicken repl)
|
||||
testing
|
||||
listing
|
||||
dictionary
|
||||
month
|
||||
period
|
||||
command-line
|
||||
util-list
|
||||
ansi
|
||||
members-base
|
||||
primes
|
||||
member-record
|
||||
configuration
|
||||
table
|
||||
cards
|
||||
members-print
|
||||
member-parser
|
||||
member-fees
|
||||
members-dir
|
||||
util-csv
|
||||
members-payments
|
||||
web-static
|
||||
environment
|
||||
bank-account
|
||||
mailman
|
||||
util-set-list
|
||||
util-parser
|
||||
texts)
|
||||
|
||||
;; Print banner
|
||||
(print "HackerBase 0.9.3 (c) 2023 Brmlab, z.s.")
|
||||
(newline)
|
||||
|
||||
;; Command-line options and configurable parameters
|
||||
(define -apikeys-file- (make-parameter "apikey.ntlm"))
|
||||
(define -needs-bank- (make-parameter #f))
|
||||
(define -member-id- (make-parameter #f))
|
||||
(define -member-nick- (make-parameter #f))
|
||||
(define -action- (make-parameter #f))
|
||||
(define -fname- (make-parameter #f))
|
||||
(define -run-tests?- (make-parameter #f))
|
||||
(define -web-dir- (make-parameter #f))
|
||||
(define -bank-dir- (make-parameter #f))
|
||||
(define -normal-month- (make-parameter #t))
|
||||
(define -jendasap-checked- (make-parameter "checked.ntlm"))
|
||||
(define -ml-all- (make-parameter #f))
|
||||
(define -show-destroyed- (make-parameter #f))
|
||||
(define -notify-months- (make-parameter 1))
|
||||
|
||||
;; Arguments parsing
|
||||
(command-line
|
||||
print-help
|
||||
(-h () "This help"
|
||||
(print "Command-line options:")
|
||||
(newline)
|
||||
(print-help)
|
||||
(newline)
|
||||
(exit 0))
|
||||
(-license () "Show licensing terms"
|
||||
(print banner)
|
||||
(newline)
|
||||
(print license)
|
||||
(exit 0))
|
||||
""
|
||||
"Configuration options:"
|
||||
(-members (dir) "Members base directory" (*members-directory* dir))
|
||||
(-month (YYYY-MM) "Specify current month"
|
||||
(-normal-month- #f)
|
||||
(*current-month* (string->month YYYY-MM)))
|
||||
(-tstyle (style) "Use given table style: debug, ascii, unicode"
|
||||
(*table-border-style* (string->symbol style)))
|
||||
(-apikey (fname) "File with Fio API keys"
|
||||
(-apikeys-file- fname))
|
||||
(-bankdir (dir) "Where are bank CSV files"
|
||||
(-bank-dir- dir))
|
||||
(-checked (file) "JendaSAP checked.ntlm file"
|
||||
(-jendasap-checked- file))
|
||||
(-ml-all () "Load all mailman lists"
|
||||
(-ml-all- #t))
|
||||
(-destroyed () "Show destroyed members in -fees"
|
||||
(-show-destroyed- #t))
|
||||
""
|
||||
"Query options:"
|
||||
(-mi (id) "Specify member by id" (-member-id- (string->number id)))
|
||||
(-mn (nick) "Specify member by nick"
|
||||
(when (not (-action-))
|
||||
(-action- 'no-op))
|
||||
(-member-nick- nick))
|
||||
""
|
||||
"Actions:"
|
||||
(-info () "Print information"
|
||||
(-needs-bank- #t)
|
||||
(-action- 'print-info))
|
||||
(-stats (file:gnuplot-data) "Get stats for all months"
|
||||
(-action- 'print-stats)
|
||||
(-fname- file:gnuplot-data))
|
||||
(-print () "Print given member file"
|
||||
(-action- 'print-member-file))
|
||||
(-tests () "Run self-tests upon startup" (-run-tests?- #t))
|
||||
(-idstats () "Returns information about available member ids" (-action- 'print-idstats))
|
||||
(-genid () "Generates random member id" (-action- 'genid))
|
||||
(-gencards (file:cards file:desfires) "Generates brmdoor-compatible card files"
|
||||
(-action- 'gencards)
|
||||
(-fname- (list file:cards file:desfires)))
|
||||
(-problems () "Prints all files with problems" (-action- 'problems))
|
||||
(-fees () "Prints fees table"
|
||||
(-needs-bank- #t)
|
||||
(-action- 'fees))
|
||||
(-genweb (dir) "Generate static web files"
|
||||
(-needs-bank- #t)
|
||||
(-web-dir- dir)
|
||||
(-action- 'genweb))
|
||||
(-repl () "Start REPL with everything loaded"
|
||||
(-needs-bank- #t)
|
||||
(-action- 'repl))
|
||||
(-edit () "Edit selected user"
|
||||
(-action- 'edit))
|
||||
(-unpaired () "Show latest unpaired bank transactions"
|
||||
(-needs-bank- #t)
|
||||
(-action- 'unpaired))
|
||||
(-mlcheck () "Check internal ML"
|
||||
(-action- 'mlcheck))
|
||||
(-mlsync () "Synchronize internal ML"
|
||||
(-action- 'mlsync))
|
||||
(-notify () "Members with debt for more than 1 month"
|
||||
(-notify-months- 1)
|
||||
(-needs-bank- #t)
|
||||
(-action- 'notify))
|
||||
(-notify3 () "Members with debt for more than 3 month"
|
||||
(-notify-months- 3)
|
||||
(-needs-bank- #t)
|
||||
(-action- 'notify))
|
||||
)
|
||||
|
||||
;; Run tests
|
||||
(when (-run-tests?-)
|
||||
(listing-tests!)
|
||||
(dictionary-tests!)
|
||||
(month-tests!)
|
||||
(period-tests!)
|
||||
(util-list-tests!)
|
||||
(ansi-tests!)
|
||||
(command-line-tests!)
|
||||
(members-dir-tests!)
|
||||
(primes-tests!)
|
||||
(member-record-tests!)
|
||||
(table-tests!)
|
||||
(csv-simple-tests!)
|
||||
(lset-tests!)
|
||||
(parser-tests!)
|
||||
(newline))
|
||||
|
||||
;; Load the members database (required for everything anyway)
|
||||
(define MB0
|
||||
(if (-action-)
|
||||
(let ((mb (load-members (*members-directory*) #t)))
|
||||
(if (-needs-bank-)
|
||||
(members-payments-process mb (-apikeys-file-) (-bank-dir-) (-jendasap-checked-))
|
||||
mb))
|
||||
#f))
|
||||
|
||||
;; Load ML(s) and merge them
|
||||
(define-values (MB internal-ml)
|
||||
(if MB0
|
||||
(if (-ml-all-)
|
||||
(let ()
|
||||
(define mls (load-mailman-lists))
|
||||
(values (foldl (lambda (mb ml)
|
||||
(members-base-merge-mailman mb ml))
|
||||
MB0
|
||||
mls)
|
||||
(find-mailman-list mls "internal")))
|
||||
(let ()
|
||||
(define internal-ml (load-mailman-list "internal"))
|
||||
(values (members-base-merge-mailman MB0 internal-ml)
|
||||
internal-ml)))
|
||||
(values #f #f)))
|
||||
|
||||
;; If a member is specified by either id or nick, get its record
|
||||
(define mr
|
||||
(if (-member-id-)
|
||||
(let ((mr (find-member-by-id MB (-member-id-))))
|
||||
(when (not mr)
|
||||
(print "Member id " (-member-id-) " not found!"))
|
||||
mr)
|
||||
(if (-member-nick-)
|
||||
(let ((mrs (find-members-by-nick MB (-member-nick-))))
|
||||
(cond ((null? mrs)
|
||||
(newline)
|
||||
(print "Member nick " (-member-nick-) " not found!")
|
||||
#f)
|
||||
((> (length mrs) 1)
|
||||
(newline)
|
||||
(print "Found: " (member-records->string mrs))
|
||||
(-action- 'no-op)
|
||||
#f)
|
||||
(else
|
||||
(car mrs))))
|
||||
#f)))
|
||||
|
||||
;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;; Perform requested action
|
||||
(case (-action-)
|
||||
((print-info)
|
||||
(newline)
|
||||
(print "Current month: " (month->string (*current-month*)))
|
||||
(newline)
|
||||
(if mr
|
||||
(print-member-table mr)
|
||||
(print-members-base-table MB))
|
||||
(newline))
|
||||
((print-stats)
|
||||
(newline)
|
||||
(parameterize ((current-output-port (open-output-file (-fname-))))
|
||||
(print-members-base-stats
|
||||
(members-base-stats MB))))
|
||||
((print-member-file)
|
||||
(cond (mr
|
||||
(newline)
|
||||
(print-member-source mr))
|
||||
(else
|
||||
(print "No member specified!"))))
|
||||
((print-idstats)
|
||||
(newline)
|
||||
(print-members-ids-stats MB)
|
||||
(newline))
|
||||
((genid)
|
||||
(newline)
|
||||
(print "New member id: " (gen-member-id MB))
|
||||
(newline))
|
||||
((gencards)
|
||||
(if (-normal-month-)
|
||||
(apply cards-export MB (-fname-))
|
||||
(print "Cards export disabled with manually specified current month.")))
|
||||
((problems)
|
||||
(let ((num (let loop ((mb (members-base-members MB))
|
||||
(num 0))
|
||||
(if (null? mb)
|
||||
num
|
||||
(loop (cdr mb)
|
||||
(if (or (member-has-problems? (car mb))
|
||||
(member-has-highlights? (car mb)))
|
||||
(let ()
|
||||
(newline)
|
||||
(print-member-table (car mb))
|
||||
(print-member-source (car mb))
|
||||
(add1 num))
|
||||
num))))))
|
||||
(when (= num 0)
|
||||
(newline)
|
||||
(print "No problems found."))))
|
||||
((fees)
|
||||
(newline)
|
||||
(print-members-fees-table MB (-show-destroyed-)))
|
||||
((repl)
|
||||
(repl))
|
||||
((genweb)
|
||||
(gen-web-static MB (-web-dir-)))
|
||||
((edit)
|
||||
(if mr
|
||||
(edit-file (member-file-path mr))
|
||||
(print "No member to edit.")))
|
||||
((no-op) (void))
|
||||
((unpaired)
|
||||
(newline)
|
||||
(print-unpaired-table MB))
|
||||
((mlsync)
|
||||
(if (-normal-month-)
|
||||
(mailman-sync-members internal-ml (members-base-active-emails MB))
|
||||
(print "Mailman synchronization disabled with manually specified current month.")))
|
||||
((mlcheck)
|
||||
(let-values (((missing surplus)
|
||||
(mailman-compare-members internal-ml
|
||||
(members-base-active-emails MB))))
|
||||
(if (and (null? missing)
|
||||
(null? surplus))
|
||||
(print "Internal mailing list membership in sync.")
|
||||
(let ()
|
||||
(print "Internal mailing list:")
|
||||
(when (not (null? missing))
|
||||
(print " Missing: " missing))
|
||||
(when (not (null? surplus))
|
||||
(print " Outsiders: " surplus))))))
|
||||
((notify)
|
||||
(let ((nmembers (members-to-notify MB (-notify-months-))))
|
||||
(newline)
|
||||
(if (null? nmembers)
|
||||
(print "Everyone paid on time.")
|
||||
(let ()
|
||||
(print "Notify" (-notify-months-))
|
||||
(print (map member-nick nmembers))))))
|
||||
(else
|
||||
(print "Nothing to do."))
|
||||
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue