bug-guix
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] gnu-maintenance: Add 'find-package-with-attrs' and '%package


From: Ludovic Courtès
Subject: Re: [PATCH] gnu-maintenance: Add 'find-package-with-attrs' and '%package-list'.
Date: Fri, 22 Feb 2013 11:00:03 +0100
User-agent: Gnus/5.130005 (Ma Gnus v0.5) Emacs/24.2 (gnu/linux)

Hi,

Nikita Karetnikov <address@hidden> 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 = ("package: guix" "logo: /software/guix/graphics/guix-logo.small.png" 
> "doc-category: Sysadmin" "doc-summary: Managing installed software packages 
> and versions" "doc-url: none" "gplv3-status: should-be-ok" "activity-status: 
> newpkg/20121117")

Instead of adding a new procedure, what about having this one replace
‘official-gnu-packages’?  It does basically the same, just provides more
info.

Also, I think it should process fields, and return an alist, or even
better, a ‘gnu-package-descriptor’ record (say).

  (define-record-type <gnu-package-descriptor>
    gnu-package-descriptor?
    (gnu-package-descriptor name logo-url doc-category ...)
    ...
    )

  (official-gnu-packages)
  => (#<gnu-package-descriptor name: "guix" logo-url: "http://..."; ...#> ...)

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’t make it a global variable.  Instead, fetch it when it’s
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 ‘http-get*’
(Guile 2.0.7) or ‘(http-get ... #:streaming? #t)’ (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 ‘read-line’ from (ice-9 rdelim)), with a basic state machine to
determine if you’ve 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 ‘match’ from (ice-9 match) for these things.
It will make your life brighter.  :-)

HTH,
Ludo’.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]