66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
"""
|
|
Main entry point for the MARTe Autodoc project"
|
|
|
|
Author: Martino Ferrari
|
|
Email: martinogiordano.ferrari@iter.org
|
|
"""
|
|
from argparse import ArgumentParser
|
|
import logging
|
|
import sys
|
|
import os
|
|
import pprint
|
|
|
|
from MARTe.StandardParser import StandardParser
|
|
from MARTe.StandardParser import ParseException
|
|
import json
|
|
|
|
import autodoc
|
|
|
|
__version__ = "0.0.0"
|
|
|
|
def __args__():
|
|
"""Parse arguments."""
|
|
parser = ArgumentParser(
|
|
prog="autodoc",
|
|
description="MARTe configuration auto documentation tool",
|
|
)
|
|
parser.add_argument("filename", help="Configuration file to document", type=str)
|
|
parser.add_argument("--type", choices=["json", "marte"], default="marte", help="Configuration file type (default: `marte`)")
|
|
parser.add_argument("--loglevel", choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], default="ERROR", help="Logging level (default: `ERROR`)")
|
|
parser.add_argument("--version", action="version", version=__version__)
|
|
return parser.parse_args()
|
|
|
|
def main():
|
|
"""Main function."""
|
|
args = __args__()
|
|
logging.basicConfig(level=args.loglevel)
|
|
logging.info(f"AutoDoc v{__version__}")
|
|
if not os.path.exists(args.filename):
|
|
logging.error(f"Specified file `{args.filename}` does not exists")
|
|
sys.exit(1)
|
|
config = {}
|
|
if args.type == 'marte':
|
|
parser = StandardParser()
|
|
try:
|
|
config = parser.parse_file(args.filename)
|
|
except ParseException as e:
|
|
logging.error(f"Impossible to parse file `{args.filename}` at position ({e.line},{e.col}): {e.msg}`")
|
|
sys.exit(1)
|
|
except Exception as e:
|
|
logging.error(f"Sometihng went wrong with file `{args.filename}`")
|
|
sys.exit(1)
|
|
else:
|
|
with open(args.filename, "r") as file:
|
|
config = json.load(file)
|
|
if not config:
|
|
logging.error(f"Impossible to load configuration `{args.filename}`")
|
|
sys.exit(1)
|
|
print(f"# `{os.path.splitext(os.path.basename(args.filename))[0]}` Documentation")
|
|
for label, obj in config.items():
|
|
if 'Class' in obj:
|
|
autodoc.document(label, obj)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
|