-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.ibb
executable file
·80 lines (71 loc) · 2.23 KB
/
main.ibb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import ibb
import re
KNOWN_EXTENSIONS = [
'.js',
'.html',
'.css',
'.scss',
'.tml',
'.hb',
]
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
_sourceListNodes = []
for sourceDir in ['src', 'fakes', 's', 'bin', 'tests']:
_sourceListNodes.append(SourceListNode(build.File(sourceDir)))
@build.subcommand
def search(args):
count = 0
[pattern] = args
matcher = re.compile(pattern.encode('latin-1'), re.IGNORECASE)
for sourceListNode in _sourceListNodes:
for node in sourceListNode.value:
if node.data is None:
continue
q = matcher.search(node.data)
if q:
d = node.data.decode('latin-1')
s = q.span()
l = 0
printed = False
for lin in d.splitlines():
l = l + 1
match = matcher.search(lin.encode('latin-1'))
if match:
printed = True
print("%s(%d): %s" % (node.abspath, l, lin))
count += 1
if not printed:
print("%s{%d}: match found" % (node.abspath, d[0:q.span()[0]].count("\n")+1));
print('found', count, 'matches')
@build.subcommand
def find(args):
[pattern] = args
matcher = re.compile(pattern, re.IGNORECASE)
for sourceListNode in _sourceListNodes:
for node in sourceListNode.value:
if node.data is None:
continue
q = matcher.search(node.abspath)
if q: print(node.abspath)