From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id wGQ1MjJId2CJDwAAgWs5BA (envelope-from ) for ; Wed, 14 Apr 2021 21:53:22 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 2GvvKzJId2DRMAAAbx9fmQ (envelope-from ) for ; Wed, 14 Apr 2021 19:53:22 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5205218C5E for ; Wed, 14 Apr 2021 21:53:22 +0200 (CEST) Received: from localhost ([::1]:53072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWlZg-0006dW-U8 for larch@yhetil.org; Wed, 14 Apr 2021 15:53:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWlVs-0004ez-70 for guix-devel@gnu.org; Wed, 14 Apr 2021 15:49:24 -0400 Received: from mout02.posteo.de ([185.67.36.66]:36679) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWlVk-0004V3-RH for guix-devel@gnu.org; Wed, 14 Apr 2021 15:49:23 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 4D5932400E5 for ; Wed, 14 Apr 2021 21:49:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1618429752; bh=aBRnSoDfkSDCNsoz0uvTDsNJyz8kbDw/S8C4fjJxvPg=; h=Date:From:To:Subject:From; b=WnbFd8xTp8uhOZR0/7/i9bSwv9CtqPMXufPu92fuotoeuv8PA1En3bAwkcilnXcXg DwAI8CT1qFGchUzBO9Aw0z9GTaErS/wNPauHf0SGpSIm0fDT+iGniKUZCiBgIlMjOA nPjC6B4AbMNDyvx/iqIxSD05zwVEC2+Y2N00w7gSPm1dzlpOU4VXCVVPNJr3ZP1pgy AtuDvwwmmciKiuGhM0y1OlP/Wf+W5sWw/YP/4TE5ni4jLdy4EX4N3e2grl5fCiWg8m IEFAFOh/8gkEYGRf9IyQzGAk99l0muP5VrsVr07leD168adsIZ0cU6fLi8ylPimjN6 GcFe696zHIItQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4FLCj23bTyz9rxQ for ; Wed, 14 Apr 2021 21:49:10 +0200 (CEST) Date: Wed, 14 Apr 2021 16:48:59 -0300 From: Luciana Lima Brito To: guix-devel@gnu.org Subject: Outreachy - Guix Data Service: implementing basic json output for derivation comparison page Message-ID: <20210414164859.7acc631f@lubrito> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/8ROSF63y_LPET02aqBt_jI8" Received-SPF: pass client-ip=185.67.36.66; envelope-from=lubrito@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list 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+larch=yhetil.org@gnu.org Sender: "Guix-devel" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1618430002; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=EvxZtRXw2OZhqz5C5YfA+BTD0ddxzQvzVkbVgEZiAjs=; b=U3Fvk8v+hny5vVFI0+JysXWzgJOhczWxRtRpEKBeqRUHROuNh1Xr+Z8PRs/X+Uy6VbmPZo JCjQjyYMyB/sk1bZIiwlqGXZyrsIOWsE8hcWfNnwRDHARCSTFHUuD76udxauA8sihDu3gD M4UPhNxyjG0jPxrvzXLXUj9duvMNaIhuOuQQwbgyn5uCgqe0shhQrTYzGz4hjOBzUQGty2 kOKN0z+BeXsjWYMl6G/RMBQ3Su3JciSW6WXyb/VN6hVPk9wjg5HUfO5itbW3gYP+NrrRjo N5yoHgOCOHfyd4OZI1akL/PUtEtZ/EpNROwTjHR1WP4ehABF9uNk3/pMxY2n2A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1618430002; a=rsa-sha256; cv=none; b=Tf54zYR0+GfAmoqsVmwhA/hUHzuiaSK6DKom9kvdGHff6aJXQA1kuZpvo73g7R/nvQfZds khDY7oIQlMRcL5fNjmS2zXxc8a1ZD/zUldsBcFF9VQZX1BB/7NPAMKySDA3eWo7wuoUcWA 3BZESwXeoVzc/H+PSTxv0xQQuNzshbslxJuzcbBOJ4T9nykd9AiMI3rjbQKovUYN6R2Vxj YOQwfFsM+FfUmqZ/Cfs9mIxXYiW+VbDGzuQQWqIyuZyavbWM4vSJOXKYftdfFDcZJSh49C Ny/E1gUam2vsOlFgfGrRIg7gFH6rDlx9cuozq7d3Gee1WUDMuWi/h9tVuCTkcw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=WnbFd8xT; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of guix-devel-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-devel-bounces@gnu.org X-Migadu-Spam-Score: -2.64 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=WnbFd8xT; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of guix-devel-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-devel-bounces@gnu.org X-Migadu-Queue-Id: 5205218C5E X-Spam-Score: -2.64 X-Migadu-Scanner: scn0.migadu.com X-TUID: QAsgnYBBa4tP --MP_/8ROSF63y_LPET02aqBt_jI8 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, I implemented a basic json output for the derivation comparison page, for my first contribution as an Outreachy applicant. The patch for the code I've changed is attached. I'm waiting your reviews :) -- Best Regards, Luciana Lima Brito MSc. in Computer Science --MP_/8ROSF63y_LPET02aqBt_jI8 Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=controller.patch diff --git a/guix-data-service/web/compare/controller.scm b/guix-data-service/web/compare/controller.scm index a6aa198..b7788cb 100644 --- a/guix-data-service/web/compare/controller.scm +++ b/guix-data-service/web/compare/controller.scm @@ -584,19 +584,115 @@ (derivation-differences-data conn base-derivation target-derivation))))) - (case (most-appropriate-mime-type - '(application/json text/html) - mime-types) - ((application/json) - (render-json - '((error . "unimplemented")) ; TODO - #:extra-headers http-headers-for-unchanging-content)) - (else - (render-html - #:sxml (compare/derivation - query-parameters - data) - #:extra-headers http-headers-for-unchanging-content))))))) + (let ((outputs (assq-ref data 'outputs)) + (inputs (assq-ref data 'inputs)) + (sources (assq-ref data 'sources)) + (system (assq-ref data 'system)) + (builder (assq-ref data 'builder)) + (args (assq-ref data 'arguments)) + (environment-variables (assq-ref data 'environment-variables)) + (get-derivation-data + (lambda (items) + (map + (match-lambda + ((name path hash-alg hash recursive) + `(,@(if (null? name) + '() + `((name . ,name))) + ,@(if (null? path) + '() + `((path . ,path)) + ) + ,@(if (or (null? hash-alg) (not (string? hash-alg))) + '() + `((hash-algorithm . ,hash-alg)) + ) + ,@(if (or (null? hash) (not (string? hash))) + '() + `((hash . ,hash)) + ) + ,@(if (null? recursive) + '() + `((recursive . ,(string=? recursive "t")))))) + ((derivation output) + `(,@(if (null? derivation) + '() + `((derivation . ,derivation))) + ,@(if (null? output) + '() + `((output . ,output))))) + ((derivation) + `(,@(if (null? derivation) + '() + `((derivation . ,derivation)))))) + (or items '()))))) + + (let ((base-system (assq-ref system 'base)) + (target-system (assq-ref system 'target)) + (common-system (assq-ref system 'common)) + + (base-builder (assq-ref builder 'base)) + (target-builder (assq-ref builder 'target)) + (common-builder (assq-ref builder 'common)) + + (base-args (assq-ref args 'base)) + (target-args (assq-ref args 'target)) + (common-args (assq-ref args 'common))) + + (let ((matched-outputs (append-map get-derivation-data + (list (assq-ref outputs 'base) + (assq-ref outputs 'target) + (assq-ref outputs 'common)))) + (matched-inputs (append-map get-derivation-data + (list (assq-ref inputs 'base) + (assq-ref inputs 'target)))) + (matched-sources (append-map get-derivation-data + (list (assq-ref sources 'base) + (assq-ref sources 'target) + (assq-ref sources 'common))))) + (case (most-appropriate-mime-type + '(application/json text/html) + mime-types) + ((application/json) + (render-json + `((revision + . ((base + . ((derivation . ,base-derivation))) + (target + . ((derivation . ,target-derivation))))) + (outputs + . ,((lambda (l) (cond + ((= (length l) 3) `((base . ,(first l)) + (target . ,(second l)) + (common . ,(third l)))) + ((= (length l) 2) `((base . ,(first l)) + (target . ,(second l)))) + (else `((common . ,(first l)))))) + matched-outputs)) + (inputs + . ((base . ,(first matched-inputs)) + (target . ,(second matched-inputs)))) + (source + . ((base . ,(first matched-sources)) + (target . ,(second matched-sources)) + (common . ,(third matched-sources)))) + (system + . ((common . ,common-system))) + (builder-and-arguments + . ((builder . ,common-builder) + (arguments + . ((base . ,(list->vector + base-args)) + (target . ,(list->vector + target-args)))))) + (environment-variables . ,environment-variables)) + #:extra-headers http-headers-for-unchanging-content)) + (else + (render-html + #:sxml (compare/derivation + query-parameters + data) + #:extra-headers http-headers-for-unchanging-content)))))))))) (define (render-compare/package-derivations mime-types query-parameters) --MP_/8ROSF63y_LPET02aqBt_jI8--