forked from nocproject/noc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtodos.py
58 lines (50 loc) · 1.68 KB
/
todos.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
# ---------------------------------------------------------------------
# manage.py todos
# ---------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
import os
# NOC modules
from noc.core.management.base import BaseCommand
from noc.settings import INSTALLED_APPS
from noc.core.fileutils import read_file
class Command(BaseCommand):
help = "Display todo's left in code"
exclude = {"commands/todos.py"}
def handle(self, *args, **options):
dirs = ["lib"] + [a[4:] for a in INSTALLED_APPS if a.startswith("noc.")]
n = 0
for d in dirs:
for dirpath, dirs, files in os.walk(d):
for f in files:
if f.startswith(".") or not f.endswith(".py"):
continue
path = os.path.join(dirpath, f)
if path not in self.exclude:
n += self.show_todos(path)
if n:
print("-" * 72)
print("%d todos found" % n)
else:
print("No todos found")
def show_todos(self, path):
"""
Display todos
:param path:
:return:
"""
data = read_file(path)
if not data:
return 0
n = 0
for nl, l in enumerate(data.splitlines()):
if "@todo:" in l:
idx = l.index("@todo:")
todo = l[idx + 6 :].strip()
print("%50s:%5d: %s" % (path, nl, todo))
n += 1
return n
if __name__ == "__main__":
Command().run()