summaryrefslogtreecommitdiff
path: root/secateurs.py
blob: 7111c04849b35bb02ef13cc118a4857a7fe8d3c0 (plain)
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
import plantuml
import sys

f = open(sys.argv[1], 'r').readlines()
p = plantuml.PlantUML(url="http://www.plantuml.com/plantuml/img/")

preamble = []


def add_preamble(offset):
    for line in range(offset, len(f)):
        if "namespace" in f[line]:
            return line - 1
        else:
            preamble.append(f[line])


def generate_svg(text):
    print(f"generating: {text}")
    res = p.get_url(plantuml_text=('\n'.join(preamble) + text))
    print(res)


def parse_namespace(offset):
    print(f"offset: {offset}")
    depth = 1
    contains_subspaces = False
    for i in range(offset + 2, len(f)):
        #print(f[i])
        depth += f[i].count("{") - f[i].count("}")
        if "namespace" in f[i]:
            print("parsing subnamespace")
            contains_subspaces = True
            parse_namespace(i)
        if depth == 0:
            if not contains_subspaces:
                generate_svg('\n'.join(f[offset:i + 1]))
            return i


offset = 0
while offset < len(f):
    offset = add_preamble(offset)
    offset = parse_namespace(offset)