Skip to content

Commit

Permalink
Merge pull request #18 from hyakuhei/Package
Browse files Browse the repository at this point in the history
Plugin modifications
  • Loading branch information
hyakuhei authored May 23, 2023
2 parents 6e5db6b + d9ee669 commit a77e481
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/ltm/ltm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
37 changes: 32 additions & 5 deletions src/ltm/ltmRenderer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import io
import io, sys, os

from util import search, Dot

Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -176,5 +193,15 @@ def render(
ctr += 1
report_fd.write("\n")

if printSingleModeHtml == True:
print("<table>")
print("<tr><td>Id</td><td>From</td><td>To</td><td>Data</td></tr>")

ctr = 1
for flow in scene[sceneName]:
print(f"<tr><td>{ctr}</td><td>{flow['from']}</td><td>{flow['to']}</td><td>{flow['data']}</td></tr>")
ctr += 1
print("</table>")

if report_fd is not None:
report_fd.close()

0 comments on commit a77e481

Please sign in to comment.