1 |
-----BEGIN PGP SIGNED MESSAGE----- |
2 |
Hash: SHA1 |
3 |
|
4 |
Well, I've been trying to post this all day, probably soon three |
5 |
different copies will turn up at once . . . |
6 |
|
7 |
- ---------------------------------------------------------- |
8 |
#! /usr/bin/env python2.2 |
9 |
|
10 |
# Very simple program that searches the /usr/portage tree for |
11 |
# ebuilds that match a key provided by the user. |
12 |
|
13 |
from os.path import splitext, walk, isdir |
14 |
import re |
15 |
|
16 |
portageRoot = "/usr/portage" |
17 |
installRoot = "/var/db/pkg" |
18 |
|
19 |
# inelegant routine to assemble the install directory that is associated |
20 |
# with a given portage directory |
21 |
def getinstalldir(portagedir): |
22 |
path = portagedir.split('/') |
23 |
installdir = installRoot |
24 |
for dir in path[3:-1]: |
25 |
installdir += "/" + dir |
26 |
return installdir |
27 |
|
28 |
# workhorse routine: for each directory look for ebuild files and |
29 |
# interrogate each ebuild file to see if it matches the key and, |
30 |
# if it does, also check to see if it is installed. |
31 |
def visit(key, dirname, files): |
32 |
for file in files: |
33 |
(base, ext) = splitext(file) |
34 |
if (ext == ".ebuild"): |
35 |
if (re.search(key.lower(), base.lower())): |
36 |
# package found. Is it also installed? |
37 |
installname = getinstalldir(dirname) + '/' + base |
38 |
if (isdir(installname)): |
39 |
print dirname + "/" + file + "\t (installed)" |
40 |
else: |
41 |
print dirname + "/" + file |
42 |
|
43 |
|
44 |
if __name__ == '__main__': |
45 |
import sys |
46 |
if (len(sys.argv) != 2): |
47 |
print "Usage: pkgsearch key" |
48 |
sys.exit(1) |
49 |
key = sys.argv[1] |
50 |
walk(portageRoot, visit, key) |
51 |
|
52 |
- ---------------------------------------------------------- |
53 |
|
54 |
Hopefully no indentation/wrapping problems! |
55 |
|
56 |
HTH, |
57 |
|
58 |
- -- |
59 |
- ------------------------------------------------------------------------ |
60 |
Ian Smith |
61 |
Worst . . . signature . . . ever ! |
62 |
- ------------------------------------------------------------------------ |
63 |
-----BEGIN PGP SIGNATURE----- |
64 |
Version: GnuPG v1.0.7 (GNU/Linux) |
65 |
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org |
66 |
|
67 |
iD8DBQE9XBZRhzSkrHqkFB4RAmH4AJ4oyu9JSe9oq77+XwsAz/tByPgSqgCgsu8D |
68 |
P64cFRHvCjDeky/sSh1cECQ= |
69 |
=ELrD |
70 |
-----END PGP SIGNATURE----- |