From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:37718) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j424h-0007YV-NK for guix-patches@gnu.org; Tue, 18 Feb 2020 07:34:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j424g-0004XH-GV for guix-patches@gnu.org; Tue, 18 Feb 2020 07:34:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:33649) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j424g-0004X0-Cu for guix-patches@gnu.org; Tue, 18 Feb 2020 07:34:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1j424g-0006Tj-Ad for guix-patches@gnu.org; Tue, 18 Feb 2020 07:34:02 -0500 Subject: [bug#39547] [PATCH v2 1/2] website: Refactor and resolve mirror:// of JSON package list. References: <20200210170418.32076-1-zimon.toutoune@gmail.com> In-Reply-To: <20200210170418.32076-1-zimon.toutoune@gmail.com> Resent-Message-ID: From: zimoun Date: Tue, 18 Feb 2020 13:32:45 +0100 Message-Id: <20200218123246.32473-1-zimon.toutoune@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 39547@debbugs.gnu.org Cc: zimoun * website/apps/packages/builder.scm (origin->json): New procedure. --- website/apps/packages/builder.scm | 34 ++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/website/apps/packages/builder.scm b/website/apps/packages/builder.scm index 9dc44c9..d3a777e 100644 --- a/website/apps/packages/builder.scm +++ b/website/apps/packages/builder.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2017 Ludovic Courtès ;;; Copyright © 2019 Ricardo Wurmus ;;; Copyright © 2019 Nicolò Balzarotti +;;; Copyright © 2020 Simon Tournier ;;; ;;; Initially written by sirgazil ;;; who waives all copyright interest on this file. @@ -37,13 +38,16 @@ #:use-module (haunt page) #:use-module (haunt utils) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) #:use-module (guix packages) #:use-module (guix download) #:use-module (guix git-download) #:use-module (guix svn-download) #:use-module (guix utils) ;location + #:use-module ((guix build download) #:select (maybe-expand-mirrors)) #:use-module (json) #:use-module (ice-9 match) + #:use-module ((web uri) #:select (string->uri uri->string)) #:export (builder)) @@ -84,33 +88,43 @@ ;; Maximum number of packages shown on /packages. 30) -(define (packages-json-builder) - "Return a JSON page listing all packages." - (define (origin->json origin) +(define (origin->json origin) (define method (origin-method origin)) + (define uri ;represented as string + (origin-uri origin)) + + (define (resolve urls) + (map uri->string + (append-map (cut maybe-expand-mirrors <> %mirrors) + (map string->uri urls)))) + `((type . ,(cond ((eq? url-fetch method) 'url) ((eq? git-fetch method) 'git) ((eq? svn-fetch method) 'svn) (else #nil))) ,@(cond ((eq? url-fetch method) - `(("url" . ,(match (origin-uri origin) - ((? string? url) (vector url)) - ((urls ...) (list->vector urls)))))) + `(("url" . ,(list->vector + (resolve + (match uri + ((? string? url) (list url)) + ((urls ...) urls))))))) ((eq? git-fetch method) - `(("git_url" . ,(git-reference-url (origin-uri origin))))) + `(("git_url" . ,(git-reference-url uri)))) ((eq? svn-fetch method) - `(("svn_url" . ,(svn-reference-url (origin-uri origin))))) + `(("svn_url" . ,(svn-reference-url uri)))) (else '())) ,@(if (eq? method git-fetch) - `(("git_ref" . ,(git-reference-commit (origin-uri origin)))) + `(("git_ref" . ,(git-reference-commit uri))) '()) ,@(if (eq? method svn-fetch) `(("svn_revision" . ,(svn-reference-revision - (origin-uri origin)))) + uri))) '()))) +(define (packages-json-builder) + "Return a JSON page listing all packages." (define (package->json package) (define cpe-name (assoc-ref (package-properties package) 'cpe-name)) -- 2.25.0