[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dtache 763246bffe 026/158: Remove explicit dependency o
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dtache 763246bffe 026/158: Remove explicit dependency on dtache-env |
Date: |
Wed, 19 Jan 2022 18:57:41 -0500 (EST) |
branch: externals/dtache
commit 763246bffe18e41edfd8bd1bcddb12241f69b688
Author: Niklas Eklund <niklas.eklund@zenseact.com>
Commit: Niklas Eklund <niklas.eklund@posteo.net>
Remove explicit dependency on dtache-env
The package should be able to run without dtache-env. In this commit
the package is restructured to be able to run without dtache-env. The
consequence of not using dtache-env is that dtache can't automatically
label the status of a session. The README has been updated to reflect
this change.
---
README.org | 35 ++++++++++-------------------------
dtache-env | 9 +++++++++
dtache.el | 51 ++++++++++++++++++++++++++++++---------------------
3 files changed, 49 insertions(+), 46 deletions(-)
diff --git a/README.org b/README.org
index 101aa9099d..b08545864f 100644
--- a/README.org
+++ b/README.org
@@ -52,30 +52,6 @@ A minimal configuration for =dtache=.
(setq dtache-session-directory (expand-file-name "dtache"
(temporary-file-directory))))
#+end_src
-** The dtache-env script
-
-Create an executable shell script, named =dtache-env=, which will be used as a
wrapper for the shell commands we are running.
-
-#+begin_src sh
- #!/usr/bin/env bash
-
- dtache_command="$*"
-
- if eval "$dtache_command"; then
- echo -e "\nDtache session finished"
- else
- echo -e "\nDtache exited abnormally with code $?"
- fi
-#+end_src
-
-Either put it somewhere in path or customize the =dtache-env= variable so that
it refers to the script.
-
-#+begin_src elisp
- (setq dtache-env "/path/to/dtache-env")
-#+end_src
-
-This script is necessary in order for =dtache= to get information about the
exit status of a session.
-
* Commands
** Creating a session
@@ -159,6 +135,16 @@ Add [[https://github.com/oantolin/embark/][embark]]
actions to =dtache-open-sess
#+end_src
* Tips & Tricks
+** Automatic status labeling
+
+The =dtache-env= script found in this repository can be used to execute shell
commands in a controlled environment. This environment makes sure that the exit
status is present in the session's output. This makes it possible for =dtache=
to automatically label a session with either =success= or =failure=.
+
+Add the following to the configuration in order to take advantage of this
feature.
+
+#+begin_src elisp
+ (setq dtache-env "/path/to/dtache-env")
+#+end_src
+
** System notifications
By default =dtache= uses the echo area to notify the user when a session has
finished. An alternative is to utilize the
[[https://github.com/jwiegley/alert][alert]] package to get a system
notification instead.
@@ -187,7 +173,6 @@ With the usage of =advice= the user can override the
default implantation with t
#+begin_src elisp
(advice-add 'dtache-session-finish-notification :override
#'dtache-session-finish-alert)
#+end_src
-
** Metadata annotators
The user can configure any number of annotators to run upon creation of a
session. Here is an example of an annotator which captures the branch name if
the session is started in a git repository.
diff --git a/dtache-env b/dtache-env
new file mode 100755
index 0000000000..d03c4bbebc
--- /dev/null
+++ b/dtache-env
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+
+dtache_command="$*"
+
+if eval "$dtache_command"; then
+ echo -e "\nDtache session finished"
+else
+ echo -e "\nDtache exited abnormally with code $?"
+fi
diff --git a/dtache.el b/dtache.el
index d6102d699b..e6c81d6924 100644
--- a/dtache.el
+++ b/dtache.el
@@ -59,7 +59,7 @@
"The name of the `dtach' program.")
(defvar dtache-shell-program "bash"
"Shell to run the dtach command in.")
-(defvar dtache-env "dtache-env"
+(defvar dtache-env nil
"The name of the `dtache' program.")
(defvar dtache-max-command-length 90
"Maximum length of displayed command.")
@@ -73,7 +73,7 @@
"Custom function to use to open a session.")
(defvar dtache-session-callback-function nil
"Custom function to callback when a session finish.")
-(defvar dtache-session-status-function #'dtache-session-exit-code-status
+(defvar dtache-session-status-function nil
"Custom function to deduce the status of a session.")
(defvar dtache-compile-hooks nil
"Hooks to run when compiling a session.")
@@ -101,6 +101,7 @@
(open-function nil :read-only t)
(callback-function nil :read-only t)
(status-function nil :read-only t)
+ (env nil :read-only t)
(working-directory nil :read-only t)
(creation-time nil :read-only t)
(session-directory nil :read-only t)
@@ -379,8 +380,9 @@ Sessions running on current host or localhost are updated."
(setf (dtache--session-active session) nil)
(setf (dtache--session-duration session)
(dtache--duration session))
- (when-let ((status (dtache--session-status-function session)))
- (setf (dtache--session-status session) (funcall status session)))
+ (if-let ((status (dtache--session-status-function session)))
+ (setf (dtache--session-status session) (funcall status session))
+ (setf (dtache--session-status session)
(dtache-session-exit-code-status session)))
(dtache-session-finish-notification session)
(when-let ((callback (dtache--session-callback-function session)))
(funcall callback session))))
@@ -445,18 +447,21 @@ Sessions running on current host or localhost are
updated."
(defun dtache-session-exit-code-status (session)
"Return status based on exit-code in SESSION."
- (with-temp-buffer
- (insert-file-contents (dtache-session-file session 'log))
- (goto-char (point-max))
- (if (string-match "Dtache session finished" (thing-at-point 'line t))
- 'success
- 'failure)))
+ (if (null dtache-env)
+ 'unknown
+ (with-temp-buffer
+ (insert-file-contents (dtache-session-file session 'log))
+ (goto-char (point-max))
+ (if (string-match "Dtache session finished" (thing-at-point 'line t))
+ 'success
+ 'failure))))
(defun dtache-session-output (session)
"Return content of SESSION's output."
(let* ((filename (dtache-session-file session 'log))
(status (dtache--session-status session))
- (remove-dtache-message (not (eq status 'unknown))))
+ (remove-dtache-message (and (dtache--session-env session)
+ (not (eq status 'unknown)))))
(with-temp-buffer
(insert-file-contents filename)
(goto-char (point-max))
@@ -480,10 +485,9 @@ Sessions running on current host or localhost are
updated."
(dtache-open-output session))
((eq 'failure (dtache--session-status session))
(dtache-compile-session session))
- ;; TODO: Inactive sessions should never have status unknown,
- ;; need to investigate why that happens
- (t (progn (message "Unknown status of session.")
- (dtache-open-output session)))))
+ ((eq 'unknown (dtache--session-status session))
+ (dtache-open-output session))
+ (t (message "Dtache session is in an unexpected state."))))
;;;;; Other
@@ -574,6 +578,7 @@ Sessions running on current host or localhost are updated."
:callback-function
dtache-session-callback-function
:status-function
dtache-session-status-function
:working-directory
(dtache-get-working-directory)
+ :env dtache-env
:redirect-only (dtache-redirect-only-p
command)
:creation-time (time-to-seconds
(current-time))
:status 'unknown
@@ -749,8 +754,9 @@ Sessions running on current host or localhost are updated."
(dtache--db-update-session session)
;; Update status
- (when-let ((status (dtache--session-status-function session)))
- (setf (dtache--session-status session) (funcall status session)))
+ (if-let ((status (dtache--session-status-function session)))
+ (setf (dtache--session-status session) (funcall status session))
+ (setf (dtache--session-status session)
(dtache-session-exit-code-status session)))
;; Send notification
(dtache-session-finish-notification session)
@@ -783,10 +789,13 @@ Sessions running on current host or localhost are
updated."
If SESSION is redirect-only fallback to a command that doesn't rely on tee.
Otherwise use tee to log stdout and stderr individually."
- (let* ((command (string-join
- `(,dtache-env
- ,dtache-shell-program "-c" "-i"
- ,(shell-quote-argument (format "\"%s\""
(dtache--session-command session)))) " "))
+ (let* ((command
+ (if dtache-env
+ (string-join
+ `(,dtache-env
+ ,dtache-shell-program "-c"
+ ,(shell-quote-argument (format "\"%s\""
(dtache--session-command session)))) " ")
+ `(,dtache-shell-program "-c" ,(shell-quote-argument
(dtache--session-command session)))))
(directory (dtache--session-session-directory session))
(file-name (dtache--session-id session))
(log (concat directory file-name ".log")))
- [elpa] externals/dtache b75af1b9a7 059/158: Update notification setup, (continued)
- [elpa] externals/dtache b75af1b9a7 059/158: Update notification setup, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache b47bc3be09 061/158: Update copyright years, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 182ab7ccc6 064/158: Add integration with consult, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache ea6d8ae426 068/158: Add missing autoloads, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache e2efe466e0 076/158: Improve error handling with dtache-valid-session, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 79f1d905a9 078/158: Add example of how to enhance a command with dtach, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache dae6db33db 083/158: Fix various minor problems, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 52e839ff4a 007/158: Update README with links, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 7e8727f3a2 020/158: Add TODO to investigate unknown inactive sessions, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache b94baaeecd 021/158: Fix bug in setup notification, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 763246bffe 026/158: Remove explicit dependency on dtache-env,
ELPA Syncer <=
- [elpa] externals/dtache 087e8f4c73 019/158: Update README, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache d574161815 042/158: Simplify buffer handling, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 1878cefb2f 038/158: Remove embark dependency, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 3c61776c7f 014/158: Fix dtache initialization, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 7c07950642 043/158: Implement better encapsulation of database, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 42569d1c5f 036/158: Update broken tests, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache ddf9bb6ade 039/158: Add action map example, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache c70c9366a5 028/158: Update test to test with/without dtache-env, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache d5aa90356a 029/158: Add CHANGELOG to project, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 4751b4d812 046/158: Implement a general timer function, ELPA Syncer, 2022/01/19