[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
22/68: installer: Add new utils.
From: |
guix-commits |
Subject: |
22/68: installer: Add new utils. |
Date: |
Thu, 17 Jan 2019 08:05:12 -0500 (EST) |
civodul pushed a commit to branch master
in repository guix.
commit 3ad8f7757c840de290a6035747578a18ff7279da
Author: Mathieu Othacehe <address@hidden>
Date: Wed Dec 5 14:24:04 2018 +0900
installer: Add new utils.
* gnu/installer/utils.scm (nearest-exact-integer): New exported procedure,
(read-percentage): ditto,
(run-shell-command): ditto.
---
gnu/installer/utils.scm | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/gnu/installer/utils.scm b/gnu/installer/utils.scm
index 5087683..e91f90a 100644
--- a/gnu/installer/utils.scm
+++ b/gnu/installer/utils.scm
@@ -17,10 +17,16 @@
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (gnu installer utils)
+ #:use-module (guix utils)
+ #:use-module (guix build utils)
#:use-module (ice-9 rdelim)
+ #:use-module (ice-9 regex)
#:use-module (ice-9 textual-ports)
#:export (read-lines
- read-all))
+ read-all
+ nearest-exact-integer
+ read-percentage
+ run-shell-command))
(define* (read-lines #:optional (port (current-input-port)))
"Read lines from PORT and return them as a list."
@@ -35,3 +41,23 @@
"Return the content of the given FILE as a string."
(call-with-input-file file
get-string-all))
+
+(define (nearest-exact-integer x)
+ "Given a real number X, return the nearest exact integer, with ties going to
+the nearest exact even integer."
+ (inexact->exact (round x)))
+
+(define (read-percentage percentage)
+ "Read PERCENTAGE string and return the corresponding percentage as a
+number. If no percentage is found, return #f"
+ (let ((result (string-match "^([0-9]+)%$" percentage)))
+ (and result
+ (string->number (match:substring result 1)))))
+
+(define (run-shell-command command)
+ (call-with-temporary-output-file
+ (lambda (file port)
+ (format port "~a~%" command)
+ ;; (format port "exit~%")
+ (close port)
+ (invoke "bash" "--init-file" file))))
- 66/68: installer: Adjust messages on the final page., (continued)
- 66/68: installer: Adjust messages on the final page., guix-commits, 2019/01/17
- 65/68: syscalls: 'device-in-use?' returns #f upon EINVAL., guix-commits, 2019/01/17
- 67/68: installer: "formating" → "formatting"., guix-commits, 2019/01/17
- 63/68: installer: partition: Add encryption password confirmation., guix-commits, 2019/01/17
- 03/68: services: kmscon: Remove virtual-terminal requirement., guix-commits, 2019/01/17
- 04/68: gnu: kmscon: Add runtime keymap update support., guix-commits, 2019/01/17
- 02/68: guile: newt: Update revision to 3., guix-commits, 2019/01/17
- 01/68: gnu: Add ghc-tldr., guix-commits, 2019/01/17
- 21/68: installer: Remove "selection" from all titles., guix-commits, 2019/01/17
- 20/68: file-systems: Export read-partition-label and read-partition-uuid., guix-commits, 2019/01/17
- 22/68: installer: Add new utils.,
guix-commits <=
- 33/68: installer: Reorder POTFILES.in, guix-commits, 2019/01/17
- 31/68: installer: Add user module., guix-commits, 2019/01/17
- 32/68: installer: Add partitioning support., guix-commits, 2019/01/17
- 09/68: doc: Document the graphical installer., guix-commits, 2019/01/17
- 34/68: installer: Reorder local.mk., guix-commits, 2019/01/17
- 35/68: installer: Remove group selection in user page., guix-commits, 2019/01/17
- 06/68: installer: newt: Use scheme-modules* instead of scheme-modules., guix-commits, 2019/01/17
- 07/68: installer: newt: Locate the logo within local-file., guix-commits, 2019/01/17
- 08/68: configure: Disable installer build by default., guix-commits, 2019/01/17
- 05/68: gnu: Add graphical installer support., guix-commits, 2019/01/17