all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nikita Karetnikov <nikita@karetnikov.org>
To: bug-guix@gnu.org
Subject: Re: guix-package --search
Date: Sun, 20 Jan 2013 16:40:38 -0500	[thread overview]
Message-ID: <87r4lfr0r3.fsf@karetnikov.org> (raw)
In-Reply-To: <87libor1c9.fsf@karetnikov.org> (Nikita Karetnikov's message of "(unknown date)")


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

Hi,

I'm attaching the diff.

Some comments:

1. 'psd-list' is a potential bottleneck.  It will cause problems when we
   have more packages.  If it's possible to evaluate it lazily, I'll
   rewrite it.  (I haven't checked yet.)

2. The above is valid for 'package?' too.  Also, it's probably possible
   to rewrite it using 'match', but I haven't found a way to do so.

3. The command-line part just mimics 'list-available'.  (Maybe there is
   a better way.)

4. I've noticed that 'fold-packages' returns duplicates.  Should it be
   fixed?  Should I filter the output instead?

   Examples:

   # ./pre-inst-env guile
   scheme@(guile-user)> ,use (guix ui) (gnu packages) (guix packages)
   scheme@(guile-user)> (for-each display
                                  (sort 
                                   (map (lambda (x) 
                        		          (string-append (package-name x) " "
                                                         (location->string (package-location x))
                                                         "\n"))
				                        (fold-packages cons '()))
                                   string<?))
   [...]

   glibc gnu/packages/base.scm:497:3
   glibc gnu/packages/base.scm:497:3

   [...]

   guile gnu/packages/guile.scm:93:3
   guile gnu/packages/guile.scm:93:3

   # ./pre-inst-env guix-package -s "C library"

   [...]

   glibc   2.17    gnu/packages/base.scm:497:3
   glibc   2.17    gnu/packages/base.scm:497:3

   # ./pre-inst-env guix-package -s Guile

   [...]

   guile   2.0.7   gnu/packages/guile.scm:93:3
   guile   2.0.7   gnu/packages/guile.scm:93:3

Nikita


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: guix-package-search.diff --]
[-- Type: text/x-diff, Size: 2973 bytes --]

--- guix-package-orig	2013-01-20 16:43:13.000000000 +0000
+++ guix-package	2013-01-20 20:47:38.000000000 +0000
@@ -230,6 +230,32 @@
            (leave (_ "error: no previous profile; not rolling back~%")))
           (else (switch-link)))))
 
+(define (sd-search rx)
+  "Search in SYNOPSIS and DESCRIPTION using RX.  Return a list of
+matching packages."
+  (define psd-list
+    ;; Return a list of lists (each inner list contains PACKAGE-NAME,
+    ;; SYNOPSIS, and DESCRIPTION of every package).
+    (map (lambda (x)
+           (list x (package-synopsis x) (package-description x)))
+         (fold-packages cons '())))
+
+  (define (matcher str)
+    ;; Match RX against STR.  Return the result or #f if nothing was
+    ;; found.
+    (false-if-exception (match:substring (regexp-exec rx str) 0)))
+
+  (define (package? lst)
+    ;; Return PACKAGE wrapped in a list or '() if match failed.
+    (if (any (cut matcher <>) (list (cadr lst) (caddr lst)))
+        (list (car lst))
+        '()))
+
+  (sort (append-map package? psd-list)
+        (lambda (p1 p2)
+          (string<? (package-name p1)
+                    (package-name p2)))))
+
 \f
 ;;;
 ;;; Command-line options.
@@ -261,6 +287,8 @@
       --verbose          produce verbose output"))
   (newline)
   (display (_ "
+  -s, --search=REGEXP    search in synopsis and description using REGEXP"))
+  (display (_ "
   -I, --list-installed[=REGEXP]
                          list installed packages matching REGEXP"))
   (display (_ "
@@ -306,6 +334,10 @@
         (option '("verbose") #f #f
                 (lambda (opt name arg result)
                   (alist-cons 'verbose? #t result)))
+        (option '(#\s "search") #t #f
+                  (lambda (opt name arg result)
+                    (cons `(query search ,(or arg ""))
+                          result)))
         (option '(#\I "list-installed") #f #t
                 (lambda (opt name arg result)
                   (cons `(query list-installed ,(or arg ""))
@@ -526,6 +558,7 @@
                                  name (or version "?") output path))))
                      installed)
            #t))
+
         (('list-available regexp)
          (let* ((regexp    (and regexp (make-regexp regexp)))
                 (available (fold-packages
@@ -548,6 +581,16 @@
                              (string<? (package-name p1)
                                        (package-name p2)))))
            #t))
+
+        (('search regexp)
+         (let ((regexp (and regexp (make-regexp regexp))))
+           (for-each (lambda (p)
+                       (format #t "~a\t~a\t~a~%"
+                               (package-name p)
+                               (package-version p)
+                               (location->string (package-location p))))
+                     (sd-search regexp))
+           #t))
         (_ #f))))
 
   (setlocale LC_ALL "")

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

  reply	other threads:[~2013-01-20 21:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-20  3:15 guix-package --search Nikita Karetnikov
2013-01-20 21:40 ` Nikita Karetnikov [this message]
2013-01-21 22:13   ` Ludovic Courtès
2013-01-23 15:33     ` Nikita Karetnikov
2013-01-24 21:14       ` Ludovic Courtès
2013-01-26  8:55         ` [PATCH] guix-package: Add '--search'. (was: guix-package --search) Nikita Karetnikov
2013-01-26 21:43           ` [PATCH] guix-package: Add '--search' Ludovic Courtès

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=87r4lfr0r3.fsf@karetnikov.org \
    --to=nikita@karetnikov.org \
    --cc=bug-guix@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.