improved csv format

This commit is contained in:
Robin Müller 2022-06-21 01:21:01 +02:00
parent a2e0c4f98e
commit a5dee6e417
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
2 changed files with 32 additions and 23 deletions

View File

@ -239,19 +239,22 @@ class EventParser(FileParser):
return description return description
def export_to_file(filename: Path, event_list: EventDictT, file_separator: str): def export_to_csv(filename: Path, event_list: EventDictT, col_sep: str):
file = open(filename, "w") with open(filename, "w") as out:
fsep = file_separator fsep = col_sep
for entry in event_list.items(): out.write(
event_id = int(entry[0]) f"Event ID (dec){col_sep} Event ID (hex){col_sep} Name{col_sep} "
event_value = entry[1] f"Severity{col_sep} Description{col_sep} File Path\n"
event_id_as_hex = f"{event_id:#06x}"
file.write(
f"{event_id}{fsep}{event_id_as_hex}{fsep}{event_value.name}{fsep}"
f"{event_value.severity}{fsep}{event_value.description}"
f"{fsep}{event_value.file_name.as_posix()}\n"
) )
file.close() for entry in event_list.items():
event_id = int(entry[0])
event_value = entry[1]
event_id_as_hex = f"{event_id:#06x}"
out.write(
f"{event_id}{fsep}{event_id_as_hex}{fsep}{event_value.name}{fsep}"
f"{event_value.severity}{fsep}{event_value.description}"
f"{fsep}{event_value.file_name.as_posix()}\n"
)
def write_translation_source_file( def write_translation_source_file(
@ -297,9 +300,7 @@ def handle_csv_export(file_name: Path, event_list: EventDictT, file_separator: s
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.
""" """
export_to_file( export_to_csv(filename=file_name, event_list=event_list, col_sep=file_separator)
filename=file_name, event_list=event_list, file_separator=file_separator
)
def handle_cpp_export( def handle_cpp_export(

View File

@ -405,15 +405,23 @@ class ReturnValueParser(FileParser):
self.mib_table = self.return_value_dict self.mib_table = self.return_value_dict
@staticmethod @staticmethod
def export_to_file(filename: Path, list_of_entries: RetvalDictT, file_sep: str): def export_to_csv(filename: Path, list_of_entries: RetvalDictT, column_sep: str):
file = open(filename, "w") with open(filename, "w") as out:
for entry in list_of_entries.items(): out.write(
file.write( f"Full ID (hex){column_sep} Name{column_sep} Description{column_sep} "
f"{entry[0]:#06x}{file_sep}{entry[1].name}{file_sep}{entry[1].description}" f"Unique ID{column_sep} Subsytem Name{column_sep} File Path\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() for entry in list_of_entries.items():
if column_sep == ";":
entry[1].description = entry[1].description.replace(";", ",")
elif column_sep == ",":
# Quote the description
entry[1].description = f'"{entry[1].description}"'
out.write(
f"{entry[0]:#06x}{column_sep}{entry[1].name}{column_sep}{entry[1].description}"
f"{column_sep}{entry[1].unique_id}{column_sep}{entry[1].subsystem_name}"
f"{column_sep}{entry[1].file_name.as_posix()}\n"
)
def build_checked_string( def build_checked_string(
self, self,