3
from pathlib import Path
11
class Tutorial(object):
12
def __init__(self, path):
18
with open(path, "rt") as f:
22
rx_title = re.compile(r"\{#(\w+)\}")
23
rx_subpage = re.compile(r"@subpage\s+(\w+)")
24
rx_prev = re.compile(r"@prev_tutorial\{(\w+)\}")
25
rx_next = re.compile(r"@next_tutorial\{(\w+)\}")
27
if self.title is None:
28
m = rx_title.search(line)
30
self.title = m.group(1)
33
m = rx_prev.search(line)
35
self.prev = m.group(1)
38
m = rx_next.search(line)
40
self.next = m.group(1)
42
m = rx_subpage.search(line)
44
self.children.append(m.group(1))
47
def verify_prev_next(self, storage):
50
if self.title is None:
55
for one in self.children:
57
if c.prev is not None and c.prev != prev:
58
print("[W] Wrong prev_tutorial: expected {} / actual {}".format(c.prev, prev))
63
for one in reversed(self.children):
65
if c.next is not None and c.next != next:
66
print("[W] Wrong next_tutorial: expected {} / actual {}".format(c.next, next))
70
if len(self.children) == 0 and self.prev is None and self.next is None:
71
print("[W] No prev and next tutorials")
76
if __name__ == "__main__":
79
print("Looking for tutorials in: '{}'".format(p))
81
all_tutorials = dict()
82
for f in p.glob('**/*'):
83
if f.suffix.lower() in ('.markdown', '.md'):
85
all_tutorials[t.title] = t
88
print("Found: {}".format(len(all_tutorials)))
90
for title, t in all_tutorials.items():
91
if not t.verify_prev_next(all_tutorials):
92
print("[E] Verification failed: {}".format(t.path))