Here is a short program I find useful.
#! /usr/bin/env python
import os, sys, tempfile
"""Greps the numarray source code"""
command = \
"""grep -n "%s" \
/usr/local/src/numarray-0.4/Include/numarray/arrayobject.h \
...
/usr/local/src/numarray-0.4/Lib/_ufunc.py \
...
/usr/local/src/numarray-0.4/Src/libnumarraymodule.c \
> %s
"""
if len(sys.argv) != 2:
raise Exception, 'program requires exactly one argument'
temp = tempfile.mktemp()
try:
os.system(command % (sys.argv[1], temp))
f = file(temp, 'r')
lines = f.read().splitlines()
f.close()
finally:
if os.path.exists(temp):
os.remove(temp)
common = len('/usr/local/src/numarray-0.4/')
d = {}
names = []
for line in lines:
line = line[common:]
colonloc = line.index(':')
name = line[:colonloc]
text = line[colonloc+1:]
if not d.has_key(name):
d[name] = []
names.append(name)
d[name].append(text)
for name in names:
if len(d[name]) == 0:
continue
print '%s:' % name
for text in d[name]:
print ' %s' % text
print
|