From: Nikita Karetnikov <nikita@karetnikov.org>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: bug-guix@gnu.org
Subject: Re: guix-package --search
Date: Wed, 23 Jan 2013 10:33:30 -0500 [thread overview]
Message-ID: <87r4lb29sy.fsf@karetnikov.org> (raw)
In-Reply-To: <87obgi6v7f.fsf@gnu.org> ("Ludovic Courtès"'s message of "(unknown date)")
[-- Attachment #1.1: Type: text/plain, Size: 1036 bytes --]
> Instead, you can directly build the list of matching packages, like:
> (fold-packages (lambda (package result)
> (if (or (regexp-exec rx (package-synopsis package))
> (regexp-exec rx (package-description package)))
> (cons package result)
> result))
> '())
> This way, only one traversal is done.
'regexp-exec' will raise an error if either 'synopsis' or 'description'
is not a string. That's why I wrapped it in 'false-if-exception'.
> For i18n, we should actually use (gettext (package-description
> package)), likewise for synopsis. This way, that will search through
> text in the user’s native language.
I added it, but I haven't properly tested it. Also, there is
'remove-duplicates' that works in the REPL. But it doesn't remove
duplicates when I call it via 'guix-package -s'. (Sometimes they appear
and sometimes they don't show up.) Anyway, I'm attaching the patch.
Nikita
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-guix-package-Add-search.patch --]
[-- Type: text/x-diff, Size: 4229 bytes --]
From a365d7f796d0db711bb67902f65826af9e951d06 Mon Sep 17 00:00:00 2001
From: Nikita Karetnikov <nikita@karetnikov.org>
Date: Wed, 23 Jan 2013 15:22:34 +0000
Subject: [PATCH] guix-package: Add '--search'.
* guix-package.in (find-packages-by-description): New procedure.
(show-help): Add '--search'.
(%options): Likewise.
(guix-package)[process-query]: Add support for '--search'.
---
guix-package.in | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/guix-package.in b/guix-package.in
index 85ac358..16a268b 100644
--- a/guix-package.in
+++ b/guix-package.in
@@ -229,6 +229,39 @@ all of PACKAGES, a list of name/version/output/path tuples."
(leave (_ "error: no previous profile; not rolling back~%")))
(else (switch-link)))))
+(define (find-packages-by-description rx)
+ "Search in SYNOPSIS and DESCRIPTION using RX. Return a list of
+matching packages."
+ (define (remove-duplicates pred lst)
+ ;; Remove duplicates from sorted LST using PRED.
+ (cond ((null-list? lst) lst)
+ ((= (length lst) 1) lst)
+ ((= (length lst) 2)
+ (if (pred (first lst) (second lst)) (cdr lst) lst))
+ ((pred (first lst) (second lst))
+ (remove-duplicates pred (cdr lst)))
+ (else (cons (first lst) (remove-duplicates pred (cdr lst))))))
+
+ (define (same-location? p1 p2)
+ ;; Compare locations of two packages.
+ (eq? (package-location p1) (package-location p2)))
+
+ (remove-duplicates
+ same-location?
+ (stable-sort
+ (fold-packages
+ (lambda (package result)
+ (if (or (false-if-exception
+ (regexp-exec rx (gettext (package-synopsis package))))
+ (false-if-exception
+ (regexp-exec rx (gettext (package-description package)))))
+ (cons package result)
+ result))
+ '())
+ (lambda (p1 p2)
+ (string<? (package-name p1)
+ (package-name p2))))))
+
\f
;;;
;;; Command-line options.
@@ -251,6 +284,8 @@ Install, remove, or upgrade PACKAGES in a single transaction.\n"))
--roll-back roll back to the previous generation"))
(newline)
(display (_ "
+ -s, --search=REGEXP search in synopsis and description using REGEXP"))
+ (display (_ "
-p, --profile=PROFILE use PROFILE instead of the user's default profile"))
(display (_ "
-n, --dry-run show what would be done without actually doing it"))
@@ -305,6 +340,10 @@ Install, remove, or upgrade PACKAGES in a single transaction.\n"))
(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 ""))
@@ -525,6 +564,7 @@ Install, remove, or upgrade PACKAGES in a single transaction.\n"))
name (or version "?") output path))))
installed)
#t))
+
(('list-available regexp)
(let* ((regexp (and regexp (make-regexp regexp)))
(available (fold-packages
@@ -547,6 +587,16 @@ Install, remove, or upgrade PACKAGES in a single transaction.\n"))
(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))))
+ (find-packages-by-description regexp))
+ #t))
(_ #f))))
(setlocale LC_ALL "")
--
1.7.5.4
[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]
next prev parent reply other threads:[~2013-01-23 15:33 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
2013-01-21 22:13 ` Ludovic Courtès
2013-01-23 15:33 ` Nikita Karetnikov [this message]
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
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r4lb29sy.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 public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).