diff --git a/modules/ordo/action/filesystem.scm b/modules/ordo/action/filesystem.scm index 855eb85..7eb6a35 100644 --- a/modules/ordo/action/filesystem.scm +++ b/modules/ordo/action/filesystem.scm @@ -10,22 +10,24 @@ install-directory install-file)) -(define* (create-temporary-directory ctx #:key tmpdir suffix template) - (connection-must (context-connection ctx) - "mktemp" (chain-when - '("--directory") - (tmpdir (append _ `("--tmpdir" tmpdir))) - (suffix (append _ `("--suffix" suffix))) - (template (append _ `(template)))))) +(define* (create-temporary-directory #:key tmpdir suffix template) + (lambda (ctx) + (connection-must (context-connection ctx) + "mktemp" (chain-when + '("--directory") + (tmpdir (append _ `("--tmpdir" tmpdir))) + (suffix (append _ `("--suffix" suffix))) + (template (append _ `(template))))))) -(define* (install-directory ctx path #:key owner group mode) - (connection-must (context-connection ctx) - "install" (chain-when - '("--directory") - (owner (append _ `("--owner" ,owner))) - (group (append _ `("--group" ,group))) - (mode (append _ `("--mode" ,mode))) - (#t (append _ `(,path)))))) +(define* (install-directory path #:key owner group mode) + (lambda (ctx) + (connection-must (context-connection ctx) + "install" (chain-when + '("--directory") + (owner (append _ `("--owner" ,owner))) + (group (append _ `("--group" ,group))) + (mode (append _ `("--mode" ,mode))) + (#t (append _ `(,path))))))) ;; Helper not intended for use outside of this module (define (upload-tmp-file ctx) @@ -43,21 +45,21 @@ ;; Because we might need sudo to install the remote file, we first ;; upload the source to a temporary file. -(define* (install-file ctx path #:key owner group mode content local-src remote-src backup?) +(define* (install-file path #:key owner group mode content local-src remote-src backup?) (when (not (= 1 (length (filter identity (list content local-src remote-src))))) (error "exactly one of #:content, #:local-src, or #:remote-src is required")) - (format #t "install-file ~a~%" path) - (let ((remote-src (cond - (remote-src remote-src) - (local-src (call-with-input-file local-src (upload-tmp-file ctx))) - ((string? content) (call-with-input-string content (upload-tmp-file ctx))) - ((bytevector? content) (call-with-input-bytevector content (upload-tmp-file ctx))) - (else (error "unsupported type for #:content"))))) - (connection-must (context-connection ctx) - "install" (chain-when - '() - (owner (append _ `("--owner" ,owner))) - (group (append _ `("--group" ,group))) - (mode (append _ `("--mode" ,mode))) - (backup? (append _ '("--backup" "numbered"))) - (#t (append _ (list remote-src path))))))) + (lambda (ctx) + (let ((remote-src (cond + (remote-src remote-src) + (local-src (call-with-input-file local-src (upload-tmp-file ctx))) + ((string? content) (call-with-input-string content (upload-tmp-file ctx))) + ((bytevector? content) (call-with-input-bytevector content (upload-tmp-file ctx))) + (else (error "unsupported type for #:content"))))) + (connection-must (context-connection ctx) + "install" (chain-when + '() + (owner (append _ `("--owner" ,owner))) + (group (append _ `("--group" ,group))) + (mode (append _ `("--mode" ,mode))) + (backup? (append _ '("--backup" "numbered"))) + (#t (append _ (list remote-src path)))))))) diff --git a/modules/ordo/context.scm b/modules/ordo/context.scm index a698199..bc07882 100644 --- a/modules/ordo/context.scm +++ b/modules/ordo/context.scm @@ -11,7 +11,8 @@ get-context-triggers context-triggered? register-context-var! - context-ref)) + context-ref + bind-context-vars)) (define-record-type (make-context connection vars scratch-dir) @@ -37,3 +38,10 @@ (define (register-context-var! ctx var-name val) (set-context-vars! ctx (assoc-set! (context-vars ctx) var-name val))) + +(define-syntax bind-context-vars + (syntax-rules () + ((bind-context-vars (var-name ...) proc) + (lambda (ctx) + (let ((var-name (context-ref ctx (quote var-name))) ...) + (proc ctx)))))) diff --git a/modules/ordo/play.scm b/modules/ordo/play.scm index f3ebc0e..9bb8639 100644 --- a/modules/ordo/play.scm +++ b/modules/ordo/play.scm @@ -42,7 +42,6 @@ (lambda (c) (let* ((tmp-dir (car (connection-must c "mktemp" '("--directory")))) (ctx (make-context c (play-vars play) tmp-dir))) - (pk ctx) (dynamic-wind (const #t) (lambda () diff --git a/tryme.scm b/tryme.scm index 8f2ac87..7428ac8 100644 --- a/tryme.scm +++ b/tryme.scm @@ -30,21 +30,22 @@ (const "/home/ray/ordo-test-again") #:register 'base-dir) (task "Create test directory" - (lambda (ctx) - (install-directory ctx (context-ref ctx 'base-dir)))) + (bind-context-vars + (base-dir) + (install-directory base-dir))) (task "Create test file from string content" - (lambda (ctx) - (install-file ctx (file-name-join* (context-ref ctx 'base-dir) "foo") - #:content "Hello, world!\n"))) + (bind-context-vars + (base-dir) + (install-file (file-name-join* base-dir "foo") #:content "Hello, world!\n"))) (task "Create test file from local source" - (lambda (ctx) - (install-file ctx (file-name-join* (context-ref ctx 'base-dir) "bar") - #:local-src (file-name-join* (context-ref ctx 'base-dir) "foo"))) + (bind-context-vars + (base-dir) + (install-file (file-name-join* base-dir "bar") #:local-src (file-name-join* base-dir "foo"))) #:triggers '(fritz)) (task "Create test file from remote source" - (lambda (ctx) - (install-file ctx (file-name-join* (context-ref ctx 'base-dir) "baz") - #:remote-src (file-name-join* (context-ref ctx 'base-dir) "bar"))) + (bind-context-vars + (base-dir) + (install-file (file-name-join* base-dir "baz") #:remote-src (file-name-join* base-dir "bar"))) #:triggers '(frobnicate))) #:handlers `((frobnicate . ,(handler "Frobnicate" (const #t))) (fritz . ,(handler "Fritz" (const #t)))