From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Kost Subject: [PATCH] Export 'check-package-freshness' Date: Sat, 16 Aug 2014 22:23:25 +0400 Message-ID: <87ppg0cmzm.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIidd-0007up-8H for guix-devel@gnu.org; Sat, 16 Aug 2014 14:23:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XIidT-0002M6-Es for guix-devel@gnu.org; Sat, 16 Aug 2014 14:23:37 -0400 Received: from mail-lb0-x22b.google.com ([2a00:1450:4010:c04::22b]:48175) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIidT-0002M0-1v for guix-devel@gnu.org; Sat, 16 Aug 2014 14:23:27 -0400 Received: by mail-lb0-f171.google.com with SMTP id l4so2942184lbv.16 for ; Sat, 16 Aug 2014 11:23:26 -0700 (PDT) Received: from leviafan (128-70-193-103.broadband.corbina.ru. [128.70.193.103]) by mx.google.com with ESMTPSA id f9sm18529965lbd.46.2014.08.16.11.23.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Aug 2014 11:23:24 -0700 (PDT) List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s (2014-08-13 20:03 +0400) wrote: [...] > Alex Kost skribis: > > [...] > >> Also I think "guix.el" should check for freshness too, so >> =E2=80=98check-package-freshness=E2=80=99 should probably be exported. > > Yes, probably in the (gnu packages) module? Here is the patch for that. I'm not sure about the commit message. Should it be changed? --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Move-check-package-freshness-from-guix-package-to-pa.patch >From a13dbc81b6ca8c16343aaaafd17ec57812f0c24e Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Sat, 16 Aug 2014 22:00:34 +0400 Subject: [PATCH] Move 'check-package-freshness' from 'guix package' to 'packages' * guix/scripts/package.scm (%sigint-prompt, call-with-sigint-handler) (waiting, ftp-open*, check-package-freshness): Move to... * gnu/packages.scm: ... here. --- gnu/packages.scm | 84 +++++++++++++++++++++++++++++++++++++++++++++++- guix/scripts/package.scm | 79 --------------------------------------------- 2 files changed, 83 insertions(+), 80 deletions(-) diff --git a/gnu/packages.scm b/gnu/packages.scm index 77d9d3e..bad7efb 100644 --- a/gnu/packages.scm +++ b/gnu/packages.scm @@ -22,6 +22,8 @@ #:use-module (guix packages) #:use-module (guix ui) #:use-module (guix utils) + #:use-module ((guix ftp-client) #:select (ftp-open)) + #:use-module (guix gnu-maintenance) #:use-module (ice-9 ftw) #:use-module (ice-9 vlist) #:use-module (ice-9 match) @@ -41,7 +43,9 @@ package-direct-dependents package-transitive-dependents - package-covering-dependents)) + package-covering-dependents + + check-package-freshness)) ;;; Commentary: ;;; @@ -246,3 +250,81 @@ include all of PACKAGES and all packages that depend on PACKAGES." (lambda (node) (vhash-refq dependency-dag node)) ;; Start with the dependents to avoid including PACKAGES in the result. (package-direct-dependents packages)))) + + +(define %sigint-prompt + ;; The prompt to jump to upon SIGINT. + (make-prompt-tag "interruptible")) + +(define (call-with-sigint-handler thunk handler) + "Call THUNK and return its value. Upon SIGINT, call HANDLER with the signal +number in the context of the continuation of the call to this function, and +return its return value." + (call-with-prompt %sigint-prompt + (lambda () + (sigaction SIGINT + (lambda (signum) + (sigaction SIGINT SIG_DFL) + (abort-to-prompt %sigint-prompt signum))) + (dynamic-wind + (const #t) + thunk + (cut sigaction SIGINT SIG_DFL))) + (lambda (k signum) + (handler signum)))) + +(define-syntax-rule (waiting exp fmt rest ...) + "Display the given message while EXP is being evaluated." + (let* ((message (format #f fmt rest ...)) + (blank (make-string (string-length message) #\space))) + (display message (current-error-port)) + (force-output (current-error-port)) + (call-with-sigint-handler + (lambda () + (dynamic-wind + (const #f) + (lambda () exp) + (lambda () + ;; Clear the line. + (display #\cr (current-error-port)) + (display blank (current-error-port)) + (display #\cr (current-error-port)) + (force-output (current-error-port))))) + (lambda (signum) + (format (current-error-port) " interrupted by signal ~a~%" SIGINT) + #f)))) + +(define ftp-open* + ;; Memoizing version of `ftp-open'. The goal is to avoid initiating a new + ;; FTP connection for each package, esp. since most of them are to the same + ;; server. This has a noticeable impact when doing "guix upgrade -u". + (memoize ftp-open)) + +(define (check-package-freshness package) + "Check whether PACKAGE has a newer version available upstream, and report +it." + ;; TODO: Automatically inject the upstream version when desired. + + (catch #t + (lambda () + (when (false-if-exception (gnu-package? package)) + (let ((name (package-name package)) + (full-name (package-full-name package))) + (match (waiting (latest-release name + #:ftp-open ftp-open* + #:ftp-close (const #f)) + (_ "looking for the latest release of GNU ~a...") name) + ((latest-version . _) + (when (version>? latest-version full-name) + (format (current-error-port) + (_ "~a: note: using ~a \ +but ~a is available upstream~%") + (location->string (package-location package)) + full-name latest-version))) + (_ #t))))) + (lambda (key . args) + ;; Silently ignore networking errors rather than preventing + ;; installation. + (case key + ((getaddrinfo-error ftp-error) #f) + (else (apply throw key args)))))) diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index 3bfef4f..239df77 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -29,7 +29,6 @@ #:use-module (guix config) #:use-module (guix scripts build) #:use-module ((guix build utils) #:select (directory-exists? mkdir-p)) - #:use-module ((guix ftp-client) #:select (ftp-open)) #:use-module (ice-9 format) #:use-module (ice-9 match) #:use-module (ice-9 regex) @@ -42,7 +41,6 @@ #:use-module (gnu packages) #:use-module ((gnu packages base) #:select (guile-final)) #:use-module ((gnu packages bootstrap) #:select (%bootstrap-guile)) - #:use-module (guix gnu-maintenance) #:export (specification->package+output guix-package)) @@ -258,48 +256,6 @@ RX." (package-name p2)))) same-location?)) -(define %sigint-prompt - ;; The prompt to jump to upon SIGINT. - (make-prompt-tag "interruptible")) - -(define (call-with-sigint-handler thunk handler) - "Call THUNK and return its value. Upon SIGINT, call HANDLER with the signal -number in the context of the continuation of the call to this function, and -return its return value." - (call-with-prompt %sigint-prompt - (lambda () - (sigaction SIGINT - (lambda (signum) - (sigaction SIGINT SIG_DFL) - (abort-to-prompt %sigint-prompt signum))) - (dynamic-wind - (const #t) - thunk - (cut sigaction SIGINT SIG_DFL))) - (lambda (k signum) - (handler signum)))) - -(define-syntax-rule (waiting exp fmt rest ...) - "Display the given message while EXP is being evaluated." - (let* ((message (format #f fmt rest ...)) - (blank (make-string (string-length message) #\space))) - (display message (current-error-port)) - (force-output (current-error-port)) - (call-with-sigint-handler - (lambda () - (dynamic-wind - (const #f) - (lambda () exp) - (lambda () - ;; Clear the line. - (display #\cr (current-error-port)) - (display blank (current-error-port)) - (display #\cr (current-error-port)) - (force-output (current-error-port))))) - (lambda (signum) - (format (current-error-port) " interrupted by signal ~a~%" SIGINT) - #f)))) - (define-syntax-rule (leave-on-EPIPE exp ...) "Run EXP... in a context when EPIPE errors are caught and lead to 'exit' with successful exit code. This is useful when writing to the standard output @@ -363,41 +319,6 @@ an output path different than CURRENT-PATH." (not (string=? current-path candidate-path)))))) (#f #f))) -(define ftp-open* - ;; Memoizing version of `ftp-open'. The goal is to avoid initiating a new - ;; FTP connection for each package, esp. since most of them are to the same - ;; server. This has a noticeable impact when doing "guix upgrade -u". - (memoize ftp-open)) - -(define (check-package-freshness package) - "Check whether PACKAGE has a newer version available upstream, and report -it." - ;; TODO: Automatically inject the upstream version when desired. - - (catch #t - (lambda () - (when (false-if-exception (gnu-package? package)) - (let ((name (package-name package)) - (full-name (package-full-name package))) - (match (waiting (latest-release name - #:ftp-open ftp-open* - #:ftp-close (const #f)) - (_ "looking for the latest release of GNU ~a...") name) - ((latest-version . _) - (when (version>? latest-version full-name) - (format (current-error-port) - (_ "~a: note: using ~a \ -but ~a is available upstream~%") - (location->string (package-location package)) - full-name latest-version))) - (_ #t))))) - (lambda (key . args) - ;; Silently ignore networking errors rather than preventing - ;; installation. - (case key - ((getaddrinfo-error ftp-error) #f) - (else (apply throw key args)))))) - ;;; ;;; Search paths. -- 2.0.3 --=-=-=--