guix-commits
[Top][All Lists]
Advanced

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

05/08: ui: 'show-what-to-build' displays how much will be downloaded.


From: Ludovic Courtès
Subject: 05/08: ui: 'show-what-to-build' displays how much will be downloaded.
Date: Fri, 2 Jun 2017 12:48:16 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit d9bad2f08296fa73b967973aa6648d24c100980f
Author: Ludovic Courtès <address@hidden>
Date:   Wed May 31 15:06:28 2017 +0200

    ui: 'show-what-to-build' displays how much will be downloaded.
    
    * guix/ui.scm (show-what-to-build)[download-size]
    [display-download-size?]: New variables.
    Add cases for when DISPLAY-DOWNLOAD-SIZE? is true.
---
 guix/ui.scm | 49 +++++++++++++++++++++++++++++++++++++------------
 1 file changed, 37 insertions(+), 12 deletions(-)

diff --git a/guix/ui.scm b/guix/ui.scm
index 9b64648..04700a6 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -632,6 +632,15 @@ report what is prerequisites are available for download."
                                            download))))
                      download)))
     ;; TODO: Show the installed size of DOWNLOAD.
+    (define download-size
+      (/ (reduce + 0 (map substitutable-download-size download))
+         1e6))
+
+    (define display-download-size?
+      ;; Sometimes narinfos lack information about the download size.  Only
+      ;; display when we have information for all of DOWNLOAD.
+      (not (any (compose zero? substitutable-download-size) download)))
+
     (if dry-run?
         (begin
           (format (current-error-port)
@@ -639,24 +648,40 @@ report what is prerequisites are available for download."
                       "~:[The following derivations would be built:~%~{   
~a~%~}~;~]"
                       (length build))
                   (null? build) build)
-          (format (current-error-port)
-                  (N_ "~:[The following file would be downloaded:~%~{   
~a~%~}~;~]"
-                      "~:[The following files would be downloaded:~%~{   
~a~%~}~;~]"
-                      (length download))
-                  (null? download)
-                  (map substitutable-path download)))
+          (if display-download-size?
+              (format (current-error-port)
+                      ;; TRANSLATORS: "MB" is for "megabyte"; it should be
+                      ;; translated to the corresponding abbreviation.
+                      (G_ "~:[~,1h MB would be downloaded:~%~{   ~a~%~}~;~]")
+                      (null? download)
+                      download-size
+                      (map substitutable-path download))
+              (format (current-error-port)
+                      (N_ "~:[The following file would be downloaded:~%~{   
~a~%~}~;~]"
+                          "~:[The following files would be downloaded:~%~{   
~a~%~}~;~]"
+                          (length download))
+                      (null? download)
+                      (map substitutable-path download))))
         (begin
           (format (current-error-port)
                   (N_ "~:[The following derivation will be built:~%~{   
~a~%~}~;~]"
                       "~:[The following derivations will be built:~%~{   
~a~%~}~;~]"
                       (length build))
                   (null? build) build)
-          (format (current-error-port)
-                  (N_ "~:[The following file will be downloaded:~%~{   
~a~%~}~;~]"
-                      "~:[The following files will be downloaded:~%~{   
~a~%~}~;~]"
-                      (length download))
-                  (null? download)
-                  (map substitutable-path download))))
+          (if display-download-size?
+              (format (current-error-port)
+                      ;; TRANSLATORS: "MB" is for "megabyte"; it should be
+                      ;; translated to the corresponding abbreviation.
+                      (G_ "~:[~,1h MB will be downloaded:~%~{   ~a~%~}~;~]")
+                      (null? download)
+                      download-size
+                      (map substitutable-path download))
+              (format (current-error-port)
+                      (N_ "~:[The following file will be downloaded:~%~{   
~a~%~}~;~]"
+                          "~:[The following files will be downloaded:~%~{   
~a~%~}~;~]"
+                          (length download))
+                      (null? download)
+                      (map substitutable-path download)))))
     (pair? build)))
 
 (define show-what-to-build*



reply via email to

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