Skip to content

Commit

Permalink
Updated black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hyakuhei committed Dec 29, 2021
1 parent 6c1ea54 commit 1a60d40
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 27 deletions.
55 changes: 34 additions & 21 deletions src/jtg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from util import search, Dot

#XXX: This is ugly
# XXX: This is ugly
ARCH = "High Level Architecture"


def drawRecursiveBoundaries(doc, boundaryKey, graph, drawnBoundaries=None):
if drawnBoundaries is None:
drawnBoundaries = {}
Expand All @@ -29,9 +30,9 @@ def genGraph(doc, sceneName, compoundLinks=False, linkCounters=True, printLabels
linkCounter = 0

_STYLES = {
'boundary':'color="Red"',
'node':'shape="box", margin="0.1", color="Grey", fontsize="13", fontname="Helvetica"',
'link':'fontsize="13", penwidth="1.2", arrowsize="0.8", fontname="Helvetica"'
"boundary": 'color="Red"',
"node": 'shape="box", margin="0.1", color="Grey", fontsize="13", fontname="Helvetica"',
"link": 'fontsize="13", penwidth="1.2", arrowsize="0.8", fontname="Helvetica"',
}

graphContainer = graph.newSubgraph(sceneName, style='color="Black"')
Expand Down Expand Up @@ -59,19 +60,24 @@ def genGraph(doc, sceneName, compoundLinks=False, linkCounters=True, printLabels

parentBoundary = drawnBoundaries[key]

drawnActors[actor] = graph.newNode(actor, parent=parentBoundary, style=_STYLES['node'])
drawnActors[actor] = graph.newNode(
actor, parent=parentBoundary, style=_STYLES["node"]
)

linkCounter += 1

flowLabel = ""
if linkCounters == True:
flowLabel = f"{linkCounter}."

if printLabels == True:
flowLabel = flowLabel + flow["data"]

link = graph.newLink(
drawnActors[flow["from"]], drawnActors[flow["to"]], label=flowLabel, style=_STYLES['link']
drawnActors[flow["from"]],
drawnActors[flow["to"]],
label=flowLabel,
style=_STYLES["link"],
)

return graph
Expand Down Expand Up @@ -109,18 +115,23 @@ def prepDoc(doc):
path = search(doc["boundaries"], actor)
return doc

def main(generateArchDiagram=True, markdown=False, printLabels=False, linkCounters=True):

def main(
generateArchDiagram=True, markdown=False, printLabels=False, linkCounters=True
):
doc = json.loads(sys.stdin.read())
doc = prepDoc(doc)
graph = None

scenes = doc['scenes']
scenes = doc["scenes"]
if generateArchDiagram == True: # TODO: Make this a command line argument
doc = addArchScene(doc) # adds an ARCH scene to the doc

for scene in doc["scenes"]:
for sceneName in scene.keys():
graph = genGraph(doc, sceneName, linkCounters=linkCounters, printLabels=printLabels)
graph = genGraph(
doc, sceneName, linkCounters=linkCounters, printLabels=printLabels
)

fileName = f"output/{sceneName}"
with open(f"{fileName}.dot", "w") as f:
Expand All @@ -130,7 +141,8 @@ def main(generateArchDiagram=True, markdown=False, printLabels=False, linkCounte
f.write(graph.dot())

_ = subprocess.run(
["dot", "-s100", "-Tpng", f"{fileName}.dot", f"-o{fileName}.png"], shell=False
["dot", "-s100", "-Tpng", f"{fileName}.dot", f"-o{fileName}.png"],
shell=False,
)

if markdown:
Expand All @@ -141,25 +153,26 @@ def main(generateArchDiagram=True, markdown=False, printLabels=False, linkCounte
print("| -- | ---- | -- | ---- |")
ctr = 1
for flow in scene[sceneName]:
print(f"| {ctr} | {flow['from']} | {flow['to']} | {flow['data']} |")
ctr+=1
print(
f"| {ctr} | {flow['from']} | {flow['to']} | {flow['data']} |"
)
ctr += 1


if __name__ == "__main__":
#TODO argument handling
# TODO argument handling

parms = {
'generateArchDiagram':False,
'markdown':False,
'printLabels':False,
'linkCounters':False

"generateArchDiagram": False,
"markdown": False,
"printLabels": False,
"linkCounters": False,
}

if "-arch" in sys.argv:
parms['generateArchDiagram'] = True
parms["generateArchDiagram"] = True
if "-markdown" in sys.argv:
parms['markdown'] = True
parms["markdown"] = True
if "-label" in sys.argv:
parms["printLabels"] = True
if "-number" in sys.argv:
Expand Down
27 changes: 21 additions & 6 deletions src/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def __init__(self):
2. A subgraph can only belong to 0..1 subgraphs
"""

def newSubgraph(self, label: str = "", parent: dict = None, style: str = 'color="Coral1"') -> dict:
def newSubgraph(
self, label: str = "", parent: dict = None, style: str = 'color="Coral1"'
) -> dict:
"""Create a new subgraph
Args:
Expand All @@ -78,12 +80,17 @@ def newSubgraph(self, label: str = "", parent: dict = None, style: str = 'color=
"label": label,
"parent": parent,
"nodetype": "subgraph",
"style":style
"style": style,
}
self._subgraphs.append(newSub)
return newSub

def newNode(self, label: str = "", parent: dict = None, style: str = 'shape="box", margin="0.1", color="Grey"') -> dict:
def newNode(
self,
label: str = "",
parent: dict = None,
style: str = 'shape="box", margin="0.1", color="Grey"',
) -> dict:
"""Create a new node
Args:
Expand All @@ -103,12 +110,18 @@ def newNode(self, label: str = "", parent: dict = None, style: str = 'shape="box
"label": label,
"parent": parent,
"nodetype": "node",
"style":style
"style": style,
}
self._nodes.append(node)
return node

def newLink(self, nodeA: dict, nodeB: dict, label: str = "", style: str = 'fontsize="10",penwidth="1.2",arrowsize="0.8"') -> dict:
def newLink(
self,
nodeA: dict,
nodeB: dict,
label: str = "",
style: str = 'fontsize="10",penwidth="1.2",arrowsize="0.8"',
) -> dict:
"""Create a new link between nodes or subgraphs
Creates a directional link from nodeA to nodeB
Expand Down Expand Up @@ -161,7 +174,9 @@ def recurse(self, item: dict, s: list, depth: int = 1, parent: dict = None):
s.append(f"{tab*depth}{closeBrace}")

if item["nodetype"] == "node":
s.append(f'{tab*depth}node{item["id"]} [label="{item["label"]}" {item["style"]}];')
s.append(
f'{tab*depth}node{item["id"]} [label="{item["label"]}" {item["style"]}];'
)

def dot(self, compoundLinks=False) -> str:
"""Generate a string of the dot graph
Expand Down

0 comments on commit 1a60d40

Please sign in to comment.