58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
"""
|
|
Autodoc functions
|
|
"""
|
|
import logging
|
|
import os
|
|
|
|
import common as doc
|
|
from doc_state import *
|
|
|
|
|
|
def __doc_app_state__(state, tab=" │ "):
|
|
res = ""
|
|
if "+Threads" in state:
|
|
for i, tname in enumerate(state["+Threads"]):
|
|
if tname[0] == "+":
|
|
ch = "├─●" if i < len(state["+Threads"]) - 1 else "╰─●"
|
|
res += f"{tab} {ch} {tname[1:]}\n"
|
|
return res
|
|
|
|
|
|
def __doc_application__(label, app):
|
|
mdapp = f'\n## Real-time application "{label[1:]}"\n\n'
|
|
mdapp += f"Below are descrbed the states and threads of the real-time application {label[1:]}.\n"
|
|
mdapp += "```\n"
|
|
mdapp += f'╭{"─"*(len(label)-1)}╮\n'
|
|
mdapp += f"│{label[1:]}│\n"
|
|
mdapp += f'╰┬{"─"*(len(label)-2)}╯\n'
|
|
states = app["+States"]
|
|
for i, (label, obj) in enumerate(states.items()):
|
|
ch = "├─▷" if i < len(states) - 1 else "╰─▷"
|
|
tab = " │ " if i < len(states) - 1 else " "
|
|
if label[0] == "+":
|
|
mdapp += f" {ch} {label[1:]}\n"
|
|
mdapp += __doc_app_state__(obj, tab)
|
|
mdapp += "```\n"
|
|
for label, obj in states.items():
|
|
if label[0] == "+":
|
|
mdapp += f'\n### State "{label[1:]}"\n'
|
|
mdapp += doc_state(label, obj, app)
|
|
return mdapp
|
|
|
|
|
|
def document(fname, args, config):
|
|
"""Document MARTe object."""
|
|
doc.set_path(os.path.join(args.destination, fname))
|
|
if not os.path.isdir(doc.path()):
|
|
os.mkdir(doc.path())
|
|
|
|
mddoc = f"# {fname}\n"
|
|
for label, obj in config.items():
|
|
if "Class" in obj:
|
|
if obj["Class"] == "RealTimeApplication":
|
|
mddoc += __doc_application__(label, obj)
|
|
if obj["Class"] == "StateMachine":
|
|
mddoc += f'\n## State-Machine "{label[1:]}"'
|
|
with open(os.path.join(doc.path(), f"{fname}.md"), "w") as file:
|
|
file.write(mddoc)
|