diff options
-rw-r--r-- | module/calp/entry-points/update-zoneinfo.scm | 42 | ||||
-rw-r--r-- | module/calp/main.scm | 24 |
2 files changed, 45 insertions, 21 deletions
diff --git a/module/calp/entry-points/update-zoneinfo.scm b/module/calp/entry-points/update-zoneinfo.scm new file mode 100644 index 00000000..b565faeb --- /dev/null +++ b/module/calp/entry-points/update-zoneinfo.scm @@ -0,0 +1,42 @@ +(define-module (calp entry-points update-zoneinfo) + :export (main) + ;; :use-module (hnh util) + :use-module (datetime) + :use-module (srfi srfi-1) + :use-module (hnh util path) + :use-module ((hnh util io) :select (with-atomic-output-to-file)) + :use-module ((xdg basedir) :prefix xdg-) + :use-module ((ice-9 rdelim) :select (read-line)) + :use-module (hnh util options) + :use-module (ice-9 getopt-long) + :use-module (ice-9 popen) + :use-module (ice-9 format) + :use-module (calp translation)) + +(define opt-spec + `((help (single-char #\h) (description ,(_ "Print this help."))))) + +(define (main args) + (define opts (getopt-long args (getopt-opt opt-spec))) + + (when (option-ref opts 'help #f) + (print-arg-help opt-spec) + (throw 'return)) + + (let* ((locations (list "/usr/libexec/calp/tzget" + (path-append (xdg-data-home) "tzget"))) + (filename (or (find file-exists? locations) + (scm-error 'missing-helper "update-zoneinfo" + (_ "tzget not installed, please put it in one of ~a") + (list locations) + (list "tzget" locations)))) + + (pipe (open-input-pipe filename)) + (names (string-split (read-line pipe) #\space))) + (with-atomic-output-to-file (path-append (xdg-data-home) "calp" "zoneinfo.scm") + (lambda () + (format #t ";;; Autogenerated file~%;;; Last updated ~a~%~y~%" + (datetime->string (current-datetime)) + `((@ (datetime instance) tz-list) (quote ,names))))) + + (close-pipe pipe))) diff --git a/module/calp/main.scm b/module/calp/main.scm index 1cbd0f4e..7f2a4679 100644 --- a/module/calp/main.scm +++ b/module/calp/main.scm @@ -61,8 +61,6 @@ contain all events. (description ,(format #f (_ "Display version, which is ~a btw.") (@ (calp) version)))) - (update-zoneinfo) - (help (single-char #\h) (description ,(_ "Print this help"))) @@ -92,6 +90,8 @@ from the module (calp benchmark <i>module</i>).</p>") displays events. The <i>/month/{date}.html</i> & <i>/week/{date}.html</i> runs the same output code as <b>html</b>. While the <i>/calendar/{uid}.ics</i> uses the same code as <b>ical</b>.</p>") + (_ "<p><b>update-zoneinfo</b> in theory downloads and updates our local +zoneinfo database, but is currently broken.</p>") "<hr/><br/>" ;; Header for list of available flags. ;; Actual list is auto generated elsewhere. @@ -164,25 +164,6 @@ the same code as <b>ical</b>.</p>") (format #t (_ "Calp version ~a~%") (@ (calp) version)) (throw 'return)) - (when (option-ref opts 'update-zoneinfo #f) - (let* ((locations (list "/usr/libexec/calp/tzget" (path-append (xdg-data-home) "tzget"))) - (filename (or (find file-exists? locations) - (scm-error 'missing-helper "wrapped-main" - (_ "tzget not installed, please put it in one of ~a") - (list locations) - (list "tzget" locations)))) - (pipe (open-input-pipe filename))) - - ;; (define path (read-line pipe)) - (define line ((@ (ice-9 rdelim) read-line) pipe)) - (define names (string-split line #\space)) - ((@ (hnh util io) with-atomic-output-to-file) - (path-append (xdg-data-home) "calp" "zoneinfo.scm") - (lambda () - (write `((@ (datetime instance) tz-list) ',names)) (newline) - ;; (write `(set-config! 'last-zoneinfo-upgrade ,((@ (datetime) current-date)))) (newline) - )))) - ;; always load zoneinfo if available. (let ((z (path-append (xdg-data-home) "calp" "zoneinfo.scm"))) (when (file-exists? z) @@ -209,6 +190,7 @@ the same code as <b>ical</b>.</p>") ((convert) (@ (calp entry-points convert) main)) ((tidsrapport) (@ (calp entry-points tidsrapport) main)) ((benchmark) (@ (calp entry-points benchmark) main)) + ((update-zoneinfo) (@ (calp entry-points update-zoneinfo) main)) (else => (lambda (s) (format (current-error-port) (_ "Unsupported mode of operation: ~a~%") |