Gentoo Archives: gentoo-dev

From: Ryan Hill <dirtyepic@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] Re: I want to steal your tools
Date: Mon, 04 Feb 2008 23:03:41
Message-Id: fo85jd$gld$1@ger.gmane.org
In Reply to: Re: [gentoo-dev] Re: I want to steal your tools by Thomas de Grenier de Latour
1 Thomas de Grenier de Latour wrote:
2 > On 2008/02/04, Ryan Hill <dirtyepic@g.o> wrote:
3 >> Can someone provide a tool that given a package name simply prints
4 >> the category or cat/pkg, or if ambiguous, prints the multiple
5 >> cat/pkgs or returns an error code? I don't care what it's written in
6 >> as long as it's relatively quick.
7 >
8 > As long as you're only interrested in stuffs from the Portage tree,
9 > and not overlays, and you have portage-utils installed along with its
10 > post-sync hook, you can use one of this function:
11 >
12 > find_cat1() {
13 > qsearch -CsN "^${1}$"
14 > }
15 >
16 > find_cat2() {
17 > sed -n "\\|/${1}/|s:/[^/]*\$::p" "${PORTDIR}"/.ebuild.x \
18 > | uniq
19 > }
20 >
21 > Note that find_cat1() is case-insensitive, probably not what you want.
22 >
23 > And without portage-utils' ebuilds cache, this works too:
24 >
25 > find_cat3() {
26 > pushd "${PORTDIR}" >/dev/null
27 > ls -1d $(sed "s:\$:/${1}:" profiles/categories) 2>/dev/null
28 > popd >/dev/null
29 > }
30 >
31 > Here are some benchs (real time, with 1 run from cold I/O cache, and
32 > then 100 runs also from cold I/O cache, with "fuse" as argument):
33 >
34 > * find_cat1:
35 > - 0m0.972s
36 > - 0m25.967s
37 > (No real advantage... that's not the primary target of this applet.)
38 >
39 > * find_cat2:
40 > - 0m0.237s
41 > - 0m3.746s
42 > (Acceptable in both cases.)
43 >
44 > * find_cat3:
45 > - 0m2.319s
46 > - 0m2.607s
47 > (Really slow on first run, but really fast once the tree as been
48 > walked. May be a good choice in some contexts.)
49
50 Perfect! I'll tinker with these and see what I come up with.
51
52 Thanks.
53
54
55 --
56 fonts, by design, by neglect
57 gcc-porting, for a fact or just for effect
58 wxwindows @ gentoo EFFD 380E 047A 4B51 D2BD C64F 8AA8 8346 F9A4 0662

Attachments

File name MIME type
signature.asc application/pgp-signature