Implementing new features
This commit is contained in:
@@ -1 +1,2 @@
|
||||
from autodoc.autodoc import *
|
||||
from autodoc.configdb import *
|
||||
|
||||
+4
-1
@@ -11,6 +11,7 @@ import sys
|
||||
from argparse import ArgumentParser
|
||||
|
||||
import autodoc
|
||||
from configdb import ConfigDB
|
||||
|
||||
__version__ = "0.0.0"
|
||||
|
||||
@@ -78,7 +79,9 @@ def main():
|
||||
filename = args.output
|
||||
else:
|
||||
filename = os.path.splitext(os.path.basename(args.filename))[0]
|
||||
autodoc.document(filename, args, config)
|
||||
# autodoc.document(filename, args, config)
|
||||
|
||||
cfgdb = ConfigDB()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
"""
|
||||
Autodoc functions
|
||||
"""
|
||||
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
import common as doc
|
||||
from doc_state import *
|
||||
from doc_state_machine import doc_state_machine
|
||||
|
||||
|
||||
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):
|
||||
logging.info(f"Documenting real time application {label}")
|
||||
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 += "```\n"
|
||||
# mdapp += f'╭{"─"*(len(label)-1)}╮\n'
|
||||
# mdapp += f"│{label[1:]}│\n"
|
||||
# mdapp += f'╰┬{"─"*(len(label)-2)}╯\n'
|
||||
states = app["+States"]
|
||||
|
||||
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'
|
||||
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))
|
||||
doc.set_config(args)
|
||||
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 += "geometry: margin=2cm\n"
|
||||
mddoc += "---\n\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:]}"\n'
|
||||
mddoc += doc_state_machine(label[1:], obj)
|
||||
fpath = os.path.join(doc.path(), f"{fname}.md")
|
||||
outpath = os.path.join(doc.path(), fname)
|
||||
logging.info(f"Saving markdown: {fpath}")
|
||||
with open(fpath, "w") as file:
|
||||
file.write(mddoc)
|
||||
if doc.build():
|
||||
logging.info(f"Generating html: {outpath}.html")
|
||||
os.system(
|
||||
f"pandoc --css pandoc/styling.css --resource-path={doc.path()} --embed-resource --to html5 -s {fpath} -o {outpath}.html"
|
||||
)
|
||||
logging.info(f"Generating pdf: {outpath}.pdf")
|
||||
os.system(
|
||||
f"pandoc -H pandoc/disable_float.tex --resource-path={doc.path()} -s {fpath} -o {outpath}.pdf"
|
||||
)
|
||||
+5
-1
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
import sys
|
||||
|
||||
__PATH__ = "."
|
||||
__CONFIG__ = None
|
||||
@@ -29,12 +30,15 @@ def type_bytes_count(mtype):
|
||||
return 1
|
||||
|
||||
|
||||
def signal_byte_size(sig):
|
||||
def signal_byte_size(parent_id, sig_id, sig):
|
||||
noe = 1 if "NumberOfElements" not in sig else int(sig["NumberOfElements"])
|
||||
nod = 1 if "NumberOfDimensions" not in sig else int(sig["NumberOfDimensions"])
|
||||
nod = nod if nod > 0 else 1
|
||||
noe = noe if noe > 0 else 1
|
||||
nos = 1 if "Samples" not in sig else int(sig["Samples"])
|
||||
if "Type" not in sig:
|
||||
logging.fatal(f"no type defined for signal {parent_id}.{sig_id}")
|
||||
sys.exit(1)
|
||||
bytes = type_bytes_count(sig["Type"])
|
||||
tot = noe * nod * nos
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
from re import search
|
||||
|
||||
from MARTe.StandardParser import logging
|
||||
|
||||
|
||||
class ConfigDB:
|
||||
def __new__(cls):
|
||||
if not hasattr(cls, "instance"):
|
||||
cls.instance = super(ConfigDB, cls).__new__(cls)
|
||||
return cls.instance
|
||||
|
||||
def __init__(self):
|
||||
ConfigDB.__INST__ = self
|
||||
self.__db__ = {}
|
||||
|
||||
def get(self, path: str):
|
||||
ipath = path.split(".")
|
||||
obj = self.__db__
|
||||
for p in ipath:
|
||||
if p in obj:
|
||||
obj = obj[p]
|
||||
else:
|
||||
logging.error(f"no key {p} found for {path}")
|
||||
return None
|
||||
return obj
|
||||
|
||||
def insert(self, key: dict, obj):
|
||||
pass
|
||||
|
||||
|
||||
class MARTeOBJ:
|
||||
def __init__(self, fname, id, cfg):
|
||||
self.__name__ = id
|
||||
self.__mcls__ = cfg["Class"]
|
||||
self.__struct__ = {}
|
||||
for key, itm in cfg.items():
|
||||
if key != "Class":
|
||||
if isinstance(itm, dict) and "Class" in itm:
|
||||
self.__struct__[key] = MARTeOBJ(fname, key, itm)
|
||||
else:
|
||||
self.__struct__[key] = itm
|
||||
|
||||
def pretty_print(self, spacing=""):
|
||||
str = f"{spacing}{self.__name__}[{self.__mcls__}]:\n"
|
||||
for key, itm in self.__struct__.items():
|
||||
if isinstance(itm, MARTeOBJ):
|
||||
str += itm.pretty_print(spacing + " ")
|
||||
else:
|
||||
str += f"{spacing} {key}: {itm}\n"
|
||||
return str
|
||||
|
||||
def __repr__(self) -> str:
|
||||
str = f"{self.__name__}[{self.__mcls__}]:\n"
|
||||
for key, itm in self.__struct__.items():
|
||||
str += f" {key}: {itm}\n"
|
||||
return str
|
||||
|
||||
|
||||
def parse_config(fname: str, config: dict):
|
||||
for key, obj in config.items():
|
||||
ConfigDB().insert(key, obj)
|
||||
@@ -111,7 +111,7 @@ def __doc_iogam__(id, obj, edges, thread):
|
||||
while input_size <= output_size and in_i < len(inputs):
|
||||
in_label = input_names[in_i]
|
||||
input = inputs[in_label]
|
||||
input_size += doc.signal_byte_size(input)
|
||||
input_size += doc.signal_byte_size(id, in_label, input)
|
||||
in_i += 1
|
||||
alias = doc.signal_alias(in_label, input)
|
||||
mtype = doc.signal_type(input)
|
||||
@@ -134,7 +134,7 @@ def __doc_iogam__(id, obj, edges, thread):
|
||||
while output_size < input_size and out_i < len(outputs):
|
||||
out_label = output_names[out_i]
|
||||
output = outputs[out_label]
|
||||
output_size += doc.signal_byte_size(output)
|
||||
output_size += doc.signal_byte_size(id, out_label, output)
|
||||
out_i += 1
|
||||
alias = doc.signal_alias(out_label, output)
|
||||
mtype = doc.signal_type(output)
|
||||
|
||||
Reference in New Issue
Block a user