Peter Bex committed 8b0204c Merge

Comments (0)

Files changed (1)


 (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 (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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.