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.
This commit is contained in:
Ludovic Courtès 2017-05-31 15:06:28 +02:00
parent 2dc98729af
commit d9bad2f082
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 37 additions and 12 deletions

View File

@ -632,6 +632,15 @@ report what is prerequisites are available for download."
download)))) download))))
download))) download)))
;; TODO: Show the installed size of 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? (if dry-run?
(begin (begin
(format (current-error-port) (format (current-error-port)
@ -639,24 +648,40 @@ report what is prerequisites are available for download."
"~:[The following derivations would be built:~%~{ ~a~%~}~;~]" "~:[The following derivations would be built:~%~{ ~a~%~}~;~]"
(length build)) (length build))
(null? build) build) (null? build) build)
(format (current-error-port) (if display-download-size?
(N_ "~:[The following file would be downloaded:~%~{ ~a~%~}~;~]" (format (current-error-port)
"~:[The following files would be downloaded:~%~{ ~a~%~}~;~]" ;; TRANSLATORS: "MB" is for "megabyte"; it should be
(length download)) ;; translated to the corresponding abbreviation.
(null? download) (G_ "~:[~,1h MB would be downloaded:~%~{ ~a~%~}~;~]")
(map substitutable-path download))) (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 (begin
(format (current-error-port) (format (current-error-port)
(N_ "~:[The following derivation will be built:~%~{ ~a~%~}~;~]" (N_ "~:[The following derivation will be built:~%~{ ~a~%~}~;~]"
"~:[The following derivations will be built:~%~{ ~a~%~}~;~]" "~:[The following derivations will be built:~%~{ ~a~%~}~;~]"
(length build)) (length build))
(null? build) build) (null? build) build)
(format (current-error-port) (if display-download-size?
(N_ "~:[The following file will be downloaded:~%~{ ~a~%~}~;~]" (format (current-error-port)
"~:[The following files will be downloaded:~%~{ ~a~%~}~;~]" ;; TRANSLATORS: "MB" is for "megabyte"; it should be
(length download)) ;; translated to the corresponding abbreviation.
(null? download) (G_ "~:[~,1h MB will be downloaded:~%~{ ~a~%~}~;~]")
(map substitutable-path download)))) (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))) (pair? build)))
(define show-what-to-build* (define show-what-to-build*