From 873482d6a4a1df53281634e939286b34485e8007 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 8 Jun 2021 12:57:41 +0200 Subject: [PATCH] corrected generators --- generators/datapool/mib_datapool_parser.py | 8 +-- .../mib_device_command_parser.py | 8 +-- generators/events/event_parser.py | 8 +-- generators/objects/objects.py | 6 +- generators/parserbase/__init__.py | 0 generators/parserbase/mib_file_list_parser.py | 71 ------------------- generators/parserbase/mib_parser.py | 71 ------------------- .../returnvalues/returnvalues_parser.py | 8 +-- .../subservice/mib_subservice_parser.py | 4 +- generators/utility/mib_csv_writer.py | 62 ---------------- generators/utility/mib_file_management.py | 22 ------ generators/utility/mib_printer.py | 15 ---- generators/utility/mib_sql_writer.py | 37 ---------- 13 files changed, 21 insertions(+), 299 deletions(-) delete mode 100644 generators/parserbase/__init__.py delete mode 100644 generators/parserbase/mib_file_list_parser.py delete mode 100644 generators/parserbase/mib_parser.py delete mode 100644 generators/utility/mib_csv_writer.py delete mode 100644 generators/utility/mib_file_management.py delete mode 100644 generators/utility/mib_printer.py delete mode 100644 generators/utility/mib_sql_writer.py diff --git a/generators/datapool/mib_datapool_parser.py b/generators/datapool/mib_datapool_parser.py index d1299f1..1825a5a 100644 --- a/generators/datapool/mib_datapool_parser.py +++ b/generators/datapool/mib_datapool_parser.py @@ -16,10 +16,10 @@ import re from enum import Enum from datetime import date -from parserbase.mib_parser import FileParser -from utility.mib_csv_writer import CsvWriter -from utility.mib_printer import Printer -from utility.mib_file_management import copy_file +from fsfw_generators.parserbase.parser import FileParser +from fsfw_generators.utility.csv_writer import CsvWriter +from fsfw_generators.utility.printer import Printer +from fsfw_generators.utility.file_management import copy_file DATE_TODAY = date.today() diff --git a/generators/devicecommands/mib_device_command_parser.py b/generators/devicecommands/mib_device_command_parser.py index 64d074a..70dfe01 100644 --- a/generators/devicecommands/mib_device_command_parser.py +++ b/generators/devicecommands/mib_device_command_parser.py @@ -11,10 +11,10 @@ import re from enum import Enum -from parserbase.mib_file_list_parser import FileListParser -from parserbase.mib_parser import FileParser -from utility.mib_csv_writer import CsvWriter -from utility.mib_printer import Printer +from fsfw_generators.parserbase.file_list_parser import FileListParser +from fsfw_generators.parserbase.parser import FileParser +from fsfw_generators.utility.csv_writer import CsvWriter +from fsfw_generators.utility.printer import Printer DH_COMMAND_PACKET_DEFINITION_DESTINATION = "../../mission/devices/devicepackets/" diff --git a/generators/events/event_parser.py b/generators/events/event_parser.py index a77d2f8..e99d720 100644 --- a/generators/events/event_parser.py +++ b/generators/events/event_parser.py @@ -11,12 +11,12 @@ On Windows, Build Tools installation might be necessary """ import datetime -from modgen.events.event_parser import handle_csv_export, handle_cpp_export, SubsystemDefinitionParser, EventParser -from modgen.parserbase.file_list_parser import FileListParser -from modgen.utility.printer import PrettyPrinter +from fsfw_generators.events.event_parser import handle_csv_export, handle_cpp_export, SubsystemDefinitionParser, EventParser +from fsfw_generators.parserbase.file_list_parser import FileListParser +from fsfw_generators.utility.printer import PrettyPrinter +from fsfw_generators.utility.file_management import copy_file, move_file from definitions import BspSelect, BspFolderDict -from utility.mib_file_management import copy_file, move_file # TODO: Ask from user or store in json file? BSP_SELECT = BspSelect.BSP_LINUX.value diff --git a/generators/objects/objects.py b/generators/objects/objects.py index 27c7833..4d2b0f2 100644 --- a/generators/objects/objects.py +++ b/generators/objects/objects.py @@ -10,10 +10,10 @@ On Windows, Build Tools installation might be necessary """ import datetime -from modgen.objects.objects import ObjectDefinitionParser, sql_object_exporter, write_translation_file, \ +from fsfw_generators.objects.objects import ObjectDefinitionParser, sql_object_exporter, write_translation_file, \ export_object_file, write_translation_header_file -from modgen.utility.printer import PrettyPrinter -from modgen.utility.file_management import copy_file, move_file +from fsfw_generators.utility.printer import PrettyPrinter +from fsfw_generators.utility.file_management import copy_file, move_file from definitions import DATABASE_NAME, BspSelect, BspFolderDict DATE_TODAY = datetime.datetime.now() diff --git a/generators/parserbase/__init__.py b/generators/parserbase/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/generators/parserbase/mib_file_list_parser.py b/generators/parserbase/mib_file_list_parser.py deleted file mode 100644 index 3e2dcb9..0000000 --- a/generators/parserbase/mib_file_list_parser.py +++ /dev/null @@ -1,71 +0,0 @@ -""" -@file mib_file_list_parser.py -@brief Generic File Parser class -@details -Used by parse header files. Implemented as class in case header parser becomes more complex -@author R. Mueller -@date 22.11.2019 -""" -import os -import re -from typing import Union - - -# pylint: disable=too-few-public-methods -class FileListParser: - """ - Generic header parser which takes a directory name or directory name list - and parses all included header files recursively. - """ - def __init__(self, directory_list_or_name: Union[str, list]): - if isinstance(directory_list_or_name, str): - self.directory_list = [directory_list_or_name] - elif isinstance(directory_list_or_name, list): - self.directory_list = directory_list_or_name - else: - print("Header Parser: Passed directory list is not a header name or list of " - "header names") - self.header_files = [] - - def parse_header_files(self, search_recursively: bool = False, - printout_string: str = "Parsing header files: ", - print_current_dir: bool = False): - """ - This function is called to get a list of header files - :param search_recursively: - :param printout_string: - :param print_current_dir: - :return: - """ - print(printout_string, end="") - for directory in self.directory_list: - self.__get_header_file_list(directory, search_recursively, print_current_dir) - print(str(len(self.header_files)) + " header files were found.") - # g.PP.pprint(self.header_files) - return self.header_files - - def __get_header_file_list(self, base_directory: str, seach_recursively: bool = False, - print_current_dir: bool = False): - if base_directory[-1] != '/': - base_directory += '/' - local_header_files = [] - if print_current_dir: - print("Parsing header files in: " + base_directory) - base_list = os.listdir(base_directory) - # g.PP.pprint(base_list) - for entry in base_list: - header_file_match = re.match(r"[_.]*.*\.h", entry) - if header_file_match: - if os.path.isfile(base_directory + entry): - match_string = header_file_match.group(0) - if match_string[0] == '.' or match_string[0] == '_': - pass - else: - local_header_files.append(base_directory + entry) - if seach_recursively: - next_path = base_directory + entry - if os.path.isdir(next_path): - self.__get_header_file_list(next_path, seach_recursively) - # print("Files found in: " + base_directory) - # g.PP.pprint(local_header_files) - self.header_files.extend(local_header_files) diff --git a/generators/parserbase/mib_parser.py b/generators/parserbase/mib_parser.py deleted file mode 100644 index 1f22ba5..0000000 --- a/generators/parserbase/mib_parser.py +++ /dev/null @@ -1,71 +0,0 @@ -#! /usr/bin/python3.7 -""" -@file - mib_packet_content_parser.py -@brief - Generic File Parser class -@details - Used by the MIB Exporter. There are two functions which can be implemented by child class. - Default implementations are empty - - 1. handleFileParsing(...) which handles the parsing of one file - 2. updateTableEntries(...) After all files have been parsed, the table can - be updated by imlementing this function - - A file list to parse must be supplied. - Child classes fill out the MIB table (self.mib_table) -@author - R. Mueller -@date - 14.11.2019 -""" -from abc import abstractmethod -from typing import Dict - - -class FileParser: - """ - This parent class gathers common file parser operations into a super class. - Everything else needs to be implemented by child classes - (e.g. which strings to parse for or operations to take after file parsing has finished) - """ - def __init__(self, file_list): - if len(file_list) == 0: - print("File list is empty !") - self.file_list_empty = True - else: - self.file_list_empty = False - self.file_list = file_list - # Can be used to have unique key in MIB tables - self.index = 0 - # Initialize empty MIB table which will be filled by specific parser implementation - self.mib_table = dict() - - def parse_files(self, *args: any, **kwargs) -> Dict: - """ - Core method which is called to parse the files - :param args: Optional positional arguments. Passed on the file parser - :param kwargs: Optional keyword arguments. Passed on to file parser - :return: - """ - if not self.file_list_empty: - for file_name in self.file_list: - # Implemented by child class ! Fill out info table (self.mib_table) in this routine - self._handle_file_parsing(file_name, *args, **kwargs) - # Can be implemented by child class to edit the table after it is finished. - # default implementation is empty - self._post_parsing_operation() - return self.mib_table - - # Implemented by child class ! Fill out info table (self.mib_table) in this routine - @abstractmethod - def _handle_file_parsing(self, file_name: str, *args, **kwargs): - pass - - @abstractmethod - def _post_parsing_operation(self): - """ - # Can be implemented by child class to perform post parsing operations (e.g. setting a - flag or editting MIB table entries) - :return: - """ diff --git a/generators/returnvalues/returnvalues_parser.py b/generators/returnvalues/returnvalues_parser.py index cab0bae..a185374 100644 --- a/generators/returnvalues/returnvalues_parser.py +++ b/generators/returnvalues/returnvalues_parser.py @@ -9,10 +9,10 @@ Returnvalue exporter. To use MySQLdb, run pip install mysqlclient or install in IDE. On Windows, Build Tools installation might be necessary. :data: 21.11.2019 """ -from modgen.parserbase.file_list_parser import FileListParser -from modgen.returnvalues.returnvalues_parser import InterfaceParser, ReturnValueParser -from modgen.utility.sql_writer import SqlWriter -from modgen.utility.file_management import move_file +from fsfw_generators.parserbase.file_list_parser import FileListParser +from fsfw_generators.returnvalues.returnvalues_parser import InterfaceParser, ReturnValueParser +from fsfw_generators.utility.sql_writer import SqlWriter +from fsfw_generators.utility.file_management import move_file from definitions import DATABASE_NAME, BspSelect, BspFolderDict diff --git a/generators/subservice/mib_subservice_parser.py b/generators/subservice/mib_subservice_parser.py index 7addb3e..cad995c 100644 --- a/generators/subservice/mib_subservice_parser.py +++ b/generators/subservice/mib_subservice_parser.py @@ -21,8 +21,8 @@ enum Subservice: uint8_t { import re from enum import Enum -from parserbase.mib_file_list_parser import FileListParser -from parserbase.mib_parser import FileParser +from fsfw_generators.parserbase.file_list_parser import FileListParser +from fsfw_generators.parserbase.parser import FileParser from utility.mib_csv_writer import CsvWriter from utility.mib_printer import Printer diff --git a/generators/utility/mib_csv_writer.py b/generators/utility/mib_csv_writer.py deleted file mode 100644 index 9823149..0000000 --- a/generators/utility/mib_csv_writer.py +++ /dev/null @@ -1,62 +0,0 @@ -#! /usr/bin/python3.7 -""" -@file - mib_packet_content_parser.py -@brief - CSV Writer -@details - This class writes tables to a csv. -@author - R. Mueller -@date - 14.11.2019 -""" -from utility import mib_globals as g -from utility.mib_file_management import copy_file, move_file - - -# TODO: Export to SQL -class CsvWriter: - def __init__(self, filename, table_to_print=None, header_array=None): - if header_array is None: - header_array = [] - if table_to_print is None: - table_to_print = dict() - self.filename = filename - self.tableToPrint = table_to_print - self.headerArray = header_array - if self.headerArray != 0: - self.columnNumbers = len(self.headerArray) - self.fileSeparator = g.fileSeparator - - def write_to_csv(self): - file = open(self.filename, "w") - file.write("Index" + self.fileSeparator) - for index in range(self.columnNumbers): - # noinspection PyTypeChecker - if index < len(self.headerArray)-1: - file.write(self.headerArray[index] + self.fileSeparator) - else: - file.write(self.headerArray[index] + "\n") - for index, entry in self.tableToPrint.items(): - file.write(str(index) + self.fileSeparator) - for columnIndex in range(self.columnNumbers): - # noinspection PyTypeChecker - if columnIndex < len(self.headerArray) - 1: - file.write(str(entry[columnIndex]) + self.fileSeparator) - else: - file.write(str(entry[columnIndex]) + "\n") - file.close() - - def copy_csv(self, copy_destination: str = g.copyDestination): - copy_file(self.filename, copy_destination) - print("CSV file was copied to " + copy_destination) - - def move_csv(self, move_destination): - move_file(self.filename, move_destination) - if move_destination == ".." or move_destination == "../": - print("CSV Writer: CSV file was moved to parser root directory") - else: - print("CSV Writer: CSV file was moved to " + move_destination) - - diff --git a/generators/utility/mib_file_management.py b/generators/utility/mib_file_management.py deleted file mode 100644 index b5fb901..0000000 --- a/generators/utility/mib_file_management.py +++ /dev/null @@ -1,22 +0,0 @@ -#! /usr/bin/python3.8 -# -*- coding: utf-8 -*- -import shutil -import os - -def copy_file(filename:str, destination: str= ""): - if os.path.exists(filename): - try: - shutil.copy2(filename, destination) - except FileNotFoundError as error: - print("File not found!") - print(error) - - -def move_file(file_name: str, destination: str= ""): - if os.path.exists(file_name): - try: - shutil.copy2(file_name, destination) - os.remove(file_name) - except FileNotFoundError as error: - print("File not found!") - print(error) \ No newline at end of file diff --git a/generators/utility/mib_printer.py b/generators/utility/mib_printer.py deleted file mode 100644 index 0928476..0000000 --- a/generators/utility/mib_printer.py +++ /dev/null @@ -1,15 +0,0 @@ -import pprint - -PrettyPrinter = pprint.PrettyPrinter(indent=0, width=250) - -class Printer: - def __init__(self): - pass - - @staticmethod - def print_content(dictionary, leading_string: str = ""): - if leading_string != "": - print(leading_string) - PrettyPrinter.pprint(dictionary) - print("\r\n", end="") - diff --git a/generators/utility/mib_sql_writer.py b/generators/utility/mib_sql_writer.py deleted file mode 100644 index 33bce25..0000000 --- a/generators/utility/mib_sql_writer.py +++ /dev/null @@ -1,37 +0,0 @@ -import sqlite3 -SQL_DATABASE_NAME = "obsw_mib.db" - - -class SqlWriter: - def __init__(self, filename: str = SQL_DATABASE_NAME): - self.filename = filename - self.conn = sqlite3.connect(self.filename) - - def open(self, sql_creation_command: str): - print("SQL Writer: Opening " + self.filename) - self.conn.execute(sql_creation_command) - - def delete(self, sql_deletion_command): - print("SQL Writer: Deleting SQL table") - self.conn.execute(sql_deletion_command) - - def write_entries(self, sql_insertion_command, current_entry): - cur = self.conn.cursor() - cur.execute(sql_insertion_command, current_entry) - return cur.lastrowid - - def commit(self): - print("SQL Writer: Commiting SQL table") - self.conn.commit() - - def close(self): - self.conn.close() - - def sql_writing_helper(self, creation_cmd, insertion_cmd, mib_table: dict, deletion_cmd: str=""): - if deletion_cmd != "": - self.delete(deletion_cmd) - self.open(creation_cmd) - for i in mib_table: - self.write_entries(insertion_cmd, mib_table[i]) - self.commit() - self.close()