Improved pdf generation
This commit is contained in:
+39
-13
@@ -1,7 +1,9 @@
|
||||
"""
|
||||
Autodoc functions
|
||||
"""
|
||||
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
import common as doc
|
||||
from doc_state import *
|
||||
@@ -20,18 +22,26 @@ def __doc_app_state__(state, tab=" │ "):
|
||||
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'
|
||||
|
||||
mdapp += "\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 i, (state, obj) in enumerate(states.items()):
|
||||
if state[0] == "+":
|
||||
mdapp += f" - {state[1:]}\n"
|
||||
for thread in obj["+Threads"]:
|
||||
if thread[0] == "+":
|
||||
mdapp += f" - {thread[1:]}\n"
|
||||
# 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'
|
||||
@@ -44,13 +54,29 @@ def document(fname, args, config):
|
||||
doc.set_path(os.path.join(args.destination, fname))
|
||||
if not os.path.isdir(doc.path()):
|
||||
os.mkdir(doc.path())
|
||||
now = datetime.now() # current date and time
|
||||
today = now.strftime("%d/%m/%Y")
|
||||
mddoc = "---\n"
|
||||
mddoc += "toc: true\n"
|
||||
mddoc += f"title: {fname} Documentation\n"
|
||||
mddoc += "author: MARTe AutoDOC\n"
|
||||
mddoc += "titlepage: true\n"
|
||||
mddoc += f"date: {today}\n"
|
||||
mddoc += "---\n\n"
|
||||
|
||||
mddoc = f"# {fname}\n"
|
||||
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:
|
||||
fpath = os.path.join(doc.path(), f"{fname}.md")
|
||||
pdfpath = os.path.join(doc.path(), f"{fname}.pdf")
|
||||
logging.info("Writing markdown...")
|
||||
with open(fpath, "w") as file:
|
||||
file.write(mddoc)
|
||||
logging.info("Generating pdf...")
|
||||
os.system(
|
||||
f"pandoc -H pandoc/disable_float.tex --template eisvogel --resource-path={doc.path()} -s {fpath} -o {pdfpath}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user