diff --git a/src/ltm/ltm.py b/src/ltm/ltm.py index 45cf28e..61b8c12 100755 --- a/src/ltm/ltm.py +++ b/src/ltm/ltm.py @@ -54,6 +54,15 @@ def main(): action="store_true", help="Write the JSON model to the output dir (OUTDIR/model.json)", ) + argparser.add_argument( + "--single", + help="Single Diagram Mode - provide a single filename to write a diagram to - only prints the first scene (really only used for Obsidian)", + ) + argparser.add_argument( + "--html", + action="store_true", + help="Print an HTML table for a single scene", + ) args = argparser.parse_args() @@ -83,6 +92,9 @@ def main(): "report": args.report, "label": args.label, "number": args.number, + "fileNameOverride": args.single, + "singleMode":True if args.single else False, + "printSingleModeHtml": args.html } render(doc, args.outdir, **parms) diff --git a/src/ltm/ltmRenderer.py b/src/ltm/ltmRenderer.py index 64a984a..345360b 100644 --- a/src/ltm/ltmRenderer.py +++ b/src/ltm/ltmRenderer.py @@ -1,4 +1,4 @@ -import io +import io, sys, os from util import search, Dot @@ -127,6 +127,9 @@ def render( label=False, number=True, title="High Level Architecture", + singleMode=False, + fileNameOverride=None, + printSingleModeHtml=False ): doc = prepDoc(doc) graph = None @@ -139,23 +142,37 @@ def render( if generateArchDiagram == True: # TODO: Make this a command line argument doc = addArchScene(doc) # adds an ARCH scene to the doc + ctr = 0 for scene in doc["scenes"]: + ctr += 1 + if singleMode is True and ctr > 1: + break for sceneName in scene.keys(): graph = genGraph(doc, sceneName, number=number, label=label) fileName = f"{outputDir}/{sceneName}" + if fileNameOverride is not None: + fileName = f"{outputDir}/{fileNameOverride}" + if sceneName == title: graph.write(f"{fileName}.dot", compoundLinks=True) else: graph.write(f"{fileName}.dot") + + ##XXX Temporary path bypass + os.environ["PATH"] = os.environ["PATH"] + ":/opt/homebrew/bin/" + graphviz.render("dot", "png", f"{fileName}.dot").replace("\\", "/") if report: - report_fd.write(f"## {sceneName}\n") - report_fd.write( - f"![{sceneName}]({sceneName.replace(' ', '%20')}.png)\n" - ) + if singleMode == True: + pass + else: + report_fd.write(f"## {sceneName}\n") + report_fd.write( + f"![{sceneName}]({sceneName.replace(' ', '%20')}.dot.png)\n" + ) if sceneName == title and generateArchDiagram == True: report_fd.write("\n| Actor | Description |\n") report_fd.write("| --- | ---- |\n") @@ -176,5 +193,15 @@ def render( ctr += 1 report_fd.write("\n") + if printSingleModeHtml == True: + print("
Id | From | To | Data |
{ctr} | {flow['from']} | {flow['to']} | {flow['data']} |