[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
21/67: installer: Add new utils.
From: |
guix-commits |
Subject: |
21/67: installer: Add new utils. |
Date: |
Wed, 16 Jan 2019 19:00:38 -0500 (EST) |
civodul pushed a commit to branch wip-newt-installer
in repository guix.
commit 9b73dae36c36842c8e91656bc45b98909bfee8bb
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))))
- branch wip-newt-installer created (now e12a60d), guix-commits, 2019/01/16
- 01/67: guile: newt: Update revision to 3., guix-commits, 2019/01/16
- 06/67: installer: newt: Locate the logo within local-file., guix-commits, 2019/01/16
- 02/67: services: kmscon: Remove virtual-terminal requirement., guix-commits, 2019/01/16
- 09/67: guix: self: Do not install (gnu system install)., guix-commits, 2019/01/16
- 16/67: services: herd: Allow to pass arguments to start-service., guix-commits, 2019/01/16
- 11/67: installer: Rewrite welcome page., guix-commits, 2019/01/16
- 15/67: build: syscalls: Add device-in-use?., guix-commits, 2019/01/16
- 21/67: installer: Add new utils.,
guix-commits <=
- 20/67: installer: Remove "selection" from all titles., guix-commits, 2019/01/16
- 28/67: installer: Fix ethernet connection., guix-commits, 2019/01/16
- 10/67: gnu: installer: Launch the installer as kmscon login-program., guix-commits, 2019/01/16
- 19/67: file-systems: Export read-partition-label and read-partition-uuid., guix-commits, 2019/01/16
- 14/67: tests: Rename %test-encrypted-os to %test-encrypted-root-os., guix-commits, 2019/01/16
- 18/67: gnu: Add guile-parted., guix-commits, 2019/01/16
- 33/67: installer: Reorder local.mk., guix-commits, 2019/01/16
- 05/67: installer: newt: Use scheme-modules* instead of scheme-modules., guix-commits, 2019/01/16
- 17/67: gnu: guile-newt: Update to revision 4., guix-commits, 2019/01/16
- 35/67: installer: Fix compute calls., guix-commits, 2019/01/16