all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nikita Karetnikov <nikita@karetnikov.org>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: bug-guix@gnu.org
Subject: [PATCH] gnu-maintenance: Replace 'official-gnu-packages' with 'find-packages'.
Date: Wed, 06 Mar 2013 22:54:34 +0400	[thread overview]
Message-ID: <87sj48gxzp.fsf_-_@karetnikov.org> (raw)
In-Reply-To: <87sj4ok6sc.fsf@gnu.org> ("Ludovic Courtès"'s message of "(unknown date)")


[-- Attachment #1.1: Type: text/plain, Size: 1074 bytes --]

> 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?

Oh, I forgot about this when I was writing the attached patch.  Is it
fine?  Should I rewrite it using records?

I guess that it will work faster if I use 'cons' in 'loop' instead of
'append'.  Is it worth it?

Examples:

scheme@(guile-user)> ,use (guix gnu-maintenance)
scheme@(guile-user)> (find-packages "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"))

This one:

  (find-packages "guile")

should return several packages.


[-- Attachment #1.2: 0001-gnu-maintenance-Replace-official-gnu-packages-with-f.patch --]
[-- Type: text/x-diff, Size: 3943 bytes --]

From 85f9588d0502a7dd4a1e2c30f8ba54fcb300cca8 Mon Sep 17 00:00:00 2001
From: Nikita Karetnikov <nikita@karetnikov.org>
Date: Wed, 6 Mar 2013 18:24:50 +0000
Subject: [PATCH] gnu-maintenance: Replace 'official-gnu-packages' with
 'find-packages'.

* guix/gnu-maintenance.scm (http-fetch): Use 'http-get*' and return a port.
  (official-gnu-packages): Replace with 'find-packages'.
---
 guix/gnu-maintenance.scm |   56 +++++++++++++++++++++++++++++++--------------
 1 files changed, 38 insertions(+), 18 deletions(-)

diff --git a/guix/gnu-maintenance.scm b/guix/gnu-maintenance.scm
index cde31aa..6344ebe 100644
--- a/guix/gnu-maintenance.scm
+++ b/guix/gnu-maintenance.scm
@@ -1,6 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012 Nikita Karetnikov <nikita@karetnikov.org>
 ;;; Copyright © 2010, 2011, 2012, 2013 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012, 2013 Nikita Karetnikov <nikita@karetnikov.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -23,6 +23,7 @@
   #:use-module (web response)
   #:use-module (ice-9 regex)
   #:use-module (ice-9 match)
+  #:use-module (ice-9 rdelim)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-11)
   #:use-module (srfi srfi-26)
@@ -30,7 +31,7 @@
   #:use-module (guix ftp-client)
   #:use-module (guix utils)
   #:use-module (guix packages)
-  #:export (official-gnu-packages
+  #:export (find-packages
             gnu-package?
             releases
             latest-release
@@ -49,16 +50,16 @@
 ;;;
 
 (define (http-fetch uri)
-  "Return a string containing the textual data at URI, a string."
-  (let*-values (((resp data)
-                (http-get (string->uri uri)))
-               ((code)
-                (response-code resp)))
+  "Return an input port with the textual data at URI, a string."
+  (let*-values (((resp port)
+                 (http-get* (string->uri uri)))
+                ((code)
+                 (response-code resp)))
     (case code
       ((200)
-       data)
+       port)
       (else
-       (error "download failed:" uri code
+       (error "download failed" uri code
               (response-reason-phrase resp))))))
 
 (define %package-list-url
@@ -66,16 +67,35 @@
                  "viewvc/*checkout*/gnumaint/"
                  "gnupackages.txt?root=womb"))
 
-(define (official-gnu-packages)
-  "Return a list of GNU packages."
-  (define %package-line-rx
-    (make-regexp "^package: (.+)$"))
-
-  (let ((lst (string-split (http-fetch %package-list-url) #\nl)))
-    (filter-map (lambda (line)
-                  (and=> (regexp-exec %package-line-rx line)
-                         (cut match:substring <> 1)))
-                lst)))
+(define (find-packages regexp)
+  "Find packages that match REGEXP."
+  (let ((package-line-rx
+         (make-regexp (string-append "^package: " regexp "(.?)"))))
+
+    (define (group-packages port state)
+      ;; Return a list of packages.
+      (let ((line (read-line port)))
+        (define (loop str)
+          (match str
+            ('""
+             (group-packages port (append state '(()))))
+            (str
+             (group-packages port (append (drop-right state 1)
+                                          (list (append (last state)
+                                                        (list str))))))))
+
+        (if (eof-object? line)
+            (filter (lambda (lst)
+                      (not (null-list? lst)))
+                    state)
+            (loop line))))
+
+    (filter-map (lambda (sublst)
+                  (and=> (regexp-exec package-line-rx (first sublst))
+                         (lambda _
+                           sublst)))
+                (group-packages (http-fetch %package-list-url)
+                                '(())))))
 
 (define gnu-package?
   (memoize
-- 
1.7.5.4


[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

  reply	other threads:[~2013-03-06 18:53 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-22  5:29 [PATCH] gnu-maintenance: Add 'find-package-with-attrs' and '%package-list' Nikita Karetnikov
2013-02-22 10:00 ` Ludovic Courtès
2013-03-06 18:54   ` Nikita Karetnikov [this message]
2013-03-06 23:28     ` [PATCH] gnu-maintenance: Replace 'official-gnu-packages' with 'find-packages' Ludovic Courtès
2013-03-16 19:30       ` [PATCH] gnu-maintenance: Improve 'official-gnu-packages'; add the related procedures Nikita Karetnikov
2013-03-16 23:13         ` Ludovic Courtès
2013-03-22  1:37           ` Nikita Karetnikov
2013-03-22 10:08             ` Brandon Invergo
2013-03-22 12:30               ` Ludovic Courtès
2013-03-22 12:19             ` Ludovic Courtès
2013-03-26 20:22               ` Nikita Karetnikov
2013-03-26 20:50                 ` Ludovic Courtès
2013-03-26 20:59                   ` Nikita Karetnikov
2013-03-26 21:21                     ` Ludovic Courtès
2013-03-27  6:05                       ` Nikita Karetnikov
2013-03-27 10:08                         ` Ludovic Courtès
2013-03-31 22:50                           ` Ludovic Courtès
2013-03-26 20:49           ` Nikita Karetnikov
2013-03-26 21:02             ` Ludovic Courtès
2013-03-28  2:08               ` [PATCH] gnu-maintenance: Improve 'official-gnu-packages'; add " Nikita Karetnikov
2013-03-28 16:48                 ` Ludovic Courtès
2013-03-28 22:40                 ` Nikita Karetnikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sj48gxzp.fsf_-_@karetnikov.org \
    --to=nikita@karetnikov.org \
    --cc=bug-guix@gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.