continuing rework of generators
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good

This commit is contained in:
2023-02-09 15:14:21 +01:00
parent 8a88695409
commit 59689f2af6
4 changed files with 65 additions and 56 deletions

View File

@ -2,10 +2,10 @@
Object exporter.
"""
import datetime
import logging
import os
from pathlib import Path
from fsfwgen.logging import get_console_logger
from fsfwgen.objects.objects import (
sql_object_exporter,
ObjectDefinitionParser,
@ -18,7 +18,7 @@ from fsfwgen.utility.file_management import copy_file
from definitions import BspType, DATABASE_NAME, OBSW_ROOT_DIR, ROOT_DIR
LOGGER = get_console_logger()
_LOGGER = logging.getLogger(__name__)
DATE_TODAY = datetime.datetime.now()
DATE_STRING_FULL = DATE_TODAY.strftime("%Y-%m-%d %H:%M:%S")
@ -30,29 +30,40 @@ COPY_CPP = True
GENERATE_HEADER = True
BSP_SELECT = BspType.BSP_Q7S
BSP_DIR_NAME = BSP_SELECT.value
if BSP_SELECT == BspType.BSP_Q7S or BSP_SELECT == BspType.BSP_LINUX_BOARD:
FSFW_CONFIG_ROOT = f"{OBSW_ROOT_DIR}/linux/fsfwconfig"
else:
FSFW_CONFIG_ROOT = f"{OBSW_ROOT_DIR}/{BSP_DIR_NAME}/fsfwconfig"
class BspConfig:
def __init__(self, bsp_select: BspType):
self.bsp_select = bsp_select
self.bsp_dir_name = bsp_select.value
if (
self.bsp_select == BspType.BSP_Q7S
or self.bsp_select == BspType.BSP_LINUX_BOARD
):
self.fsfw_config_root = f"{OBSW_ROOT_DIR}/linux/fsfwconfig"
else:
self.fsfw_config_root = f"{OBSW_ROOT_DIR}/{self.bsp_dir_name}/fsfwconfig"
self.cpp_copy_dest = Path(f"{self.fsfw_config_root}/objects/")
self.csv_obj_filename = f"{ROOT_DIR}/{self.bsp_dir_name}_objects.csv"
self.objects_path = Path(f"{self.fsfw_config_root}/objects/systemObjectList.h")
self.objects_defs = [
self.objects_path,
FRAMEWORK_OBJECT_PATH,
COMMON_OBJECTS_PATH,
]
EXPORT_TO_SQL = True
CPP_COPY_DESTINATION = f"{FSFW_CONFIG_ROOT}/objects/"
CPP_FILENAME = f"{os.path.dirname(os.path.realpath(__file__))}//translateObjects.cpp"
CPP_H_FILENAME = f"{os.path.dirname(os.path.realpath(__file__))}//translateObjects.h"
CSV_OBJECT_FILENAME = f"{ROOT_DIR}/{BSP_SELECT.value}_objects.csv"
CSV_COPY_DEST = f"{OBSW_ROOT_DIR}/tmtc/eive_tmtc/config/objects.csv"
FILE_SEPARATOR = ";"
OBJECTS_PATH = Path(f"{FSFW_CONFIG_ROOT}/objects/systemObjectList.h")
FRAMEWORK_OBJECT_PATH = Path(
f"{OBSW_ROOT_DIR}/fsfw/src/fsfw/objectmanager/frameworkObjects.h"
)
COMMON_OBJECTS_PATH = Path(f"{OBSW_ROOT_DIR}/common/config/eive/objects.h")
OBJECTS_DEFINITIONS = [OBJECTS_PATH, FRAMEWORK_OBJECT_PATH, COMMON_OBJECTS_PATH]
SQL_DELETE_OBJECTS_CMD = """
DROP TABLE IF EXISTS Objects
@ -72,20 +83,21 @@ VALUES(?,?)
"""
def parse_objects(print_object_list: bool = True):
def parse_objects(bsp_select: BspType, print_object_list: bool = True):
cfg = BspConfig(bsp_select)
# fetch objects
object_parser = ObjectDefinitionParser(OBJECTS_DEFINITIONS)
object_parser = ObjectDefinitionParser(cfg.objects_defs)
subsystem_definitions = object_parser.parse_files()
# id_subsystem_definitions.update(framework_subsystem_definitions)
list_items = sorted(subsystem_definitions.items())
LOGGER.info(f"ObjectParser: Number of objects: {len(list_items)}")
_LOGGER.info(f"ObjectParser: Number of objects: {len(list_items)}")
if print_object_list:
PrettyPrinter.pprint(list_items)
handle_file_export(list_items)
handle_file_export(cfg, list_items)
if EXPORT_TO_SQL:
LOGGER.info("ObjectParser: Exporting to SQL")
_LOGGER.info("ObjectParser: Exporting to SQL")
sql_object_exporter(
object_table=list_items,
delete_cmd=SQL_DELETE_OBJECTS_CMD,
@ -95,29 +107,31 @@ def parse_objects(print_object_list: bool = True):
)
def handle_file_export(list_items):
def handle_file_export(cfg: BspConfig, list_items):
if GENERATE_CPP:
LOGGER.info("ObjectParser: Generating C++ translation file")
_LOGGER.info("ObjectParser: Generating C++ translation file")
write_translation_file(
filename=CPP_FILENAME,
list_of_entries=list_items,
date_string_full=DATE_STRING_FULL,
)
if COPY_CPP:
LOGGER.info("ObjectParser: Copying object file to " + CPP_COPY_DESTINATION)
copy_file(CPP_FILENAME, CPP_COPY_DESTINATION)
_LOGGER.info(
"ObjectParser: Copying object file to " + str(cfg.cpp_copy_dest)
)
copy_file(Path(CPP_FILENAME), cfg.cpp_copy_dest)
if GENERATE_HEADER:
write_translation_header_file(filename=CPP_H_FILENAME)
copy_file(filename=CPP_H_FILENAME, destination=CPP_COPY_DESTINATION)
copy_file(filename=Path(CPP_H_FILENAME), destination=cfg.cpp_copy_dest)
if GENERATE_CSV:
LOGGER.info("ObjectParser: Generating text export")
_LOGGER.info("ObjectParser: Generating text export")
export_object_file(
filename=CSV_OBJECT_FILENAME,
filename=cfg.csv_obj_filename,
object_list=list_items,
file_separator=FILE_SEPARATOR,
)
copy_file(
filename=CSV_OBJECT_FILENAME,
destination=CSV_COPY_DEST,
filename=Path(cfg.csv_obj_filename),
destination=Path(CSV_COPY_DEST),
delete_existing_file=True,
)