Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (47 sloc) 1.29 KB
import ibb
import re
KNOWN_EXTENSIONS = [
'.cpp',
'.hpp',
'.c',
'.as',
'.h',
'.py',
'.js',
]
class SourceListNode(ibb.Node):
def __init__(self, sourceDir):
ibb.Node.__init__(self)
self.__sourceDir = sourceDir
self.__dirty = True
self.__sourceList = []
self.addDependency(sourceDir)
sourceDir.addDependent(self)
def invalidate(self):
ibb.Node.invalidate(self)
self.__dirty = True
self.__sourceList = True
@property
def value(self):
if self.__dirty:
self.build()
return self.__sourceList
def build(self):
self.__sourceList = [
node
for node in self.__sourceDir.walk()
if any(node.abspath.endswith(ext) for ext in KNOWN_EXTENSIONS)]
self.__dirty = False
sourceDir = build.File('Source')
sourceList = SourceListNode(sourceDir)
@build.subcommand
def search(args):
[pattern] = args
matcher = re.compile(pattern.encode('ascii'))
for node in sourceList.value:
q = matcher.search(node.data)
if q:
d = node.data.decode('ascii')
s = q.span()
l = 1 + int(d[0:s[1]].count("\n"))
print(node.abspath + "(" + str(l) + "): " + d[s[0]:s[1]])
You can’t perform that action at this time.