From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Craven Subject: [PATCH 03/12] import: utils: Add some utilities. Date: Sun, 11 Dec 2016 18:25:28 +0100 Message-ID: <20161211172537.23315-4-david@craven.ch> References: <20161211172537.23315-1-david@craven.ch> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cG7tB-0008Ng-35 for guix-devel@gnu.org; Sun, 11 Dec 2016 12:26:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cG7tA-0001CZ-2Z for guix-devel@gnu.org; Sun, 11 Dec 2016 12:26:17 -0500 Received: from so254-10.mailgun.net ([198.61.254.10]:21343) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cG7t9-00015w-U9 for guix-devel@gnu.org; Sun, 11 Dec 2016 12:26:16 -0500 In-Reply-To: <20161211172537.23315-1-david@craven.ch> 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" To: guix-devel@gnu.org * gnu/import/utils.scm (json-fetch, maybe-inputs, maybe-native-inputs, package->definition): New variables. --- guix/import/utils.scm | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/guix/import/utils.scm b/guix/import/utils.scm index 057c2d9c7..e2e90676a 100644 --- a/guix/import/utils.scm +++ b/guix/import/utils.scm @@ -22,6 +22,8 @@ #:use-module (guix base32) #:use-module ((guix build download) #:prefix build:) #:use-module (guix hash) + #:use-module (guix http-client) + #:use-module (json) #:use-module ((guix licenses) #:prefix license:) #:use-module (guix utils) #:use-module (ice-9 match) @@ -34,8 +36,13 @@ assoc-ref* url-fetch + json-fetch guix-hash-url + maybe-inputs + maybe-native-inputs + package->definition + spdx-string->license license->symbol @@ -205,3 +212,39 @@ into a proper sentence and by using two spaces between sentences." ;; Use double spacing between sentences (regexp-substitute/global #f "\\. \\b" cleaned 'pre ". " 'post))) + +(define (package-names->package-inputs names) + (map (lambda (input) + (list input (list 'unquote (string->symbol input)))) + names)) + +(define (maybe-inputs package-names) + "Given a list of PACKAGE-NAMES, tries to generate the 'inputs' field of a +package definition." + (match (package-names->package-inputs package-names) + (() + '()) + ((package-inputs ...) + `((inputs (,'quasiquote ,package-inputs)))))) + +(define (maybe-native-inputs package-names) + "Given a list of PACKAGE-NAMES, tries to generate the 'inputs' field of a +package definition." + (match (package-names->package-inputs package-names) + (() + '()) + ((package-inputs ...) + `((native-inputs (,'quasiquote ,package-inputs)))))) + +(define* (json-fetch url) + "Return an alist representation of the url metadata." + (let* ((port (http-fetch url)) + (result (json->scm port))) + (close-port port) + (hash-table->alist result))) + +(define (package->definition guix-package) + (match guix-package + (('package ('name (? string? name)) _ ...) + `(define-public ,(string->symbol name) + ,guix-package)))) -- 2.11.0