emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/dtache ab3fc736c5 2/3: Update session host


From: ELPA Syncer
Subject: [elpa] externals/dtache ab3fc736c5 2/3: Update session host
Date: Sat, 22 Jan 2022 13:57:30 -0500 (EST)

branch: externals/dtache
commit ab3fc736c582379583029641a70aaa9fae18cad6
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>

    Update session host
    
    Change the host to a cons with hostname and type.
---
 README.org          |  2 +-
 dtache-consult.el   |  8 ++++----
 dtache-eshell.el    |  4 ++--
 dtache-shell.el     |  4 ++--
 dtache.el           | 27 +++++++++++++--------------
 test/dtache-test.el | 24 ++++++++++++------------
 6 files changed, 34 insertions(+), 35 deletions(-)

diff --git a/README.org b/README.org
index fe80bc370f..2994db487f 100644
--- a/README.org
+++ b/README.org
@@ -221,7 +221,7 @@ By default =dtache= uses the built in =notifications= 
library to issue a notific
   (defun my/dtache-state-transition-alert-notification (session)
     "Send an `alert' notification when SESSION becomes inactive."
     (let ((status (car (dtache--session-status session)))
-          (host (plist-get (dtache--session-host session) :name)))
+          (host (car (dtache--session-host session))))
       (alert (dtache--session-command session)
        :title (pcase status
                 ('success (format "Dtache finished [%s]" host))
diff --git a/dtache-consult.el b/dtache-consult.el
index ab809799f4..2fb9f8ea6e 100644
--- a/dtache-consult.el
+++ b/dtache-consult.el
@@ -129,7 +129,7 @@ See `consult-multi' for a description of the source values."
        (mapcar #'car
                (seq-filter
                 (lambda (x)
-                  (eq 'local (plist-get (dtache--session-host (cdr x)) :type)))
+                  (eq 'local (cdr (dtache--session-host (cdr x)))))
                 (dtache-session-candidates (dtache-get-sessions)))))
     "Local host `dtache' sessions as a source for `consult'."))
 
@@ -144,7 +144,7 @@ See `consult-multi' for a description of the source values."
        (mapcar #'car
                (seq-filter
                 (lambda (x)
-                  (eq 'remote (plist-get (dtache--session-host (cdr x)) 
:type)))
+                  (eq 'remote (cdr (dtache--session-host (cdr x)))))
                 (dtache-session-candidates (dtache-get-sessions))))))
   "Remote host `dtache' sessions as a source for `consult'.")
 
@@ -156,10 +156,10 @@ See `consult-multi' for a description of the source 
values."
     :action (lambda (x) (dtache-open-session (dtache--decode-session x)))
     :items
     ,(lambda ()
-       (let ((host-name (plist-get (dtache--host) :name)))
+       (let ((host-name (car (dtache--host))))
          (mapcar #'car (seq-filter
                         (lambda (x)
-                          (string= (plist-get (dtache--session-host (cdr x)) 
:name) host-name))
+                          (string= (car (dtache--session-host (cdr x))) 
host-name))
                         (dtache-session-candidates (dtache-get-sessions)))))))
   "Current host `dtache' sessions as a source for `consult'.")
 
diff --git a/dtache-eshell.el b/dtache-eshell.el
index 3af0d0f051..b6186ed53e 100644
--- a/dtache-eshell.el
+++ b/dtache-eshell.el
@@ -51,11 +51,11 @@
 
 (defun dtache-eshell-select-session ()
   "Return selected session."
-  (let* ((host-name (plist-get (dtache--host) :name))
+  (let* ((host-name (car (dtache--host)))
          (sessions
           (thread-last (dtache-get-sessions)
                        (seq-filter (lambda (it)
-                                     (string= (plist-get (dtache--session-host 
it) :name) host-name)))
+                                     (string= (car (dtache--session-host it)) 
host-name)))
                        (seq-filter #'dtache--determine-session-state))))
     (dtache-completing-read sessions)))
 
diff --git a/dtache-shell.el b/dtache-shell.el
index 46119a9bcf..d3069b0266 100644
--- a/dtache-shell.el
+++ b/dtache-shell.el
@@ -53,11 +53,11 @@
 
 (defun dtache-shell-select-session ()
   "Return selected session."
-  (let* ((host-name (plist-get (dtache--host) :name))
+  (let* ((host-name (car (dtache--host)))
          (sessions
           (thread-last (dtache-get-sessions)
                        (seq-filter (lambda (it)
-                                     (string= (plist-get (dtache--session-host 
it) :name) host-name)))
+                                     (string= (car (dtache--session-host it)) 
host-name)))
                        (seq-filter (lambda (it) (eq 'active 
(dtache--determine-session-state it)))))))
     (dtache-completing-read sessions)))
 
diff --git a/dtache.el b/dtache.el
index 8b9953dd98..faf5cb1eb9 100644
--- a/dtache.el
+++ b/dtache.el
@@ -139,7 +139,7 @@ Valid values are: create, new and attach")
 (defvar dtache-metadata-annotators-alist nil
   "An alist of annotators for metadata.")
 
-(defconst dtache-session-version "0.3.5"
+(defconst dtache-session-version "0.3.6"
   "The version of `dtache-session'.
 This version is encoded as [package-version].[revision].")
 
@@ -484,11 +484,11 @@ active session.  For sessions created with 
`dtache-compile' or
 (defun dtache-delete-sessions (&optional all-hosts)
   "Delete `dtache' sessions which belong to the current host, unless 
ALL-HOSTS."
   (interactive "P")
-  (let* ((host-name (plist-get (dtache--host) :name))
+  (let* ((host-name (car (dtache--host)))
          (sessions (if all-hosts
                        (dtache-get-sessions)
                      (seq-filter (lambda (it)
-                                   (string= (plist-get (dtache--session-host 
it) :name) host-name))
+                                   (string= (car (dtache--session-host it)) 
host-name))
                                  (dtache-get-sessions)))))
     (seq-do #'dtache--db-remove-entry sessions)))
 
@@ -582,7 +582,7 @@ Optionally SUPPRESS-OUTPUT."
 
     ;; Remove missing local sessions
     (thread-last (dtache--db-get-sessions)
-                 (seq-filter (lambda (it) (eq 'local (plist-get 
(dtache--session-host it) :type))))
+                 (seq-filter (lambda (it) (eq 'local (cdr 
(dtache--session-host it)))))
                  (seq-filter #'dtache--session-missing-p)
                  (seq-do #'dtache--db-remove-entry))
 
@@ -616,7 +616,7 @@ If session is not valid trigger an automatic cleanup on 
SESSION's host."
     (if (not (dtache--session-missing-p session))
         t
       (let ((host (dtache--session-host session)))
-        (message "Session does not exist. Initiate sesion cleanup on host %s" 
(plist-get host :name))
+        (message "Session does not exist. Initiate sesion cleanup on host %s" 
(car host))
         (dtache--cleanup-host-sessions host)
         nil))))
 
@@ -643,13 +643,13 @@ This function uses the echo area."
                   ('success "Dtache finished")
                   ('failure "Dtache failed")
                   ('unknown "Dtache finished"))))
-    (message "%s [%s]: %s" status (plist-get (dtache--session-host session) 
:name) (dtache--session-command session))))
+    (message "%s [%s]: %s" status (car (dtache--session-host session)) 
(dtache--session-command session))))
 
 (defun dtache-state-transition-notifications-message (session)
   "Issue a notification when SESSION transitions from active to inactive.
 This function uses the `notifications' library."
   (let ((status (car (dtache--session-status session)))
-        (host (plist-get (dtache--session-host session) :name)))
+        (host (car (dtache--session-host session))))
     (notifications-notify
      :title (pcase status
               ('success (format "Dtache finished [%s]" host))
@@ -824,7 +824,7 @@ Optionally CONCAT the command return command into a string."
    #'identity
    `(,(format "Command: %s" (dtache--session-command session))
      ,(format "Working directory: %s" (dtache--working-dir-str session))
-     ,(format "Host: %s" (plist-get (dtache--session-host session) :name))
+     ,(format "Host: %s" (car (dtache--session-host session)))
      ,(format "Id: %s" (symbol-name (dtache--session-id session)))
      ,(format "Status: %s" (car (dtache--session-status session)))
      ,(format "Exit-code: %s" (cdr (dtache--session-status session)))
@@ -882,9 +882,9 @@ Optionally make the path LOCAL to host."
 
 (defun dtache--cleanup-host-sessions (host)
   "Run cleanuup on HOST sessions."
-  (let ((host-name (plist-get host :name)))
+  (let ((host-name (car host)))
     (thread-last (dtache--db-get-sessions)
-                 (seq-filter (lambda (it) (string= host-name (plist-get 
(dtache--session-host it) :name))))
+                 (seq-filter (lambda (it) (string= host-name (car 
(dtache--session-host it)))))
                  (seq-filter #'dtache--session-missing-p)
                  (seq-do #'dtache--db-remove-entry))))
 
@@ -1034,10 +1034,9 @@ If SESSION is nonattachable fallback to a command that 
doesn't rely on tee."
     (format "{ %s %s; } %s" env command redirect)))
 
 (defun dtache--host ()
-  "Return name of host."
+  "Return a cons with (host . type)."
   (let ((remote (file-remote-p default-directory)))
-    `(:type ,(if remote 'remote 'local)
-            :name ,(if remote (file-remote-p default-directory 'host) 
(system-name)))))
+    `(,(if remote (file-remote-p default-directory 'host) (system-name)) . 
,(if remote 'remote 'local))))
 
 (defun dtache--update-session-time (session &optional approximate)
   "Update SESSION's time property.
@@ -1174,7 +1173,7 @@ session and trigger a state transition."
 
 (defun dtache--host-str (session)
   "Return host name of SESSION."
-  (plist-get (dtache--session-host session) :name))
+  (car (dtache--session-host session)))
 
 ;;;; Minor modes
 
diff --git a/test/dtache-test.el b/test/dtache-test.el
index 7a855a92da..5268f6e7a0 100644
--- a/test/dtache-test.el
+++ b/test/dtache-test.el
@@ -141,20 +141,20 @@
 
 (ert-deftest dtache-test-host ()
   (cl-letf (((symbol-function #'system-name) (lambda () "localhost")))
-    (should (equal '(:type local :name "localhost") (dtache--host))))
+    (should (equal '("localhost" . local) (dtache--host))))
   (let ((default-directory "/ssh:remotehost:/home/user/git"))
-    (should (equal '(:type remote :name "remotehost") (dtache--host)))))
+    (should (equal '("remotehost" . remote) (dtache--host)))))
 
 (ert-deftest dtache-test-session-active-p ()
   (dtache-test--with-temp-database
-   (let ((session (dtache-test--create-session :command "foo" :host '(:type 
local :name "bar"))))
+   (let ((session (dtache-test--create-session :command "foo" :host '("bar" . 
local))))
      (should (eq 'active (dtache--determine-session-state session)))
      (dtache-test--change-session-state session 'deactivate)
      (should (eq 'inactive (dtache--determine-session-state session))))))
 
 (ert-deftest dtache-test-session-dead-p ()
   (dtache-test--with-temp-database
-   (let ((session (dtache-test--create-session :command "foo" :host '(:type 
local :name "bar"))))
+   (let ((session (dtache-test--create-session :command "foo" :host '("bar" . 
local))))
      (should (not (dtache--session-missing-p session)))
      (dtache-test--change-session-state session 'deactivate)
      (should (not (dtache--session-missing-p session)))
@@ -163,10 +163,10 @@
 
 (ert-deftest dtache-test-cleanup-host-sessions ()
   (dtache-test--with-temp-database
-   (cl-letf* ((session1 (dtache-test--create-session :command "foo" :host 
'(:type remote :name "remotehost")))
-              (session2 (dtache-test--create-session :command "bar" :host 
'(:type local :name "localhost")))
-              (session3 (dtache-test--create-session :command "baz" :host 
'(:type local :name "localhost")))
-              (host '(:type local :name "localhost"))
+   (cl-letf* ((session1 (dtache-test--create-session :command "foo" :host 
'("remotehost" . remote)))
+              (session2 (dtache-test--create-session :command "bar" :host 
'("localhost" . local)))
+              (session3 (dtache-test--create-session :command "baz" :host 
'("localhost" . local)))
+              (host '("localhost" . local))
               ((symbol-function #'dtache--host) (lambda () host)))
      ;; One inactive, one missing, one active
      (dtache-test--change-session-state session1 'deactivate)
@@ -191,21 +191,21 @@
 
 (ert-deftest dtache-test-db-insert-session ()
   (dtache-test--with-temp-database
-   (let* ((session (dtache-test--create-session :command "foo" :host '(:type 
local :name "localhost"))))
+   (let* ((session (dtache-test--create-session :command "foo" :host 
'("localhost" . local))))
      (should (equal (dtache--db-get-sessions) `(,session))))))
 
 (ert-deftest dtache-test-db-remove-session ()
   (dtache-test--with-temp-database
    (let* ((host '(:type local :name "host"))
-          (session1 (dtache-test--create-session :command "foo" :host '(:type 
local :name "host")))
-          (session2 (dtache-test--create-session :command "bar" :host '(:type 
local :name "host"))))
+          (session1 (dtache-test--create-session :command "foo" :host '("host" 
. local)))
+          (session2 (dtache-test--create-session :command "bar" :host '("host" 
. local))))
      (should (seq-set-equal-p `(,session1 ,session2) 
(dtache--db-get-sessions)))
      (dtache--db-remove-entry session1)
      (should (seq-set-equal-p `(,session2) (dtache--db-get-sessions))))))
 
 (ert-deftest dtache-test-db-update-session ()
   (dtache-test--with-temp-database
-   (let* ((session (dtache-test--create-session :command "foo" :host '(:type 
local :name "host")))
+   (let* ((session (dtache-test--create-session :command "foo" :host '("host" 
. local)))
           (id (dtache--session-id session))
           (copy))
      (setq copy (copy-dtache-session session))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]