diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2023-03-16 13:18:41 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2023-03-16 19:05:09 -0700 |
commit | 4143535ae5eb9385a86240e152be873cc4348e03 (patch) | |
tree | 13cf54b103ef4d8a4540dc87aad7998797cb41e0 /src/connection.lisp | |
parent | a2f0f9376e110d6c930b0cd3cf533c7fd3b7b917 (diff) | |
download | consfigurator-4143535ae5eb9385a86240e152be873cc4348e03.tar.gz |
add regexp trailing option to attempt to parse matches as numbers
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/connection.lisp')
-rw-r--r-- | src/connection.lisp | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/src/connection.lisp b/src/connection.lisp index ffb0372..d1e78cb 100644 --- a/src/connection.lisp +++ b/src/connection.lisp @@ -216,17 +216,11 @@ connattr, or nil if nothing should be propagated.") (defmethod connection-connattr ((connection connection) (k (eql :remote-uid))) - (multiple-value-bind (match groups) - (re:scan-to-strings "^uid=([0-9]+)" - (connection-connattr connection 'id)) - (and match (parse-integer (elt groups 0))))) + (#1~/^uid=(\d+)/p (connection-connattr connection 'id))) (defmethod connection-connattr ((connection connection) (k (eql :remote-gid))) - (multiple-value-bind (match groups) - (re:scan-to-strings "\\) gid=([0-9]+)" - (connection-connattr connection 'id)) - (and match (parse-integer (elt groups 0))))) + (#1~/\) gid=(\d+)/p (connection-connattr connection 'id))) (defmethod connection-connattr ((connection connection) (k (eql :remote-home))) @@ -614,16 +608,11 @@ specification of POSIX ls(1))." "Get the time of the last reboot, rounded down to the nearest minute." ;; The '-b' option to who(1) is specified in POSIX, though not the output ;; format; this parse is based on GNU coreutils who(1). - (multiple-value-bind (match groups) - (re:scan-to-strings - "([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2})" - (car (runlines :env '(:TZ "UTC") "who" "-b"))) - (if match - (let ((groups (map 'vector #'parse-integer groups))) - (encode-universal-time 0 (elt groups 4) (elt groups 3) - (elt groups 2) (elt groups 1) (elt groups 0) - 0)) - (failed-change "Could not determine time of remote's last reboot.")))) + (aif (#~/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})/p + (car (runlines :env '(:TZ "UTC") "who" "-b"))) + (encode-universal-time 0 (elt it 4) (elt it 3) (elt it 2) (elt it 1) + (elt it 0) 0) + (failed-change "Could not determine time of remote's last reboot."))) (defun remote-executable-find (executable) (zerop (mrun :for-exit "command" "-v" executable))) |