summaryrefslogtreecommitdiff
path: root/secateurs.py
blob: c6a4f0412514f011abb304586877689d9f6266ac (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
45
46
47
48
49
50
51
52
53
54
import plantuml
import sys
import time

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}")
    try:
        res = p.processes(plantuml_text=('\n'.join(preamble) + text))
    except Exception as e:
        print(e)
        print(p.get_url(plantuml_text=('\n'.join(preamble) + text)))
        return

    name = text.split(' ')
    open('out/' + name[name.index('namespace') + 1] + '.png', 'wb').write(res)
    time.sleep(1)


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
offset = add_preamble(offset)
while offset < len(f):
    #offset = add_preamble(offset)
    offset = parse_namespace(offset)