diff options
Diffstat (limited to 'secateurs.py')
-rw-r--r-- | secateurs.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/secateurs.py b/secateurs.py new file mode 100644 index 0000000..7111c04 --- /dev/null +++ b/secateurs.py @@ -0,0 +1,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) |