From 56405829f2f9f2adadb42135ffaec37725759b57 Mon Sep 17 00:00:00 2001 From: "Christopher R. Nelson" Date: Mon, 19 Jun 2023 15:31:49 -0400 Subject: feat: more proper build infra - scripts should be scripts/command-name.in - tests file shouldn't mismatch style from app --- .gitignore | 1 + reading-heap.scm | 74 ---------------------------- scripts/rh-client.in | 123 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/rh-client.scm.in | 123 ----------------------------------------------- scripts/rh-server.in | 72 +++++++++++++++++++++++++++ tests/sample.json | 5 -- 6 files changed, 196 insertions(+), 202 deletions(-) mode change 100755 => 100644 reading-heap.scm create mode 100755 scripts/rh-client.in delete mode 100755 scripts/rh-client.scm.in create mode 100755 scripts/rh-server.in delete mode 100644 tests/sample.json diff --git a/.gitignore b/.gitignore index 0a123e7..ba1d131 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +# hall-added files *.eps *.go *.log diff --git a/reading-heap.scm b/reading-heap.scm old mode 100755 new mode 100644 index a7e3044..e69de29 --- a/reading-heap.scm +++ b/reading-heap.scm @@ -1,74 +0,0 @@ -#!/usr/bin/env guile -!# -(define-module (reading-heap)) - -(use-modules (srfi srfi-1) - (config) - (config api) - (config licenses) - (config parser sexp) - (reading-heap heap) - (reading-heap media) - (reading-heap zmq)) - -(define config - (configuration - (name 'rh-server) - (synopsis "client for reading-heap") - (keywords - (list - (setting - (name 'media-library) - (synopsis "media library location") - (default (string-append (or (getenv "XDG_DATA_HOME") - (string-append (getenv "HOME") - "/.local/share")) - "/media-library")) - (character #f)) - (setting - (name 'service-socket) - (synopsis "socket for communication with the service") - (default (string-append "ipc://" (or (getenv "XDG_RUNTIME_DIR") - "/tmp") - "/reading-heap.sock")) - (character #f)) - (switch - (name 'write) - (synopsis "write the default config") - (default #f) - (test boolean?) - (character #f)) - (switch - (name 'serve) - (synopsis "server the media heap") - (default #f) - (test boolean?) - (character #t)) - )) - (directory (list (in-home ".reading-heap/") - (path (given - (string-append (or (getenv "XDG_CONFIG_HOME") - (string-append (getenv "HOME") - "/.config")) - "/reading-heap/")) - (eager? #t)))) - (parser sexp-parser) - (copyright '(2023)) - (version "0.1") - (license agpl3+) - (author "Christopher R. Nelson"))) - -(define (main cmd-line) - (let ((options (getopt-config-auto cmd-line config))) - (when (option-ref options 'write) - (options-write options)) - (when (option-ref options 'serve) - (let* ((media (filetree->media-list (option-ref options 'media-library))) - (priorities (map media-priority media)) - (heap (fold heap-insert 'E priorities media))) - (server-setup (option-ref options 'service-socket)) - (rh-receive heap - (option-ref options 'media-library) - (string-append (option-ref options 'media-library) "/archive/")))))) - -(main (command-line)) diff --git a/scripts/rh-client.in b/scripts/rh-client.in new file mode 100755 index 0000000..64dfde6 --- /dev/null +++ b/scripts/rh-client.in @@ -0,0 +1,123 @@ +#!/usr/bin/env guile +!# +(use-modules (simple-zmq) + (config) + (config api) + (config parser sexp) + (config licenses) + (json)) + +(define config + (configuration + (name 'rh-client) + (synopsis "client for reading-heap") + (keywords + (list + (setting + (name 'service-socket) + (synopsis "socket for communication with the service") + (default (string-append "ipc://" (or (getenv "XDG_RUNTIME_DIR") + "/tmp") + "/reading-heap.sock"))) + (switch + (name 'write) + (synopsis "write the default config") + (default #f) + (test boolean?) + (character #f)) + (switch + (name 'title) + (synopsis "title of the new media") + (default "Foundation Trilogy") + (test string?) + (character #t)) + (switch + (name 'author) + (synopsis "author of the new media") + (default "Isaac Asimov") + (test string?) + (character #t)) + (switch + (name 'location) + (synopsis "location of the new media") + (default "https://openlibrary.org/books/OL20930675M/The_foundation_trilogy") + (test string?) + (character #t)) + (switch + (name 'priority) + (synopsis "priority of the new media") + (default "1") + (test string?) + (character #t)))) + (subcommands + (list + (configuration + (name 'next) + (synopsis "get the next media to consume") + (wanted '((keywords . (service-socket))))) + (configuration + (name 'new) + (synopsis "add new media to the heap") + (wanted '((keywords . (service-socket title author location priority))))) + (configuration + (name 'consume) + (synopsis "remove the next media from the heap") + (wanted '((keywords . (service-socket))))))) + (directory (list (in-home ".reading-heap/") + (path (given + (string-append (or (getenv "XDG_CONFIG_HOME") + (string-append (getenv "HOME") + "/.config")) + "/reading-heap/")) + (eager? #t)))) + (parser sexp-parser))) + + +(define context (zmq-create-context)) +(define client-socket (zmq-create-socket context ZMQ_REQ)) + +(define (client-setup sock) + (zmq-connect client-socket sock)) + +(define (rh-client-next) + (zmq-send client-socket "next") + (let ((msg (zmq-receive-bytevector client-socket 1500))) + (display (bv->string msg)))) + +(define (rh-client-new json) + (zmq-send client-socket "new") + (zmq-receive client-socket 1500) + (zmq-send client-socket json) + (display (zmq-receive client-socket 1500)) + (zmq-send client-socket "next") + (display (zmq-receive client-socket 1500))) + +(define (rh-client-consumed) + (zmq-send client-socket "consume") + (display (zmq-receive client-socket 1500))) + +(define (json-from-args priority title author location) + (scm->json-string `(("priority" . ,priority) + ("title" . ,title) + ("author" . ,author) + ("location" . ,location)))) + +(define (main cmd-line) + (let ((options (getopt-config-auto cmd-line config))) + (when (option-ref options 'write) + (options-write options)) + (cond ((string=? (cadr (full-command options)) "next") + (client-setup (option-ref options 'service-socket)) + (rh-client-next)) + ((string=? (cadr (full-command options)) "new") + (client-setup (option-ref options 'service-socket)) + (rh-client-new (json-from-args (string->number (option-ref options 'priority)) + (option-ref options 'title) + (option-ref options 'author) + (option-ref options 'location)))) + ((string=? (cadr (full-command options)) "consume") + (client-setup (option-ref options 'service-socket)) + (rh-client-consumed)) + (#t (emit-help options))))) + +(main (command-line)) diff --git a/scripts/rh-client.scm.in b/scripts/rh-client.scm.in deleted file mode 100755 index 64dfde6..0000000 --- a/scripts/rh-client.scm.in +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env guile -!# -(use-modules (simple-zmq) - (config) - (config api) - (config parser sexp) - (config licenses) - (json)) - -(define config - (configuration - (name 'rh-client) - (synopsis "client for reading-heap") - (keywords - (list - (setting - (name 'service-socket) - (synopsis "socket for communication with the service") - (default (string-append "ipc://" (or (getenv "XDG_RUNTIME_DIR") - "/tmp") - "/reading-heap.sock"))) - (switch - (name 'write) - (synopsis "write the default config") - (default #f) - (test boolean?) - (character #f)) - (switch - (name 'title) - (synopsis "title of the new media") - (default "Foundation Trilogy") - (test string?) - (character #t)) - (switch - (name 'author) - (synopsis "author of the new media") - (default "Isaac Asimov") - (test string?) - (character #t)) - (switch - (name 'location) - (synopsis "location of the new media") - (default "https://openlibrary.org/books/OL20930675M/The_foundation_trilogy") - (test string?) - (character #t)) - (switch - (name 'priority) - (synopsis "priority of the new media") - (default "1") - (test string?) - (character #t)))) - (subcommands - (list - (configuration - (name 'next) - (synopsis "get the next media to consume") - (wanted '((keywords . (service-socket))))) - (configuration - (name 'new) - (synopsis "add new media to the heap") - (wanted '((keywords . (service-socket title author location priority))))) - (configuration - (name 'consume) - (synopsis "remove the next media from the heap") - (wanted '((keywords . (service-socket))))))) - (directory (list (in-home ".reading-heap/") - (path (given - (string-append (or (getenv "XDG_CONFIG_HOME") - (string-append (getenv "HOME") - "/.config")) - "/reading-heap/")) - (eager? #t)))) - (parser sexp-parser))) - - -(define context (zmq-create-context)) -(define client-socket (zmq-create-socket context ZMQ_REQ)) - -(define (client-setup sock) - (zmq-connect client-socket sock)) - -(define (rh-client-next) - (zmq-send client-socket "next") - (let ((msg (zmq-receive-bytevector client-socket 1500))) - (display (bv->string msg)))) - -(define (rh-client-new json) - (zmq-send client-socket "new") - (zmq-receive client-socket 1500) - (zmq-send client-socket json) - (display (zmq-receive client-socket 1500)) - (zmq-send client-socket "next") - (display (zmq-receive client-socket 1500))) - -(define (rh-client-consumed) - (zmq-send client-socket "consume") - (display (zmq-receive client-socket 1500))) - -(define (json-from-args priority title author location) - (scm->json-string `(("priority" . ,priority) - ("title" . ,title) - ("author" . ,author) - ("location" . ,location)))) - -(define (main cmd-line) - (let ((options (getopt-config-auto cmd-line config))) - (when (option-ref options 'write) - (options-write options)) - (cond ((string=? (cadr (full-command options)) "next") - (client-setup (option-ref options 'service-socket)) - (rh-client-next)) - ((string=? (cadr (full-command options)) "new") - (client-setup (option-ref options 'service-socket)) - (rh-client-new (json-from-args (string->number (option-ref options 'priority)) - (option-ref options 'title) - (option-ref options 'author) - (option-ref options 'location)))) - ((string=? (cadr (full-command options)) "consume") - (client-setup (option-ref options 'service-socket)) - (rh-client-consumed)) - (#t (emit-help options))))) - -(main (command-line)) diff --git a/scripts/rh-server.in b/scripts/rh-server.in new file mode 100755 index 0000000..9749ec2 --- /dev/null +++ b/scripts/rh-server.in @@ -0,0 +1,72 @@ +#!/usr/bin/env guile +!# +(use-modules (srfi srfi-1) + (config) + (config api) + (config licenses) + (config parser sexp) + (reading-heap heap) + (reading-heap media) + (reading-heap zmq)) + +(define config + (configuration + (name 'rh-server) + (synopsis "client for reading-heap") + (keywords + (list + (setting + (name 'media-library) + (synopsis "media library location") + (default (string-append (or (getenv "XDG_DATA_HOME") + (string-append (getenv "HOME") + "/.local/share")) + "/media-library")) + (character #f)) + (setting + (name 'service-socket) + (synopsis "socket for communication with the service") + (default (string-append "ipc://" (or (getenv "XDG_RUNTIME_DIR") + "/tmp") + "/reading-heap.sock")) + (character #f)) + (switch + (name 'write) + (synopsis "write the default config") + (default #f) + (test boolean?) + (character #f)) + (switch + (name 'serve) + (synopsis "server the media heap") + (default #f) + (test boolean?) + (character #t)) + )) + (directory (list (in-home ".reading-heap/") + (path (given + (string-append (or (getenv "XDG_CONFIG_HOME") + (string-append (getenv "HOME") + "/.config")) + "/reading-heap/")) + (eager? #t)))) + (parser sexp-parser) + (copyright '(2023)) + (version "0.1") + (license agpl3+) + (author "Christopher R. Nelson"))) + +(define (main cmd-line) + (let ((options (getopt-config-auto cmd-line config))) + (when (option-ref options 'write) + (options-write options)) + (when (option-ref options 'serve) + (let* ((media (filetree->media-list (option-ref options 'media-library))) + (priorities (map media-priority media)) + (heap (fold heap-insert 'E priorities media))) + (server-setup (option-ref options 'service-socket)) + (rh-receive heap + (option-ref options 'media-library) + (string-append (option-ref options 'media-library) "/archive/")))))) + +(main (command-line)) diff --git a/tests/sample.json b/tests/sample.json deleted file mode 100644 index b2fbffe..0000000 --- a/tests/sample.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "title": "Foundation Trilogy", - "author": "Isaac Asimov", - "priority": 1 -} -- cgit v1.2.3