opencv

Форк
0
/
scan_tutorials.py 
96 строк · 2.8 Кб
1
#!/usr/bin/env python
2

3
from pathlib import Path
4
import re
5

6
# Tasks
7
# 1. Find all tutorials
8
# 2. Generate tree (@subpage)
9
# 3. Check prev/next nodes
10

11
class Tutorial(object):
12
    def __init__(self, path):
13
        self.path = path
14
        self.title = None # doxygen title
15
        self.children = [] # ordered titles
16
        self.prev = None
17
        self.next = None
18
        with open(path, "rt") as f:
19
            self.parse(f)
20

21
    def parse(self, 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+)\}")
26
        for line in f:
27
            if self.title is None:
28
                m = rx_title.search(line)
29
                if m:
30
                    self.title = m.group(1)
31
                    continue
32
            if self.prev is None:
33
                m = rx_prev.search(line)
34
                if m:
35
                    self.prev = m.group(1)
36
                    continue
37
            if self.next is None:
38
                m = rx_next.search(line)
39
                if m:
40
                    self.next = m.group(1)
41
                    continue
42
            m = rx_subpage.search(line)
43
            if m:
44
                self.children.append(m.group(1))
45
                continue
46

47
    def verify_prev_next(self, storage):
48
        res = True
49

50
        if self.title is None:
51
            print("[W] No title")
52
            res = False
53

54
        prev = None
55
        for one in self.children:
56
            c = storage[one]
57
            if c.prev is not None and c.prev != prev:
58
                print("[W] Wrong prev_tutorial: expected {} / actual {}".format(c.prev, prev))
59
                res = False
60
            prev = c.title
61

62
        next = None
63
        for one in reversed(self.children):
64
            c = storage[one]
65
            if c.next is not None and c.next != next:
66
                print("[W] Wrong next_tutorial: expected {} / actual {}".format(c.next, next))
67
                res = False
68
            next = c.title
69

70
        if len(self.children) == 0 and self.prev is None and self.next is None:
71
            print("[W] No prev and next tutorials")
72
            res = False
73

74
        return res
75

76
if __name__ == "__main__":
77

78
    p = Path('tutorials')
79
    print("Looking for tutorials in: '{}'".format(p))
80

81
    all_tutorials = dict()
82
    for f in p.glob('**/*'):
83
        if f.suffix.lower() in ('.markdown', '.md'):
84
            t = Tutorial(f)
85
            all_tutorials[t.title] = t
86

87
    res = 0
88
    print("Found: {}".format(len(all_tutorials)))
89
    print("------")
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))
93
            print("------")
94
            res = 1
95

96
    exit(res)
97

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.