1. Moritz Heidkamp
  2. henrietta-cache


mor...@twoticketsplease.de  committed 973ee92

add -i/--init-file option for giving an init file that is loaded
before the update process starts. implement hook functionality which
can be used from the init file (download-release-success and
download-release-error hooks only so far).

  • Participants
  • Parent commits 21b6d4f
  • Branches new-release-hook

Comments (0)

Files changed (1)

File henrietta-cache.scm

View file
 (define *cache-directory* "cache")
 (define *egg-list* "egg-locations")
 (define *chicken-release* (##sys#fudge 41))
+(define *init-file* #f)
+(define download-release-success-hook
+  (make-parameter #f))
+(define download-release-error-hook
+  (make-parameter #f))
+(define hooks
+  `((download-release-success . ,download-release-success-hook)
+    (download-release-error   . ,download-release-error-hook)))
+(define (run-hook hook-name . args)
+  (and-let* ((hook (or (alist-ref hook-name hooks)
+                       (error "invalid hook" hook-name)))
+             (hook (and hook (hook))))
+    (condition-case
+        (apply hook args)
+      (exn ()
+           (print-error-message exn
+                                (current-error-port)
+                                (sprintf "Error running hook `~A'" hook-name))
+           (flush-output (current-error-port))))))
 ;; This works on raw URI strings, not URI objects (for now?)
 (define (replace-uri-patterns uri patterns)
                                         "Error downloading or extracting egg '~A' release ~A: "
                                         egg-name egg-release)
                                (print-error-message exn (current-error-port))
-                               (flush-output (current-error-port)))
+                               (flush-output (current-error-port))
+                               (run-hook 'download-release-error egg-name egg-release))
                              (create-directory cache-dir #t)
-                             (download-release type uri cache-dir))))))
+                             (download-release type uri cache-dir)
+                             (run-hook 'download-release-success egg-name egg-release))))))
                    (cdr uri/releases))))
     (with-input-from-request uri #f read-file)))
 (define (update-egg-cache)
+  (when *init-file*
+    (load *init-file*))
    (lambda (egg)
      (let* ((egg-name (car egg))
                  (unless (pair? (cdr args)) (usage 1))
                  (set! *egg-list* (cadr args))
                  (loop (cddr args)))
+                ((or (string=? arg "-i") (string=? arg "-init-file"))
+                 (unless (pair? (cdr args)) (usage 1))
+                 (set! *init-file* (cadr args))
+                 (loop (cddr args)))
                 ((and (positive? (string-length arg))
                       (char=? #\- (string-ref arg 0)))
                  (if (> (string-length arg) 2)