-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
todo-comment-lister.py
41 lines (33 loc) · 1.46 KB
/
todo-comment-lister.py
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
# coding: utf-8
import os, sys, io
additonalFilter = None
def listTodoComments():
for root, dirs, files in os.walk(top='./'):
for file in files:
filePath = os.path.join(root, file)
filePathToPrint = filePath.replace('\\', '/')
isPathPrinted = False
if filePath.endswith('.go'):
with open(filePath, mode='r', encoding='utf-8') as f:
lineNum = 1
for line in f:
try:
if line.find('TODO') > -1 and line.find('(SDB)') > -1:
if additonalFilter and line.find(additonalFilter) == -1:
continue
if not isPathPrinted:
print(filePathToPrint)
isPathPrinted = True
stripedLine = line.strip()
print(' ' + '{:<5}'.format(str(lineNum) + ':') + ' ' + stripedLine)
finally:
lineNum += 1
def main():
global additonalFilter
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
# additonal filtering option: -f "<filtering string>"
if len(sys.argv) == 3 and sys.argv[1] == '-f':
additonalFilter = sys.argv[2]
listTodoComments()
main()