1 |
On 2008/02/04, Ryan Hill <dirtyepic@g.o> wrote: |
2 |
> |
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 |
-- |
51 |
TGL. |
52 |
-- |
53 |
gentoo-dev@l.g.o mailing list |