-
Notifications
You must be signed in to change notification settings - Fork 16
/
generate_todo.py
65 lines (57 loc) · 2.53 KB
/
generate_todo.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
62
63
64
65
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Use in terminal: ./generate_todo.py
Created on Thu Jul 11 14:27:20 2013
Copyright (c) 2013-2017, CEA/DSV/I2BM/Neurospin. All rights reserved.
@author: Tommy Löfstedt
@email: [email protected]
@license: BSD 3-clause.
"""
import os
import re
PATH = "./parsimony/"
OUTPUT = "./TODO"
RE_PY_FILE = re.compile("[^_].*\.py$")
RE_TODO = re.compile("^[^#]*#[ \t]*TODO:.*$") # TODO: Allow code before TODO
RE_FIXME = re.compile("^[^#]*#[ \t]*FIXME:.*$") # TODO: Allow code before FIXME
RE_WARNING = re.compile("^[^#]*#[ \t]*WARNING:.*$") # TODO: Allow code before WARNING
RE_ERROR = re.compile("^[^#]*#[ \t]*ERROR:.*$") # TODO: Allow code before ERROR
RE_BUG = re.compile("^[^#]*#[ \t]*BUG:.*$") # TODO: Allow code before BUG
RE_XXX = re.compile("^[^#]*#[ \t]*XXX:.*$") # TODO: Allow code before XXX
RE_COMMENT = re.compile("^[ \t]*#.*$")
def write(f, string):
f.write(string + os.linesep)
# print string
with open(OUTPUT, "w+") as out:
write(out, "# This file is automatically generated by generate_todo.py.")
write(out, "# Files that start with an underscore (\"_\") have been excluded.")
write(out, "")
for path, dirs, files in os.walk(PATH):
for filename in files:
first_in_file = True
fullpath = os.path.join(path, filename)
if RE_PY_FILE.match(filename):
with open(fullpath, "r") as f:
match_next_comment = False
for i, line in enumerate(f):
if RE_TODO.match(line) or \
RE_FIXME.match(line) or \
RE_WARNING.match(line) or \
RE_ERROR.match(line) or \
RE_BUG.match(line) or \
RE_XXX.match(line):
if first_in_file:
write(out, "%s:" % fullpath)
write(out, "-" * len(fullpath))
first_in_file = False
write(out, "%d: %s" % (i + 1, line.strip()))
match_next_comment = True
elif match_next_comment and RE_COMMENT.match(line):
write(out, "%d: %s" % (i + 1, line.strip()))
else:
if match_next_comment:
write(out, "")
match_next_comment = False
# if not first_in_file:
# write(out, "")