From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: [PATCH] gnu-maintenance: Add 'find-package-with-attrs' and '%package-list'. Date: Fri, 22 Feb 2013 11:00:03 +0100 Message-ID: <87sj4ok6sc.fsf@gnu.org> References: <87obfchq38.fsf@karetnikov.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:44065) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8pQY-00046c-7e for bug-guix@gnu.org; Fri, 22 Feb 2013 05:00:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U8pQN-00007a-2Z for bug-guix@gnu.org; Fri, 22 Feb 2013 05:00:25 -0500 Received: from [2a01:e0b:1:123:ca0a:a9ff:fe03:271e] (port=46950 helo=xanadu.aquilenet.fr) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8pQM-0008Rk-Pg for bug-guix@gnu.org; Fri, 22 Feb 2013 05:00:15 -0500 In-Reply-To: <87obfchq38.fsf@karetnikov.org> (Nikita Karetnikov's message of "Fri, 22 Feb 2013 00:29:47 -0500") List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org To: Nikita Karetnikov Cc: bug-guix@gnu.org Hi, Nikita Karetnikov skribis: > This patch adds a procedure to fetch information from Womb. Nice! > scheme@(guile-user)> ,use (guix gnu-maintenance) > scheme@(guile-user)> (find-package-with-attrs "guix") > $1 =3D ("package: guix" "logo: /software/guix/graphics/guix-logo.small.pn= g" "doc-category: Sysadmin" "doc-summary: Managing installed software packa= ges and versions" "doc-url: none" "gplv3-status: should-be-ok" "activity-st= atus: newpkg/20121117") Instead of adding a new procedure, what about having this one replace =E2=80=98official-gnu-packages=E2=80=99? It does basically the same, just = provides more info. Also, I think it should process fields, and return an alist, or even better, a =E2=80=98gnu-package-descriptor=E2=80=99 record (say). (define-record-type gnu-package-descriptor? (gnu-package-descriptor name logo-url doc-category ...) ... ) (official-gnu-packages) =3D> (# = ...) WDYT? > Also, it should be possible to get a single attribute (e.g., > 'doc-summary'), not all of them. I'll implement that later. It has to read all of the Womb file anyway, so better return all the information (like above), and let code filter what it wants. > The goal is to use this procedure from 'guix import'. Cool! > +(define %package-list > + (string-split (http-fetch %package-list-url) #\nl)) Please don=E2=80=99t make it a global variable. Instead, fetch it when it= =E2=80=99s asked. We could have some sort of a cache eventually, if we happen to call it several times in a row. Also, instead of fetching it entirely in memory, rather use =E2=80=98http-g= et*=E2=80=99 (Guile 2.0.7) or =E2=80=98(http-get ... #:streaming? #t)=E2=80=99 (Guile 2.= 0.8) to get an input port to the file. Then you can write a loop that processes the package list line-by-line (using =E2=80=98read-line=E2=80=99 from (ice-9 rdelim)), with a basic state= machine to determine if you=E2=80=99ve reach the end of a package descriptor. > +(define (find-package-with-attrs package) > + "Return a list that contains PACKAGE and its attributes." > + (define (split-womb-packages xs ys) > + ;; Return a list of lists; each inner list represents a package. > + (define (tail lst) > + (if (null-list? lst) > + lst > + (cdr lst))) > + > + (cond ((null-list? ys) (filter (lambda (lst) > + (not (null-list? lst))) > + xs)) > + (else (let-values (((xs' ys') (span (lambda (str) > + (not (string-null? str))) > + ys))) > + (split-womb-packages (append xs (list xs')) > + (tail ys')))))) In general, you should use =E2=80=98match=E2=80=99 from (ice-9 match) for t= hese things. It will make your life brighter. :-) HTH, Ludo=E2=80=99.