summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Bennée <alex.bennee@linaro.org>2017-04-18 12:47:32 +0100
committerAlex Bennée <alex.bennee@linaro.org>2017-04-18 12:47:32 +0100
commit1d858d24d8030c216a557aba3c8eecf3d2e5831e (patch)
tree1ff5d8508e662ef43be8ec07bedf9a0cdcbe5966
parentb0a4902d986ea38edce32581f7447b3c853fc7d2 (diff)
lava-mode: move utility functions into common code
-rw-r--r--lava-json-mode.el32
-rw-r--r--lava-mode.el37
2 files changed, 37 insertions, 32 deletions
diff --git a/lava-json-mode.el b/lava-json-mode.el
index dc4156f..4bf45a1 100644
--- a/lava-json-mode.el
+++ b/lava-json-mode.el
@@ -200,38 +200,6 @@ value if nothing is set."
"Return the current test repository."
lava-mode-test-repository)
-(defun lava-mode-get-pubkey ()
- "Return the public key for the user"
- (s-trim (shell-command-to-string "cat ~/.ssh/id_rsa.pub")))
-
-(defun lava-mode-end-of-day-timeout (&optional end-of-day)
- "Return the number of seconds until the `END-OF-DAY'.
-This is intended to ensure hacking sessions don't hang around for too
- long but also you don't end up leaving big timeouts in your
- definitions."
- (unless end-of-day
- (setq end-of-day "18:00"))
- (let* ((today (format-time-string "%e %b %Y"))
- (tz (format-time-string "%Z"))
- (then (format "%s %s %s" today end-of-day tz)))
- (let ((secs (round (time-to-seconds
- (time-subtract
- (date-to-time then)
- (current-time))))))
- (when (< secs 0)
- (setq secs (+ secs (* 24 60 60))))
- secs)))
-
-(defun lava-mode-find-latest-file (path pattern &optional nth)
- "Search `PATH' to find the latest file matching `PATTERN' (optionally `NTH').
-If `nth' is defined then find the nth latest file"
- (let* ((all-files (directory-files path t pattern)))
- (file-name-nondirectory
- (nth (or nth 0)
- (-sort #'(lambda (fileA fileB)
- (not (time-less-p (nth 5 (file-attributes fileA))
- (nth 5 (file-attributes fileB))))) all-files)))))
-
(defun lava-mode-device-running-latest (name-or-list-of-names)
"Return the device which is running the latest version of `NAME'."
(let* ((jobs
diff --git a/lava-mode.el b/lava-mode.el
index c77f962..9ce2a03 100644
--- a/lava-mode.el
+++ b/lava-mode.el
@@ -94,5 +94,42 @@ If the prefix is specified twice don't submit the job at all."
(kill-buffer expanded-buffer))
response))
+;; Utility functions
+;;
+;; These are useful utility functions to be called from JSON/YAML expansions
+;;
+
+(defun lava-mode-get-pubkey ()
+ "Return the public key for the user"
+ (s-trim (shell-command-to-string "cat ~/.ssh/id_rsa.pub")))
+
+(defun lava-mode-end-of-day-timeout (&optional end-of-day)
+ "Return the number of seconds until the `END-OF-DAY'.
+This is intended to ensure hacking sessions don't hang around for too
+ long but also you don't end up leaving big timeouts in your
+ definitions."
+ (unless end-of-day
+ (setq end-of-day "18:00"))
+ (let* ((today (format-time-string "%e %b %Y"))
+ (tz (format-time-string "%Z"))
+ (then (format "%s %s %s" today end-of-day tz)))
+ (let ((secs (round (time-to-seconds
+ (time-subtract
+ (date-to-time then)
+ (current-time))))))
+ (when (< secs 0)
+ (setq secs (+ secs (* 24 60 60))))
+ secs)))
+
+(defun lava-mode-find-latest-file (path pattern &optional nth)
+ "Search `PATH' to find the latest file matching `PATTERN' (optionally `NTH').
+If `nth' is defined then find the nth latest file"
+ (let* ((all-files (directory-files path t pattern)))
+ (file-name-nondirectory
+ (nth (or nth 0)
+ (-sort #'(lambda (fileA fileB)
+ (not (time-less-p (nth 5 (file-attributes fileA))
+ (nth 5 (file-attributes fileB))))) all-files)))))
+
(provide 'lava-mode)
;;; lava-mode.el ends here