#!/usr/bin/env python3 import os as _os import sys as _sys import json as _json import argparse as _argparse from lib import * def hue_regular(): return 0.4 def hue_highlight(): return 0.0 def style(level, step): return ("invis" if (step < level) else "filled") def style_new(predicate): return ( "filled" if predicate() else "invis" ) def highlight(predicate): return ( { "fillcolor": ("%.4f+0.75+0.5" % (hue_highlight(), )), "color": ("%.4f+0.75+0.5" % (hue_highlight(), )), } if predicate() else { } ) def render(input_, data, format_, path_output): path_temp = "/tmp/graph.gv" _os.makedirs(_os.path.dirname(path_temp), exist_ok = True) file_write( path_temp, string_coin( input_, data ) ) _os.makedirs(_os.path.dirname(path_output), exist_ok = True) _os.system( string_coin( "cat {{path_source}} | dot -T {{format}} > {{path_output}}", { "path_source": path_temp, "path_output": path_output, "format": format_, } ) ) def attributes_subgraph(): return { "fontname": "monospace", "fontcolor": ("%.4f+0+1" % (hue_regular(), )), "color": ("%.4f+0.25+0.25" % (hue_regular(), )), "fillcolor": ("%.4f+0.25+0.25" % (hue_regular(), )), } def dot_macro_services(conf): return dot_graph( { "name": "services", "settings": { "graph": { "layout": "dot", "rankdir": "BT", "bgcolor": "0.4+0+0.125", }, "node": { "fontname": "monospace", "shape": "hexagon", "style": "filled", "fillcolor": "0.4+0.75+0.5", "color": "0.4+0.75+0.5", "fontcolor": "0.4+0+1", }, "edge": { "fontname": "monospace", "color": "0.4+0+0.75", } }, "nodes": [ { "name": "node_db", "attributes": { "label": "DB-Server", "style": style_new(lambda: (conf["step"] >= 1)), }, }, { "name": "node_web", "attributes": { "label": "Web-Server", "style": style_new(lambda: (conf["step"] >= 2)), }, }, { "name": "node_auth", "attributes": { "label": "Auth-Server", "style": style_new(lambda: (conf["step"] >= 3)), }, }, { "name": "node_db_for_auth", "attributes": { "label": "DB-Modul\nfür\nAuth-Server", "style": style_new(lambda: (conf["step"] >= 4)), }, }, { "name": "node_auth_and_web", "attributes": { "label": "Web-Modul\nfür\nAuth-Server", "style": style_new(lambda: (conf["step"] >= 5)), }, }, { "name": "node_service", "attributes": { "label": "Dienst", "style": style_new(lambda: (conf["step"] >= 6)), }, }, { "name": "node_db_for_service", "attributes": { "label": "DB-Modul\nfür\nDienst", "style": style_new(lambda: (conf["step"] >= 7)), }, }, { "name": "node_auth_for_service", "attributes": { "label": "Auth-Modul\nfür\nDienst", "style": style_new(lambda: (conf["step"] >= 8)), }, }, { "name": "node_service_and_web", "attributes": { "label": "Web-Modul\nfür\nDienst", "style": style_new(lambda: (conf["step"] >= 9)), }, }, ], "edges": [ { "name_from": "node_db", "name_to": "node_db_for_auth", "attributes": { "style": style_new(lambda: (conf["step"] >= 4)), }, }, { "name_from": "node_db_for_auth", "name_to": "node_auth", "attributes": { "style": style_new(lambda: (conf["step"] >= 4)), }, }, { "name_from": "node_auth", "name_to": "node_auth_and_web", "attributes": { "style": style_new(lambda: (conf["step"] >= 5)), }, }, { "name_from": "node_web", "name_to": "node_auth_and_web", "attributes": { "style": style_new(lambda: (conf["step"] >= 5)), }, }, { "name_from": "node_db", "name_to": "node_db_for_service", "attributes": { "style": style_new(lambda: (conf["step"] >= 7)), }, }, { "name_from": "node_db_for_service", "name_to": "node_service", "attributes": { "style": style_new(lambda: (conf["step"] >= 7)), }, }, { "name_from": "node_auth", "name_to": "node_auth_for_service", "attributes": { "style": style_new(lambda: (conf["step"] >= 8)), }, }, { "name_from": "node_auth_for_service", "name_to": "node_service", "attributes": { "style": style_new(lambda: (conf["step"] >= 8)), }, }, { "name_from": "node_service", "name_to": "node_service_and_web", "attributes": { "style": style_new(lambda: (conf["step"] >= 9)), }, }, { "name_from": "node_web", "name_to": "node_service_and_web", "attributes": { "style": style_new(lambda: (conf["step"] >= 9)), }, }, ], "subgraphs": [ ], } ) def dot_macro_user_management(conf): return dot_graph( { "name": "user_management", "settings": { "graph": { "layout": "dot", "rankdir": "BT", "bgcolor": "0.4+0+0.125", }, "node": { "fontname": "monospace", "shape": "hexagon", "style": "filled", "fillcolor": "0.4+0.75+0.5", "color": "0.4+0.75+0.5", "fontcolor": "0.4+0+1", }, "edge": { "fontname": "monospace", "color": "0.4+0+0.75", } }, "nodes": [ { "name": "node_9", "attributes": ( { "label": "Syncer", "style": style_new(lambda: (conf["step"] >= 8)), } | highlight(lambda: (conf["step"] == 11)) ) }, ], "edges": [ { "name_from": "node_6", "name_to": "node_11", "attributes": { "style": style_new(lambda: (conf["step"] >= 3)), } }, { "name_from": "node_4", "name_to": "node_9", "attributes": { "dir": "forward", "style": style_new(lambda: (conf["step"] >= 8)), } }, { "name_from": "node_8", "name_to": "node_9", "attributes": { "dir": "both", "style": style_new(lambda: (conf["step"] >= 8)), } }, ], "subgraphs": [ { "name": "3", "attributes": ( attributes_subgraph() | { "label": "MGL", "style": style_new(lambda: (conf["step"] >= 4)), } ), "nodes": [ { "name": "node_1", "attributes": ( { "label": "MGL-DB", "style": style_new(lambda: (conf["step"] >= 6)), } | highlight(lambda: (conf["step"] == 10)) ) }, { "name": "node_2", "attributes": ( { "label": "MGL-BE", "style": style_new(lambda: (conf["step"] >= 6)), } | highlight(lambda: (conf["step"] == 10)) ) }, { "name": "node_3", "attributes": ( { "label": "MGL-FE-Web", "style": style_new(lambda: (conf["step"] >= 5)), } | highlight(lambda: (conf["step"] == 9)) ) }, { "name": "node_4", "attributes": ( { "label": "MGL-FE-CLI", "style": style_new(lambda: (conf["step"] >= 7)), } | highlight(lambda: (conf["step"] == 11)) ) }, ], "edges": [ { "name_from": "node_1", "name_to": "node_2", "attributes": { "dir": "both", "style": style_new(lambda: (conf["step"] >= 6)), } }, { "name_from": "node_2", "name_to": "node_3", "attributes": { "dir": "both", "style": style_new(lambda: (conf["step"] >= 6)), } }, { "name_from": "node_2", "name_to": "node_4", "attributes": { "dir": "forward", "style": style_new(lambda: (conf["step"] >= 7)), } }, ], }, { "name": "2", "attributes": ( attributes_subgraph() | { "label": "Espe", "style": style_new(lambda: (conf["step"] >= 1)), } ), "nodes": [ { "name": "node_5", "attributes": ( { "label": "Espe-DB", "style": style_new(lambda: (conf["step"] >= 2)), } | highlight(lambda: (conf["step"] == 12)) ) }, { "name": "node_6", "attributes": ( { "label": "Espe-BE", "style": style_new(lambda: (conf["step"] >= 2)), } | highlight(lambda: (conf["step"] == 12)) ) }, { "name": "node_8", "attributes": ( { "label": "Espe-FE-CLI", "style": style_new(lambda: (conf["step"] >= 2)), } | highlight(lambda: (conf["step"] == 11)) ) }, { "name": "node_7", "attributes": ( { "label": "Espe-FE-Web", "style": style_new(lambda: (conf["step"] >= 2)), } ) }, ], "edges": [ { "name_from": "node_5", "name_to": "node_6", "attributes": { "dir": "both", "style": style_new(lambda: (conf["step"] >= 2)), } }, { "name_from": "node_6", "name_to": "node_7", "attributes": { "dir": "both", "style": style_new(lambda: (conf["step"] >= 2)), } }, { "name_from": "node_6", "name_to": "node_8", "attributes": { "dir": "both", "style": style_new(lambda: (conf["step"] >= 2)), } }, ], }, { "name": "1", "attributes": ( attributes_subgraph() | { "label": "Dienste", "style": style_new(lambda: (conf["step"] >= 0)), } ), "nodes": [ { "name": "node_10", "attributes": { "label": "…", "style": style_new(lambda: (conf["step"] >= 0)), } }, { "name": "node_11", "attributes": ( { "label": "Auth-Server", "style": style_new(lambda: (conf["step"] >= 0)), } | highlight(lambda: (conf["step"] == 13)) ) }, { "name": "node_12", "attributes": { "label": "…", "style": style_new(lambda: (conf["step"] >= 0)), } }, ], "edges": [ { "name_from": "node_10", "name_to": "node_11", "attributes": { "dir": "both", "style": style_new(lambda: (conf["step"] >= 0)), } }, { "name_from": "node_11", "name_to": "node_12", "attributes": { "dir": "both", "style": style_new(lambda: (conf["step"] >= 0)), } }, ], }, ] } ) def main(): ## consts dir_source = "source" ## args argument_parser = _argparse.ArgumentParser( ) argument_parser.add_argument( "-f", "--format", type = str, choices = ["svg","png"], dest = "format", metavar = "", default = "svg" ) argument_parser.add_argument( "-n", "--no-extension", action = "store_true", dest = "no_extension", default = False, ) argument_parser.add_argument( "-o", "--output-directory", type = str, dest = "output_directory", metavar = "", default = "temp" ) args = argument_parser.parse_args() ## exec ### excc:services if True: size = 10 for step in range(size): render( dot_macro_services( { "step": step, } ), {}, args.format, string_coin( "{{directory}}/{{name}}-{{step}}{{extension}}", { "name": "services", "directory": args.output_directory, "step": ("%u" % step), "extension": ( "" if args.no_extension else ("." + args.format) ), } ) ) ### exec:syncing if True: size = 14 for step in range(size): render( dot_macro_user_management( { "step": step, } ), {}, args.format, string_coin( "{{directory}}/{{name}}-{{step}}{{extension}}", { "name": "user_management", "directory": args.output_directory, "step": ("%u" % step), "extension": ( "" if args.no_extension else ("." + args.format) ), } ) ) main()