;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
;;; Copyright © 2014 Cyril Roelandt <tipecaml@gmail.com>
;;; Copyright © 2014 Cyrill Schenkel <cyrill.schenkel@gmail.com>
-;;; Copyright © 2014, 2015 Alex Kost <alezost@gmail.com>
+;;; Copyright © 2014, 2015, 2017 Alex Kost <alezost@gmail.com>
;;; Copyright © 2015 David Thompson <davet@gnu.org>
;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
;;; Copyright © 2016 Roel Janssen <roel@gnu.org>
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (guix ui)
+ #:use-module (guix gexp)
#:use-module (guix utils)
#:use-module (guix store)
#:use-module (guix config)
#:use-module (texinfo)
#:use-module (texinfo plain-text)
#:use-module (texinfo string-utils)
- #:export (_
+ #:export (G_
N_
P_
report-error
fill-paragraph
texi->plain-text
package-description-string
+ package-synopsis-string
string->recutils
package->recutils
package-specification->name+version+output
;; Text domain for package synopses and descriptions.
"guix-packages")
-(define _ (cut gettext <> %gettext-domain))
+(define G_ (cut gettext <> %gettext-domain))
(define N_ (cut ngettext <> <> <> %gettext-domain))
(define (P_ msgid)
(syntax-case x ()
((name (underscore fmt) args (... ...))
(and (string? (syntax->datum #'fmt))
- (free-identifier=? #'underscore #'_))
+ (free-identifier=? #'underscore #'G_))
(with-syntax ((fmt* (augmented-format-string #'fmt))
(prefix (datum->syntax x prefix)))
#'(format (guix-warning-port) (gettext fmt*)
(case on-error
((debug)
(newline)
- (display (_ "entering debugger; type ',bt' for a backtrace\n"))
+ (display (G_ "entering debugger; type ',bt' for a backtrace\n"))
(start-repl #:debug (make-debug (stack->vector stack) 0
(error-string frame args)
#f)))
(match args
(('system-error . rest)
(let ((err (system-error-errno args)))
- (report-error (_ "failed to load '~a': ~a~%") file (strerror err))))
+ (report-error (G_ "failed to load '~a': ~a~%") file (strerror err))))
(('syntax-error proc message properties form . rest)
(let ((loc (source-properties->location properties)))
- (format (current-error-port) (_ "~a: error: ~a~%")
+ (format (current-error-port) (G_ "~a: error: ~a~%")
(location->string loc) message)))
(('srfi-34 obj)
- (report-error (_ "exception thrown: ~s~%") obj))
+ (if (message-condition? obj)
+ (report-error (G_ "~a~%")
+ (gettext (condition-message obj)
+ %gettext-domain))
+ (report-error (G_ "exception thrown: ~s~%") obj)))
((error args ...)
- (report-error (_ "failed to load '~a':~%") file)
+ (report-error (G_ "failed to load '~a':~%") file)
(apply display-error frame (current-error-port) args))))
(define (warn-about-load-error file args) ;FIXME: factorize with ↑
(match args
(('system-error . rest)
(let ((err (system-error-errno args)))
- (warning (_ "failed to load '~a': ~a~%") file (strerror err))))
+ (warning (G_ "failed to load '~a': ~a~%") file (strerror err))))
(('syntax-error proc message properties form . rest)
(let ((loc (source-properties->location properties)))
- (format (current-error-port) (_ "~a: warning: ~a~%")
+ (format (current-error-port) (G_ "~a: warning: ~a~%")
(location->string loc) message)))
(('srfi-34 obj)
- (warning (_ "failed to load '~a': exception thrown: ~s~%")
- file obj))
+ (if (message-condition? obj)
+ (warning (G_ "failed to load '~a': ~a~%")
+ file
+ (gettext (condition-message obj) %gettext-domain))
+ (warning (G_ "failed to load '~a': exception thrown: ~s~%")
+ file obj)))
((error args ...)
- (warning (_ "failed to load '~a':~%") file)
+ (warning (G_ "failed to load '~a':~%") file)
(apply display-error #f (current-error-port) args))))
(define (install-locale)
(lambda _
(setlocale LC_ALL ""))
(lambda args
- (warning (_ "failed to install locale: ~a~%")
+ (warning (G_ "failed to install locale: ~a~%")
(strerror (system-error-errno args))))))
(define (initialize-guix)
;; TRANSLATORS: Translate "(C)" to the copyright symbol
;; (C-in-a-circle), if this symbol is available in the user's
;; locale. Otherwise, do not translate "(C)"; leave it as-is. */
- (_ "(C)")
- (_ "the Guix authors\n"))
- (display (_"\
+ (G_ "(C)")
+ (G_ "the Guix authors\n"))
+ (display (G_"\
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
;; package. Please add another line saying "Report translation bugs to
;; ...\n" with the address for translation bugs (typically your translation
;; team's web or email address).
- (format #t (_ "
+ (format #t (G_ "
Report bugs to: ~a.") %guix-bug-report-address)
- (format #t (_ "
+ (format #t (G_ "
~a home page: <~a>") %guix-package-name %guix-home-page-url)
- (display (_ "
+ (display (G_ "
General help using GNU software: <http://www.gnu.org/gethelp/>"))
(newline))
+(define (augmented-system-error-handler file)
+ "Return a 'system-error' handler that mentions FILE in its message."
+ (lambda (key proc fmt args errno)
+ ;; Augment the FMT and ARGS with information about TARGET (this
+ ;; information is missing as of Guile 2.0.11, making the exception
+ ;; uninformative.)
+ (apply throw key proc "~A: ~S"
+ (list (strerror (car errno)) file)
+ (list errno))))
+
+(define-syntax-rule (error-reporting-wrapper proc (args ...) file)
+ "Wrap PROC such that its 'system-error' exceptions are augmented to mention
+FILE."
+ (let ((real-proc (@ (guile) proc)))
+ (lambda (args ...)
+ (catch 'system-error
+ (lambda ()
+ (real-proc args ...))
+ (augmented-system-error-handler file)))))
+
(set! symlink
;; We 'set!' the global binding because (gnu build ...) modules and similar
;; typically don't use (guix ui).
- (let ((real-symlink (@ (guile) symlink)))
- (lambda (target link)
- "This is a 'symlink' replacement that provides proper error reporting."
- (catch 'system-error
- (lambda ()
- (real-symlink target link))
- (lambda (key proc fmt args errno)
- ;; Augment the FMT and ARGS with information about LINK (this
- ;; information is missing as of Guile 2.0.11, making the exception
- ;; uninformative.)
- (apply throw key proc "~A: ~S"
- (list (strerror (car errno)) link)
- (list errno)))))))
+ (error-reporting-wrapper symlink (source target) target))
(set! copy-file
;; Note: here we use 'set!', not #:replace, because UIs typically use
;; 'copy-recursively', which doesn't use (guix ui).
- (let ((real-copy-file (@ (guile) copy-file)))
- (lambda (source target)
- "This is a 'copy-file' replacement that provides proper error reporting."
- (catch 'system-error
- (lambda ()
- (real-copy-file source target))
- (lambda (key proc fmt args errno)
- ;; Augment the FMT and ARGS with information about TARGET (this
- ;; information is missing as of Guile 2.0.11, making the exception
- ;; uninformative.)
- (apply throw key proc "~A: ~S"
- (list (strerror (car errno)) target)
- (list errno)))))))
+ (error-reporting-wrapper copy-file (source target) target))
+
+(set! canonicalize-path
+ (error-reporting-wrapper canonicalize-path (file) file))
+
(define (make-regexp* regexp . flags)
"Like 'make-regexp' but error out if REGEXP is invalid, reporting the error
(lambda ()
(apply make-regexp regexp flags))
(lambda (key proc message . rest)
- (leave (_ "'~a' is not a valid regular expression: ~a~%")
+ (leave (G_ "'~a' is not a valid regular expression: ~a~%")
regexp message))))
(define (string->number* str)
"Like `string->number', but error out with an error message on failure."
(or (string->number str)
- (leave (_ "~a: invalid number~%") str)))
+ (leave (G_ "~a: invalid number~%") str)))
(define (size->number str)
"Convert STR, a storage measurement representation such as \"1024\" or
str))
(num (string->number numstr)))
(unless num
- (leave (_ "invalid number: ~a~%") numstr))
+ (leave (G_ "invalid number: ~a~%") numstr))
((compose inexact->exact round)
(* num
("YB" (expt 10 24))
("" 1)
(x
- (leave (_ "unknown unit: ~a~%") unit)))))))
+ (leave (G_ "unknown unit: ~a~%") unit)))))))
(define (call-with-error-handling thunk)
"Call THUNK within a user-friendly error handler."
(file (location-file location))
(line (location-line location))
(column (location-column location)))
- (leave (_ "~a:~a:~a: package `~a' has an invalid input: ~s~%")
+ (leave (G_ "~a:~a:~a: package `~a' has an invalid input: ~s~%")
file line column
(package-full-name package) input)))
((package-cross-build-system-error? c)
(let* ((package (package-error-package c))
(loc (package-location package))
(system (package-build-system package)))
- (leave (_ "~a: ~a: build system `~a' does not support cross builds~%")
+ (leave (G_ "~a: ~a: build system `~a' does not support cross builds~%")
(location->string loc)
(package-full-name package)
(build-system-name system))))
+ ((gexp-input-error? c)
+ (let ((input (package-error-invalid-input c)))
+ (leave (G_ "~s: invalid G-expression input~%")
+ (gexp-error-invalid-input c))))
((profile-not-found-error? c)
- (leave (_ "profile '~a' does not exist~%")
+ (leave (G_ "profile '~a' does not exist~%")
(profile-error-profile c)))
((missing-generation-error? c)
- (leave (_ "generation ~a of profile '~a' does not exist~%")
+ (leave (G_ "generation ~a of profile '~a' does not exist~%")
(missing-generation-error-generation c)
(profile-error-profile c)))
((nar-error? c)
(let ((file (nar-error-file c))
(port (nar-error-port c)))
(if file
- (leave (_ "corrupt input while restoring '~a' from ~s~%")
+ (leave (G_ "corrupt input while restoring '~a' from ~s~%")
file (or (port-filename* port) port))
- (leave (_ "corrupt input while restoring archive from ~s~%")
+ (leave (G_ "corrupt input while restoring archive from ~s~%")
(or (port-filename* port) port)))))
((nix-connection-error? c)
- (leave (_ "failed to connect to `~a': ~a~%")
+ (leave (G_ "failed to connect to `~a': ~a~%")
(nix-connection-error-file c)
(strerror (nix-connection-error-code c))))
((nix-protocol-error? c)
;; FIXME: Server-provided error messages aren't i18n'd.
- (leave (_ "build failed: ~a~%")
+ (leave (G_ "build failed: ~a~%")
(nix-protocol-error-message c)))
((derivation-missing-output-error? c)
- (leave (_ "reference to invalid output '~a' of derivation '~a'~%")
+ (leave (G_ "reference to invalid output '~a' of derivation '~a'~%")
(derivation-missing-output c)
(derivation-file-name (derivation-error-derivation c))))
((file-search-error? c)
- (leave (_ "file '~a' could not be found in these \
+ (leave (G_ "file '~a' could not be found in these \
directories:~{ ~a~}~%")
(file-search-error-file-name c)
(file-search-error-search-path c)))
((message-condition? c)
;; Normally '&message' error conditions have an i18n'd message.
- (leave (_ "~a~%")
+ (leave (G_ "~a~%")
(gettext (condition-message c) %gettext-domain))))
;; Catch EPIPE and the likes.
(catch 'system-error
thunk
(lambda (key proc format-string format-args . rest)
- (leave (_ "~a: ~a~%") proc
+ (leave (G_ "~a: ~a~%") proc
(apply format #f format-string format-args))))))
(define-syntax-rule (leave-on-EPIPE exp ...)
(lambda ()
(call-with-input-string str read))
(lambda args
- (leave (_ "failed to read expression ~s: ~s~%")
+ (leave (G_ "failed to read expression ~s: ~s~%")
str args)))))
(catch #t
(lambda ()
(eval exp (force %guix-user-module)))
(lambda args
- (report-error (_ "failed to evaluate expression '~a':~%") exp)
+ (report-error (G_ "failed to evaluate expression '~a':~%") exp)
(match args
(('syntax-error proc message properties form . rest)
- (report-error (_ "syntax error: ~a~%") message))
+ (report-error (G_ "syntax error: ~a~%") message))
(('srfi-34 obj)
- (report-error (_ "exception thrown: ~s~%") obj))
+ (if (message-condition? obj)
+ (report-error (G_ "~a~%")
+ (gettext (condition-message obj)
+ %gettext-domain))
+ (report-error (G_ "exception thrown: ~s~%") obj)))
((error args ...)
(apply display-error #f (current-error-port) args))
(what? #f))
(match (read/eval str)
((? package? p) p)
(x
- (leave (_ "expression ~s does not evaluate to a package~%")
+ (leave (G_ "expression ~s does not evaluate to a package~%")
str))))
(define (show-derivation-outputs derivation)
(define (right-arrow port)
"Return either a string containing the 'RIGHT ARROW' character, or an ASCII
replacement if PORT is not Unicode-capable."
- (with-fluids ((%default-port-encoding (port-encoding port)))
- (let ((arrow "→"))
- (catch 'encoding-error
- (lambda ()
- (call-with-output-string
- (lambda (port)
- (set-port-conversion-strategy! port 'error)
- (display arrow port))))
- (lambda (key . args)
- "->")))))
+ (let ((encoding (port-encoding port))
+ (arrow "→"))
+ (catch 'encoding-error
+ (lambda ()
+ (call-with-output-string
+ (lambda (port)
+ (set-port-encoding! port encoding)
+ (set-port-conversion-strategy! port 'error)
+ (display arrow port))))
+ (lambda (key . args)
+ "->"))))
(define* (show-manifest-transaction store manifest transaction
#:key dry-run?)
"The following packages will be removed:~%~{~a~%~}~%"
len)
remove))))
- (_ #f))
+ (x #f))
(match downgrade
(((($ <manifest-entry> name old-version)
. ($ <manifest-entry> _ new-version output item)) ..1)
"The following packages will be downgraded:~%~{~a~%~}~%"
len)
downgrade))))
- (_ #f))
+ (x #f))
(match upgrade
(((($ <manifest-entry> name old-version)
. ($ <manifest-entry> _ new-version output item)) ..1)
"The following packages will be upgraded:~%~{~a~%~}~%"
len)
upgrade))))
- (_ #f))
+ (x #f))
(match install
((($ <manifest-entry> name version output item _) ..1)
(let ((len (length name))
"The following packages will be installed:~%~{~a~%~}~%"
len)
install))))
- (_ #f))))
+ (x #f))))
(define-syntax with-error-handling
(syntax-rules ()
(define (location->string loc)
"Return a human-friendly, GNU-standard representation of LOC."
(match loc
- (#f (_ "<unknown location>"))
+ (#f (G_ "<unknown location>"))
(($ <location> file line column)
(format #f "~a:~a:~a" file line column))))
(lambda args
(let ((err (system-error-errno args)))
;; ERR is necessarily different from EEXIST.
- (leave (_ "failed to create configuration directory `~a': ~a~%")
+ (leave (G_ "failed to create configuration directory `~a': ~a~%")
dir (strerror err)))))))
(define* (fill-paragraph str width #:optional (column 0))
(match (string-fold maybe-break
`(,column 0 ())
str)
- ((_ _ chars)
+ ((column newlines chars)
(list->string (reverse chars)))))
\f
(with-fluids ((%default-port-encoding "UTF-8"))
(stexi->plain-text (texi-fragment->stexi str))))
+(define (package-field-string package field-accessor)
+ "Return a plain-text representation of PACKAGE field."
+ (and=> (field-accessor package)
+ (compose texi->plain-text P_)))
+
(define (package-description-string package)
"Return a plain-text representation of PACKAGE description field."
- (and=> (package-description package)
- (compose texi->plain-text P_)))
+ (package-field-string package package-description))
+
+(define (package-synopsis-string package)
+ "Return a plain-text representation of PACKAGE synopsis field."
+ (package-field-string package package-synopsis))
(define (string->recutils str)
"Return a version of STR where newlines have been replaced by newlines
(dependencies->recutils (filter package? inputs)))))
(format port "location: ~a~%"
(or (and=> (package-location p) location->string)
- (_ "unknown")))
+ (G_ "unknown")))
;; Note: Starting from version 1.6 or recutils, hyphens are not allowed in
;; field identifiers.
((? license? license)
(license-name license))
(x
- (_ "unknown"))))
+ (G_ "unknown"))))
(format port "synopsis: ~a~%"
(string-map (match-lambda
(#\newline #\space)
(chr chr))
- (or (and=> (package-synopsis p) P_)
+ (or (and=> (package-synopsis-string p) P_)
"")))
(format port "~a~2%"
(string->recutils
(valid-generations (iota n 1)))
((lst ..1)
(valid-generations lst))
- (_ #f)))
+ (x #f)))
(define (filter-by-duration duration)
(define (time-at-midnight time)
(define (display-generation profile number)
"Display a one-line summary of generation NUMBER of PROFILE."
(unless (zero? number)
- (let ((header (format #f (_ "Generation ~a\t~a") number
+ (let ((header (format #f (G_ "Generation ~a\t~a") number
(date->string
(time-utc->date
(generation-time profile number))
;; TRANSLATORS: The word "current" here is an adjective for
;; "Generation", as in "current generation". Use the appropriate
;; gender where applicable.
- (format #t (_ "~a\t(current)~%") header)
+ (format #t (G_ "~a\t(current)~%") header)
(format #t "~a~%" header)))))
(define (display-profile-content-diff profile gen1 gen2)
(profile-manifest (generation-file-name profile number))))))
(define (display-generation-change previous current)
- (format #t (_ "switched from generation ~a to ~a~%") previous current))
+ (format #t (G_ "switched from generation ~a to ~a~%") previous current))
(define (roll-back* store profile)
"Like 'roll-back', but display what is happening."
(define (delete-generation* store profile generation)
"Like 'delete-generation', but display what is going on."
- (format #t (_ "deleting ~a~%")
+ (format #t (G_ "deleting ~a~%")
(generation-file-name profile generation))
(delete-generation store profile generation))
(define (show-guix-usage)
(format (current-error-port)
- (_ "Try `guix --help' for more information.~%"))
+ (G_ "Try `guix --help' for more information.~%"))
(exit 1))
(define (command-files)
(member command '("substitute" "authenticate" "offload"
"perform-download")))
- (format #t (_ "Usage: guix COMMAND ARGS...
+ (format #t (G_ "Usage: guix COMMAND ARGS...
Run COMMAND with ARGS.\n"))
(newline)
- (format #t (_ "COMMAND must be one of the sub-commands listed below:\n"))
+ (format #t (G_ "COMMAND must be one of the sub-commands listed below:\n"))
(newline)
;; TODO: Display a synopsis of each command.
(format #t "~{ ~a~%~}" (sort (remove internal? (commands))
(resolve-interface `(guix scripts ,command)))
(lambda -
(format (current-error-port)
- (_ "guix: ~a: command not found~%") command)
+ (G_ "guix: ~a: command not found~%") command)
(show-guix-usage))))
(let ((command-main (module-ref module
(match args
(()
(format (current-error-port)
- (_ "guix: missing command name~%"))
+ (G_ "guix: missing command name~%"))
(show-guix-usage))
((or ("-h") ("--help"))
(show-guix-help))
(show-version-and-exit "guix"))
(((? option? o) args ...)
(format (current-error-port)
- (_ "guix: unrecognized option '~a'~%") o)
+ (G_ "guix: unrecognized option '~a'~%") o)
(show-guix-usage))
(("help" command)
(apply run-guix-command (string->symbol command)