-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextractTasks.py
61 lines (46 loc) · 1.71 KB
/
extractTasks.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#@todo pass filename from outside for piping
import glob
import re
import os
import argparse
parser = argparse.ArgumentParser("Extract tasks from files and creates a todo.txt")
parser.add_argument('basePath', help='absolute path to project. Use "." for current directory')
parser.add_argument('-o', action="store", dest="todoFile", help='absolute path for output file')
parser.add_argument('-e', action="append", default=[], dest="types", help='File extensions')
parser.add_argument('-f', action="store", dest="specificFile", help='Parson single file only')
args = parser.parse_args()
basePath = args.basePath
if args.todoFile:
output = args.todoFile
if not output.endswith(".txt"):
output += '.txt'
else:
output = os.getcwd() + "/todo.txt"
types = args.types
if len(types) == 0:
types = ['php', 'js', 'py']
if basePath == '.':
basePath = os.getcwd()
if not basePath.endswith('/'):
basePath += '/'
files_grabbed = []
if args.specificFile:
files_grabbed.append(args.specificFile)
else:
for types in types:
files_grabbed.extend(glob.glob(basePath + '**/*.' + types, recursive=True))
foundTasks = []
for path in files_grabbed:
with open(path) as currentFile:
for num, line in enumerate(currentFile, 1):
match = re.search("[/#] ?@?(todo|TODO):? (.*)", line)
if match:
text = match.group(2).strip()
shortPath = re.sub(basePath, '', path)
task = text + " @" + shortPath + ":" + str(num)
foundTasks.append(task)
text_file = open(output, "w+")
text_file.write("\n".join(foundTasks))
text_file.close()
print(str(len(files_grabbed)) + " files parsed")
print(str(len(foundTasks)) + " tasks added")