guix-commits
[Top][All Lists]
Advanced

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

165/197: installer: New procedure key-value-slurp.


From: Danny Milosavljevic
Subject: 165/197: installer: New procedure key-value-slurp.
Date: Mon, 3 Jul 2017 20:37:19 -0400 (EDT)

dannym pushed a commit to branch wip-installer-2
in repository guix.

commit 9418604261236dd99569b5591f4d46c0a18b6804
Author: John Darrington <address@hidden>
Date:   Thu Feb 2 08:13:24 2017 +0100

    installer: New procedure key-value-slurp.
    
    * gnu/system/installer/utils.scm (key-value-slurp): New procedure.
    * gnu/system/installer/format.scm: Use it where appropriate.
---
 gnu/system/installer/format.scm | 12 +-----------
 gnu/system/installer/utils.scm  | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/gnu/system/installer/format.scm b/gnu/system/installer/format.scm
index f0a9aaf..b8c5f5e 100644
--- a/gnu/system/installer/format.scm
+++ b/gnu/system/installer/format.scm
@@ -36,17 +36,7 @@
 (include "i18n.scm")
 
 (define (device-attributes dev)
-  (slurp (string-append "blkid -o export " dev)
-         (lambda (x)
-           (let ((idx (string-index x #\=)))
-             (cons (string->symbol (string-fold
-                                    (lambda (c acc)
-                                      (string-append
-                                       acc
-                                       (make-string 1 (char-downcase c))))
-                                    ""
-                                    (substring x 0 idx)))
-                   (substring x (1+ idx) (string-length x)))))))
+  (key-value-slurp (string-append "blkid -o export " dev)))
 
 (define (device-fs-uuid dev)
   "Retrieve the UUID of the filesystem on DEV, where DEV is the name of the
diff --git a/gnu/system/installer/utils.scm b/gnu/system/installer/utils.scm
index e88524f..082dcc7 100644
--- a/gnu/system/installer/utils.scm
+++ b/gnu/system/installer/utils.scm
@@ -21,6 +21,7 @@
            justify*
            addstr*
            slurp
+            key-value-slurp
            quit-key?
 
            push-cursor
@@ -162,6 +163,22 @@ This version assumes some external entity puts in the 
carriage returns."
        result
        #f)))
 
+(define (key-value-slurp cmd)
+  "Slurp CMD, which is expected to give an output of key-value pairs -
+each pair terminated with a newline and the key/value delimited with ="
+  (slurp cmd
+         (lambda (x)
+           (let ((idx (string-index x #\=)))
+             (cons (string->symbol (string-fold
+                                    (lambda (c acc)
+                                      (string-append
+                                       acc
+                                       (make-string 1 (char-downcase c))))
+                                    ""
+                                    (substring x 0 idx)))
+                   (substring x (1+ idx) (string-length x)))))))
+
+
 (define (slurp-real port proc)
   "Execute CMD in a shell and return a list of strings from its standard 
output,
 one per line.  If PROC is not #f then it must be a procedure taking a string



reply via email to

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