set-config.rkt (1528B)
1 #lang racket/base 2 (require racket/cmdline 3 racket/file 4 racket/path) 5 6 (provide set-config) 7 8 (module test racket/base) 9 10 (module+ main 11 (command-line 12 #:args 13 (dest-config-file install-name build-stamp 14 doc-search . catalog) 15 (set-config dest-config-file 16 install-name build-stamp 17 doc-search catalog))) 18 19 (define (set-config dest-config-file 20 install-name build-stamp 21 doc-search catalogs) 22 (define orig 23 (if (file-exists? dest-config-file) 24 (call-with-input-file* dest-config-file read) 25 (hash))) 26 27 (let* ([table orig] 28 [table 29 (if (equal? doc-search "") 30 table 31 (hash-set table 'doc-search-url doc-search))] 32 [table (if (equal? catalogs '("")) 33 table 34 (hash-set table 'catalogs 35 (for/list ([c (in-list catalogs)]) 36 (if (equal? c "") 37 #f 38 c))))] 39 [table (if (equal? install-name "") 40 table 41 (hash-set table 'installation-name install-name))] 42 [table (hash-set table 'build-stamp build-stamp)]) 43 (unless (equal? table orig) 44 (make-directory* (path-only dest-config-file)) 45 (call-with-output-file dest-config-file 46 #:exists 'truncate 47 (lambda (o) 48 (write table o) 49 (newline o))))))