Improved pdf generation
This commit is contained in:
+39
-13
@@ -1,7 +1,9 @@
|
|||||||
"""
|
"""
|
||||||
Autodoc functions
|
Autodoc functions
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import common as doc
|
import common as doc
|
||||||
from doc_state import *
|
from doc_state import *
|
||||||
@@ -20,18 +22,26 @@ def __doc_app_state__(state, tab=" │ "):
|
|||||||
def __doc_application__(label, app):
|
def __doc_application__(label, app):
|
||||||
mdapp = f'\n## Real-time application "{label[1:]}"\n\n'
|
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 += 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 += "\n"
|
||||||
mdapp += f"│{label[1:]}│\n"
|
# mdapp += "```\n"
|
||||||
mdapp += f'╰┬{"─"*(len(label)-2)}╯\n'
|
# mdapp += f'╭{"─"*(len(label)-1)}╮\n'
|
||||||
|
# mdapp += f"│{label[1:]}│\n"
|
||||||
|
# mdapp += f'╰┬{"─"*(len(label)-2)}╯\n'
|
||||||
states = app["+States"]
|
states = app["+States"]
|
||||||
for i, (label, obj) in enumerate(states.items()):
|
|
||||||
ch = "├─▷" if i < len(states) - 1 else "╰─▷"
|
for i, (state, obj) in enumerate(states.items()):
|
||||||
tab = " │ " if i < len(states) - 1 else " "
|
if state[0] == "+":
|
||||||
if label[0] == "+":
|
mdapp += f" - {state[1:]}\n"
|
||||||
mdapp += f" {ch} {label[1:]}\n"
|
for thread in obj["+Threads"]:
|
||||||
mdapp += __doc_app_state__(obj, tab)
|
if thread[0] == "+":
|
||||||
mdapp += "```\n"
|
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():
|
for label, obj in states.items():
|
||||||
if label[0] == "+":
|
if label[0] == "+":
|
||||||
mdapp += f'\n### State "{label[1:]}"\n'
|
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))
|
doc.set_path(os.path.join(args.destination, fname))
|
||||||
if not os.path.isdir(doc.path()):
|
if not os.path.isdir(doc.path()):
|
||||||
os.mkdir(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():
|
for label, obj in config.items():
|
||||||
if "Class" in obj:
|
if "Class" in obj:
|
||||||
if obj["Class"] == "RealTimeApplication":
|
if obj["Class"] == "RealTimeApplication":
|
||||||
mddoc += __doc_application__(label, obj)
|
mddoc += __doc_application__(label, obj)
|
||||||
if obj["Class"] == "StateMachine":
|
if obj["Class"] == "StateMachine":
|
||||||
mddoc += f'\n## State-Machine "{label[1:]}"'
|
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)
|
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}"
|
||||||
|
)
|
||||||
|
|||||||
@@ -519,5 +519,5 @@ def doc_state(label, state, app):
|
|||||||
os.system(
|
os.system(
|
||||||
f"dot -Tsvg -o{os.path.join(doc.path(), fname)}.svg {os.path.join(doc.path(), fname)}.dot"
|
f"dot -Tsvg -o{os.path.join(doc.path(), fname)}.svg {os.path.join(doc.path(), fname)}.dot"
|
||||||
)
|
)
|
||||||
mdstate += f"\n"
|
mdstate += f"\n"
|
||||||
return mdstate
|
return mdstate
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
\usepackage{float}
|
||||||
|
\let\origfigure\figure
|
||||||
|
\let\endorigfigure\endfigure
|
||||||
|
\renewenvironment{figure}[1][2] {
|
||||||
|
\expandafter\origfigure\expandafter[H]
|
||||||
|
} {
|
||||||
|
\endorigfigure
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user