ui: Rename '_' to 'G_'.
[jackhill/guix/guix.git] / guix / scripts / refresh.scm
index b81c69f..645572f 100644 (file)
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
 ;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
 ;;; Copyright © 2015 Alex Kost <alezost@gmail.com>
@@ -35,7 +35,8 @@
                 #:select (%gnu-updater
                           %gnome-updater
                           %kde-updater
-                          %xorg-updater))
+                          %xorg-updater
+                          %kernel.org-updater))
   #:use-module (guix import elpa)
   #:use-module (guix import cran)
   #:use-module (guix import hackage)
@@ -75,7 +76,7 @@
                      (alist-cons 'select (string->symbol arg)
                                  result))
                     (x
-                     (leave (_ "~a: invalid selection; expected `core' or `non-core'~%")
+                     (leave (G_ "~a: invalid selection; expected `core' or `non-core'~%")
                             arg)))))
         (option '(#\t "type") #t #f
                 (lambda (opt name arg result)
                      (alist-cons 'key-download (string->symbol arg)
                                  result))
                     (x
-                     (leave (_ "unsupported policy: ~a~%")
+                     (leave (G_ "unsupported policy: ~a~%")
                             arg)))))
 
         (option '(#\h "help") #f #f
                   (show-version-and-exit "guix refresh")))))
 
 (define (show-help)
-  (display (_ "Usage: guix refresh [OPTION]... PACKAGE...
+  (display (G_ "Usage: guix refresh [OPTION]... [PACKAGE]...
 Update package definitions to match the latest upstream version.
 
 When PACKAGE... is given, update only the specified packages.  Otherwise
 update all the packages of the distribution, or the subset thereof
 specified with `--select'.\n"))
-  (display (_ "
+  (display (G_ "
   -e, --expression=EXPR  consider the package EXPR evaluates to"))
-  (display (_ "
+  (display (G_ "
   -u, --update           update source files in place"))
-  (display (_ "
+  (display (G_ "
   -s, --select=SUBSET    select all the packages in SUBSET, one of
                          `core' or `non-core'"))
-  (display (_ "
+  (display (G_ "
   -t, --type=UPDATER,... restrict to updates from the specified updaters
                          (e.g., 'gnu')"))
-  (display (_ "
+  (display (G_ "
   -L, --list-updaters    list available updaters and exit"))
-  (display (_ "
+  (display (G_ "
   -l, --list-dependent   list top-level dependent packages that would need to
                          be rebuilt as a result of upgrading PACKAGE..."))
   (newline)
-  (display (_ "
+  (display (G_ "
       --key-server=HOST  use HOST as the OpenPGP key server"))
-  (display (_ "
+  (display (G_ "
       --gpg=COMMAND      use COMMAND as the GnuPG 2.x command"))
-  (display (_ "
+  (display (G_ "
       --key-download=POLICY
                          handle missing OpenPGP keys according to POLICY:
                          'always', 'never', and 'interactive', which is also
                          used when 'key-download' is not specified"))
   (newline)
-  (display (_ "
+  (display (G_ "
   -h, --help             display this help and exit"))
-  (display (_ "
+  (display (G_ "
   -V, --version          display version information and exit"))
   (newline)
   (show-bug-report-information))
@@ -200,56 +201,106 @@ unavailable optional dependencies such as Guile-JSON."
                  %gnome-updater
                  %kde-updater
                  %xorg-updater
+                 %kernel.org-updater
                  %elpa-updater
                  %cran-updater
                  %bioconductor-updater
+                 ((guix import stackage) => %stackage-updater)
                  %hackage-updater
+                 ((guix import cpan) => %cpan-updater)
                  ((guix import pypi) => %pypi-updater)
                  ((guix import gem) => %gem-updater)
-                 ((guix import github) => %github-updater)))
+                 ((guix import github) => %github-updater)
+                 ((guix import crate) => %crate-updater)))
 
-(define (lookup-updater name)
+(define (lookup-updater-by-name name)
   "Return the updater called NAME."
   (or (find (lambda (updater)
               (eq? name (upstream-updater-name updater)))
             %updaters)
-      (leave (_ "~a: no such updater~%") name)))
+      (leave (G_ "~a: no such updater~%") name)))
 
 (define (list-updaters-and-exit)
   "Display available updaters and exit."
-  (format #t (_ "Available updaters:~%"))
-  (for-each (lambda (updater)
-              (format #t "- ~a: ~a~%"
-                      (upstream-updater-name updater)
-                      (_ (upstream-updater-description updater))))
-            %updaters)
+  (format #t (G_ "Available updaters:~%"))
+  (newline)
+
+  (let* ((packages (fold-packages cons '()))
+         (total    (length packages)))
+    (define covered
+      (fold (lambda (updater covered)
+              (let ((matches (count (upstream-updater-predicate updater)
+                                    packages)))
+                ;; TRANSLATORS: The parenthetical expression here is rendered
+                ;; like "(42% coverage)" and denotes the fraction of packages
+                ;; covered by the given updater.
+                (format #t (G_ "  - ~a: ~a (~2,1f% coverage)~%")
+                        (upstream-updater-name updater)
+                        (G_ (upstream-updater-description updater))
+                        (* 100. (/ matches total)))
+                (+ covered matches)))
+            0
+            %updaters))
+
+    (newline)
+    (format #t (G_ "~2,1f% of the packages are covered by these updaters.~%")
+            (* 100. (/ covered total))))
   (exit 0))
 
+(define (warn-no-updater package)
+  (format (current-error-port)
+          (G_ "~a: warning: no updater for ~a~%")
+          (location->string (package-location package))
+          (package-name package)))
+
 (define* (update-package store package updaters
-                         #:key (key-download 'interactive))
+                         #:key (key-download 'interactive) warn?)
   "Update the source file that defines PACKAGE with the new version.
 KEY-DOWNLOAD specifies a download policy for missing OpenPGP keys; allowed
-values: 'interactive' (default), 'always', and 'never'."
-  (let-values (((version tarball)
-                (package-update store package updaters
-                                #:key-download key-download))
-               ((loc)
-                (or (package-field-location package 'version)
-                    (package-location package))))
-    (when version
-      (if (and=> tarball file-exists?)
-          (begin
-            (format (current-error-port)
-                    (_ "~a: ~a: updating from version ~a to version ~a...~%")
-                    (location->string loc)
-                    (package-name package)
-                    (package-version package) version)
-            (let ((hash (call-with-input-file tarball
-                          port-sha256)))
-              (update-package-source package version hash)))
-          (warning (_ "~a: version ~a could not be \
+values: 'interactive' (default), 'always', and 'never'.  When WARN? is true,
+warn about packages that have no matching updater."
+  (if (lookup-updater package updaters)
+      (let-values (((version tarball)
+                    (package-update store package updaters
+                                    #:key-download key-download))
+                   ((loc)
+                    (or (package-field-location package 'version)
+                        (package-location package))))
+        (when version
+          (if (and=> tarball file-exists?)
+              (begin
+                (format (current-error-port)
+                        (G_ "~a: ~a: updating from version ~a to version ~a...~%")
+                        (location->string loc)
+                        (package-name package)
+                        (package-version package) version)
+                (let ((hash (call-with-input-file tarball
+                              port-sha256)))
+                  (update-package-source package version hash)))
+              (warning (G_ "~a: version ~a could not be \
 downloaded and authenticated; not updating~%")
-                   (package-name package) version)))))
+                       (package-name package) version))))
+      (when warn?
+        (warn-no-updater package))))
+
+(define* (check-for-package-update package updaters #:key warn?)
+  "Check whether an update is available for PACKAGE and print a message.  When
+WARN? is true and no updater exists for PACKAGE, print a warning."
+  (match (package-latest-release package updaters)
+    ((? upstream-source? source)
+     (when (version>? (upstream-source-version source)
+                      (package-version package))
+       (let ((loc (or (package-field-location package 'version)
+                      (package-location package))))
+         (format (current-error-port)
+                 (G_ "~a: ~a would be upgraded from ~a to ~a~%")
+                 (location->string loc)
+                 (package-name package) (package-version package)
+                 (upstream-source-version source)))))
+    (#f
+     (when warn?
+       (warn-no-updater package)))))
+
 
 \f
 ;;;
@@ -264,6 +315,10 @@ downloaded and authenticated; not updating~%")
   "List all the things that would need to be rebuilt if PACKAGES are changed."
   ;; Using %BAG-NODE-TYPE is more accurate than using %PACKAGE-NODE-TYPE
   ;; because it includes implicit dependencies.
+  (define (full-name package)
+    (string-append (package-name package) "@"
+                   (package-version package)))
+
   (mlet %store-monad ((edges (node-back-edges %bag-node-type
                                               (all-packages))))
     (let* ((dependents (node-transitive-edges packages edges))
@@ -276,12 +331,12 @@ downloaded and authenticated; not updating~%")
                  (N_ "No dependents other than itself: ~{~a~}~%"
                      "No dependents other than themselves: ~{~a~^ ~}~%"
                      (length packages))
-                 (map package-full-name packages)))
+                 (map full-name packages)))
 
         ((x)
          (format (current-output-port)
-                 (_ "A single dependent package: ~a~%")
-                 (package-full-name x)))
+                 (G_ "A single dependent package: ~a~%")
+                 (full-name x)))
         (lst
          (format (current-output-port)
                  (N_ "Building the following package would ensure ~d \
@@ -290,7 +345,7 @@ dependent packages are rebuilt: ~*~{~a~^ ~}~%"
 dependent packages are rebuilt: ~{~a~^ ~}~%"
                      (length covering))
                  (length covering) (length dependents)
-                 (map package-full-name covering))))
+                 (map full-name covering))))
       (return #t))))
 
 \f
@@ -303,7 +358,7 @@ dependent packages are rebuilt: ~{~a~^ ~}~%"
     ;; Return the alist of option values.
     (args-fold* args %options
                 (lambda (opt name arg result)
-                  (leave (_ "~A: unrecognized option~%") name))
+                  (leave (G_ "~A: unrecognized option~%") name))
                 (lambda (arg result)
                   (alist-cons 'argument arg result))
                 %default-options))
@@ -312,7 +367,7 @@ dependent packages are rebuilt: ~{~a~^ ~}~%"
     ;; Return the list of updaters to use.
     (match (filter-map (match-lambda
                          (('updaters . names)
-                          (map lookup-updater names))
+                          (map lookup-updater-by-name names))
                          (_ #f))
                        opts)
       (()
@@ -360,6 +415,12 @@ update would trigger a complete rebuild."
          (updaters        (options->updaters opts))
          (list-dependent? (assoc-ref opts 'list-dependent?))
          (key-download    (assoc-ref opts 'key-download))
+
+         ;; Warn about missing updaters when a package is explicitly given on
+         ;; the command line.
+         (warn?           (or (assoc-ref opts 'argument)
+                              (assoc-ref opts 'expression)))
+
          (packages
           (match (filter-map (match-lambda
                                (('argument . spec)
@@ -397,22 +458,14 @@ update would trigger a complete rebuild."
                                 (%gpg-command))))
               (for-each
                (cut update-package store <> updaters
-                    #:key-download key-download)
+                    #:key-download key-download
+                    #:warn? warn?)
                packages)
               (with-monad %store-monad
                 (return #t))))
            (else
-            (for-each (lambda (package)
-                        (match (package-update-path package updaters)
-                          ((? upstream-source? source)
-                           (let ((loc (or (package-field-location package 'version)
-                                          (package-location package))))
-                             (format (current-error-port)
-                                     (_ "~a: ~a would be upgraded from ~a to ~a~%")
-                                     (location->string loc)
-                                     (package-name package) (package-version package)
-                                     (upstream-source-version source))))
-                          (#f #f)))
+            (for-each (cut check-for-package-update <> updaters
+                           #:warn? warn?)
                       packages)
             (with-monad %store-monad
               (return #t)))))))))