some more minor improvements
This commit is contained in:
parent
1b1ac86e8c
commit
a2e0c4f98e
@ -1,18 +1,14 @@
|
|||||||
import re
|
import re
|
||||||
import os
|
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
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.parserbase.parser import FileParser
|
||||||
from fsfwgen.logging import get_console_logger
|
from fsfwgen.logging import get_console_logger
|
||||||
|
|
||||||
LOGGER = 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"'
|
FSFW_EVENT_HEADER_INCLUDE = '#include "fsfw/events/Event.h"'
|
||||||
DEFAULT_MOVING_WINDOWS_SIZE = 7
|
DEFAULT_MOVING_WINDOWS_SIZE = 7
|
||||||
SUBSYSTEM_ID_NAMESPACE = "SUBSYSTEM_ID"
|
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
|
Generates the CSV in the same directory as the .py file and copes the CSV to another
|
||||||
directory if specified.
|
directory if specified.
|
||||||
@ -307,7 +303,7 @@ def handle_csv_export(file_name: Path, event_list: list, file_separator: str):
|
|||||||
|
|
||||||
|
|
||||||
def handle_cpp_export(
|
def handle_cpp_export(
|
||||||
event_list: list,
|
event_list: EventDictT,
|
||||||
date_string: str,
|
date_string: str,
|
||||||
file_name: Path = "translateEvents.cpp",
|
file_name: Path = "translateEvents.cpp",
|
||||||
generate_header: bool = True,
|
generate_header: bool = True,
|
||||||
|
@ -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):
|
def write_translation_file(filename: str, list_of_entries, date_string_full: str):
|
||||||
outputfile = open(filename, "w")
|
with open(filename, "w") as out:
|
||||||
LOGGER.info("ObjectParser: Writing translation file " + filename)
|
LOGGER.info("ObjectParser: Writing translation file " + filename)
|
||||||
definitions = ""
|
definitions = ""
|
||||||
function = (
|
function = (
|
||||||
"const char *translateObject(object_id_t object) "
|
"const char *translateObject(object_id_t object) "
|
||||||
"{\n switch ((object & 0xFFFFFFFF)) {\n"
|
"{\n switch ((object & 0xFFFFFFFF)) {\n"
|
||||||
)
|
)
|
||||||
for entry in list_of_entries:
|
for entry in list_of_entries:
|
||||||
# first part of translate file
|
# first part of translate file
|
||||||
definitions += f'const char *{entry[1][0]}_STRING = "{entry[1][0]}";\n'
|
definitions += f'const char *{entry[1][0]}_STRING = "{entry[1][0]}";\n'
|
||||||
# second part of translate file. entry[i] contains 32 bit hexadecimal numbers
|
# 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 += f" case {entry[0]}:\n return {entry[1][0]}_STRING;\n"
|
||||||
function += ' default:\n return "UNKNOWN_OBJECT";\n }\n'
|
function += ' default:\n return "UNKNOWN_OBJECT";\n }\n'
|
||||||
outputfile.write(
|
out.write(
|
||||||
f"/**\n * @brief Auto-generated object translation file.\n"
|
f"/**\n * @brief Auto-generated object translation file.\n"
|
||||||
f" * @details\n"
|
f" * @details\n"
|
||||||
f" * Contains {len(list_of_entries)} translations.\n"
|
f" * Contains {len(list_of_entries)} translations.\n"
|
||||||
f" * Generated on: {date_string_full}\n */\n"
|
f" * Generated on: {date_string_full}\n */\n"
|
||||||
)
|
)
|
||||||
outputfile.write('#include "translateObjects.h"\n\n')
|
out.write('#include "translateObjects.h"\n\n')
|
||||||
outputfile.write(definitions + "\n" + function + " return 0;\n}\n")
|
out.write(definitions + "\n" + function + " return 0;\n}\n")
|
||||||
outputfile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def write_translation_header_file(filename: str = "translateObjects.h"):
|
def write_translation_header_file(filename: str = "translateObjects.h"):
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
"""Generic File Parser class
|
"""Generic File Parser class
|
||||||
Used by parse header files. Implemented as class in case header parser becomes more complex
|
Used by parse header files. Implemented as class in case header parser becomes more complex
|
||||||
"""
|
"""
|
||||||
import os
|
|
||||||
import re
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Union, List
|
from typing import Union, List
|
||||||
|
|
||||||
from fsfwgen.logging import get_console_logger
|
from fsfwgen.logging import get_console_logger
|
||||||
|
from logging import DEBUG
|
||||||
|
|
||||||
LOGGER = get_console_logger()
|
LOGGER = get_console_logger()
|
||||||
|
|
||||||
@ -60,9 +59,7 @@ class FileListParser:
|
|||||||
local_header_files = []
|
local_header_files = []
|
||||||
if print_current_dir:
|
if print_current_dir:
|
||||||
print(f"Parsing header files in: {base_directory}")
|
print(f"Parsing header files in: {base_directory}")
|
||||||
# g.PP.pprint(base_list)
|
|
||||||
for entry in base_directory.iterdir():
|
for entry in base_directory.iterdir():
|
||||||
# header_file_match = re.match(r"[_.]*.*\.h", entry.as_posix())
|
|
||||||
if (
|
if (
|
||||||
entry.is_file()
|
entry.is_file()
|
||||||
and entry.suffix == ".h"
|
and entry.suffix == ".h"
|
||||||
@ -72,6 +69,4 @@ class FileListParser:
|
|||||||
if seach_recursively:
|
if seach_recursively:
|
||||||
if entry.is_dir():
|
if entry.is_dir():
|
||||||
self.__get_header_file_list(entry, seach_recursively)
|
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)
|
self.header_files.extend(local_header_files)
|
||||||
|
@ -26,8 +26,8 @@ class VerbosityLevels(enum.Enum):
|
|||||||
|
|
||||||
|
|
||||||
class FileParserModes(Enum):
|
class FileParserModes(Enum):
|
||||||
REGULAR = auto()
|
REGULAR = 1
|
||||||
MOVING_WINDOW = auto()
|
MOVING_WINDOW = 2
|
||||||
|
|
||||||
|
|
||||||
class FileParser:
|
class FileParser:
|
||||||
|
@ -409,8 +409,9 @@ class ReturnValueParser(FileParser):
|
|||||||
file = open(filename, "w")
|
file = open(filename, "w")
|
||||||
for entry in list_of_entries.items():
|
for entry in list_of_entries.items():
|
||||||
file.write(
|
file.write(
|
||||||
f"{entry[0]:#06x}{file_sep}{entry[1].name}{file_sep}{entry[1].description}{file_sep}"
|
f"{entry[0]:#06x}{file_sep}{entry[1].name}{file_sep}{entry[1].description}"
|
||||||
f"{entry[1].unique_id}{file_sep}{entry[1].subsystem_name}{file_sep}{entry[1].file_name.as_posix()}\n"
|
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()
|
file.close()
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from fsfwgen.utility.file_management import copy_file, move_file
|
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:
|
class CsvWriter:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
filename: str,
|
filename: Path,
|
||||||
table_to_print=None,
|
table_to_print=None,
|
||||||
header_array=None,
|
header_array=None,
|
||||||
file_separator: str = ",",
|
file_separator: str = ",",
|
||||||
@ -40,11 +42,11 @@ class CsvWriter:
|
|||||||
file.write(str(entry[columnIndex]) + "\n")
|
file.write(str(entry[columnIndex]) + "\n")
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
def copy_csv(self, copy_destination: str = "."):
|
def copy_csv(self, copy_destination: Path = "."):
|
||||||
copy_file(self.filename, copy_destination)
|
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)
|
move_file(self.filename, move_destination)
|
||||||
if move_destination == ".." or move_destination == "../":
|
if move_destination == ".." or move_destination == "../":
|
||||||
print("CSV Writer: CSV file was moved to parser root directory")
|
print("CSV Writer: CSV file was moved to parser root directory")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user