some more minor improvements

This commit is contained in:
Robin Müller 2022-06-21 00:57:01 +02:00
parent 1b1ac86e8c
commit a2e0c4f98e
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
6 changed files with 37 additions and 44 deletions

View File

@ -1,18 +1,14 @@
import re
import os
import logging
from pathlib import Path
from typing import List, Optional, Tuple, Dict
from typing import List, Optional, Dict
from fsfwgen.parserbase.parser import FileParser
from fsfwgen.logging import get_console_logger
LOGGER = get_console_logger()
EVENT_ENTRY_NAME_IDX = 0
EVENT_ENTRY_SEVERITY_IDX = 1
EVENT_ENTRY_INFO_IDX = 2
EVENT_SOURCE_FILE_IDX = 3
FSFW_EVENT_HEADER_INCLUDE = '#include "fsfw/events/Event.h"'
DEFAULT_MOVING_WINDOWS_SIZE = 7
SUBSYSTEM_ID_NAMESPACE = "SUBSYSTEM_ID"
@ -296,7 +292,7 @@ def write_translation_header_file(filename: Path = "translateEvents.h"):
)
def handle_csv_export(file_name: Path, event_list: list, file_separator: str):
def handle_csv_export(file_name: Path, event_list: EventDictT, file_separator: str):
"""
Generates the CSV in the same directory as the .py file and copes the CSV to another
directory if specified.
@ -307,7 +303,7 @@ def handle_csv_export(file_name: Path, event_list: list, file_separator: str):
def handle_cpp_export(
event_list: list,
event_list: EventDictT,
date_string: str,
file_name: Path = "translateEvents.cpp",
generate_header: bool = True,

View File

@ -44,28 +44,27 @@ def export_object_file(filename, object_list, file_separator: str = ","):
def write_translation_file(filename: str, list_of_entries, date_string_full: str):
outputfile = open(filename, "w")
LOGGER.info("ObjectParser: Writing translation file " + filename)
definitions = ""
function = (
"const char *translateObject(object_id_t object) "
"{\n switch ((object & 0xFFFFFFFF)) {\n"
)
for entry in list_of_entries:
# first part of translate file
definitions += f'const char *{entry[1][0]}_STRING = "{entry[1][0]}";\n'
# second part of translate file. entry[i] contains 32 bit hexadecimal numbers
function += f" case {entry[0]}:\n return {entry[1][0]}_STRING;\n"
function += ' default:\n return "UNKNOWN_OBJECT";\n }\n'
outputfile.write(
f"/**\n * @brief Auto-generated object translation file.\n"
f" * @details\n"
f" * Contains {len(list_of_entries)} translations.\n"
f" * Generated on: {date_string_full}\n */\n"
)
outputfile.write('#include "translateObjects.h"\n\n')
outputfile.write(definitions + "\n" + function + " return 0;\n}\n")
outputfile.close()
with open(filename, "w") as out:
LOGGER.info("ObjectParser: Writing translation file " + filename)
definitions = ""
function = (
"const char *translateObject(object_id_t object) "
"{\n switch ((object & 0xFFFFFFFF)) {\n"
)
for entry in list_of_entries:
# first part of translate file
definitions += f'const char *{entry[1][0]}_STRING = "{entry[1][0]}";\n'
# second part of translate file. entry[i] contains 32 bit hexadecimal numbers
function += f" case {entry[0]}:\n return {entry[1][0]}_STRING;\n"
function += ' default:\n return "UNKNOWN_OBJECT";\n }\n'
out.write(
f"/**\n * @brief Auto-generated object translation file.\n"
f" * @details\n"
f" * Contains {len(list_of_entries)} translations.\n"
f" * Generated on: {date_string_full}\n */\n"
)
out.write('#include "translateObjects.h"\n\n')
out.write(definitions + "\n" + function + " return 0;\n}\n")
def write_translation_header_file(filename: str = "translateObjects.h"):

View File

@ -1,12 +1,11 @@
"""Generic File Parser class
Used by parse header files. Implemented as class in case header parser becomes more complex
"""
import os
import re
from pathlib import Path
from typing import Union, List
from fsfwgen.logging import get_console_logger
from logging import DEBUG
LOGGER = get_console_logger()
@ -60,9 +59,7 @@ class FileListParser:
local_header_files = []
if print_current_dir:
print(f"Parsing header files in: {base_directory}")
# g.PP.pprint(base_list)
for entry in base_directory.iterdir():
# header_file_match = re.match(r"[_.]*.*\.h", entry.as_posix())
if (
entry.is_file()
and entry.suffix == ".h"
@ -72,6 +69,4 @@ class FileListParser:
if seach_recursively:
if entry.is_dir():
self.__get_header_file_list(entry, seach_recursively)
# print("Files found in: " + base_directory)
# g.PP.pprint(local_header_files)
self.header_files.extend(local_header_files)

View File

@ -26,8 +26,8 @@ class VerbosityLevels(enum.Enum):
class FileParserModes(Enum):
REGULAR = auto()
MOVING_WINDOW = auto()
REGULAR = 1
MOVING_WINDOW = 2
class FileParser:

View File

@ -409,8 +409,9 @@ class ReturnValueParser(FileParser):
file = open(filename, "w")
for entry in list_of_entries.items():
file.write(
f"{entry[0]:#06x}{file_sep}{entry[1].name}{file_sep}{entry[1].description}{file_sep}"
f"{entry[1].unique_id}{file_sep}{entry[1].subsystem_name}{file_sep}{entry[1].file_name.as_posix()}\n"
f"{entry[0]:#06x}{file_sep}{entry[1].name}{file_sep}{entry[1].description}"
f"{file_sep}{entry[1].unique_id}{file_sep}{entry[1].subsystem_name}{file_sep}"
f"{entry[1].file_name.as_posix()}\n"
)
file.close()

View File

@ -1,3 +1,5 @@
from pathlib import Path
from fsfwgen.utility.file_management import copy_file, move_file
@ -5,7 +7,7 @@ from fsfwgen.utility.file_management import copy_file, move_file
class CsvWriter:
def __init__(
self,
filename: str,
filename: Path,
table_to_print=None,
header_array=None,
file_separator: str = ",",
@ -40,11 +42,11 @@ class CsvWriter:
file.write(str(entry[columnIndex]) + "\n")
file.close()
def copy_csv(self, copy_destination: str = "."):
def copy_csv(self, copy_destination: Path = "."):
copy_file(self.filename, copy_destination)
print("CSV file was copied to " + copy_destination)
print(f"CSV file was copied to {copy_destination}")
def move_csv(self, move_destination: str):
def move_csv(self, move_destination: Path):
move_file(self.filename, move_destination)
if move_destination == ".." or move_destination == "../":
print("CSV Writer: CSV file was moved to parser root directory")