corrected generators
This commit is contained in:
parent
347fdb81da
commit
873482d6a4
@ -16,10 +16,10 @@ import re
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from parserbase.mib_parser import FileParser
|
from fsfw_generators.parserbase.parser import FileParser
|
||||||
from utility.mib_csv_writer import CsvWriter
|
from fsfw_generators.utility.csv_writer import CsvWriter
|
||||||
from utility.mib_printer import Printer
|
from fsfw_generators.utility.printer import Printer
|
||||||
from utility.mib_file_management import copy_file
|
from fsfw_generators.utility.file_management import copy_file
|
||||||
|
|
||||||
|
|
||||||
DATE_TODAY = date.today()
|
DATE_TODAY = date.today()
|
||||||
|
@ -11,10 +11,10 @@
|
|||||||
import re
|
import re
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from parserbase.mib_file_list_parser import FileListParser
|
from fsfw_generators.parserbase.file_list_parser import FileListParser
|
||||||
from parserbase.mib_parser import FileParser
|
from fsfw_generators.parserbase.parser import FileParser
|
||||||
from utility.mib_csv_writer import CsvWriter
|
from fsfw_generators.utility.csv_writer import CsvWriter
|
||||||
from utility.mib_printer import Printer
|
from fsfw_generators.utility.printer import Printer
|
||||||
|
|
||||||
|
|
||||||
DH_COMMAND_PACKET_DEFINITION_DESTINATION = "../../mission/devices/devicepackets/"
|
DH_COMMAND_PACKET_DEFINITION_DESTINATION = "../../mission/devices/devicepackets/"
|
||||||
|
@ -11,12 +11,12 @@ On Windows, Build Tools installation might be necessary
|
|||||||
"""
|
"""
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from modgen.events.event_parser import handle_csv_export, handle_cpp_export, SubsystemDefinitionParser, EventParser
|
from fsfw_generators.events.event_parser import handle_csv_export, handle_cpp_export, SubsystemDefinitionParser, EventParser
|
||||||
from modgen.parserbase.file_list_parser import FileListParser
|
from fsfw_generators.parserbase.file_list_parser import FileListParser
|
||||||
from modgen.utility.printer import PrettyPrinter
|
from fsfw_generators.utility.printer import PrettyPrinter
|
||||||
|
from fsfw_generators.utility.file_management import copy_file, move_file
|
||||||
|
|
||||||
from definitions import BspSelect, BspFolderDict
|
from definitions import BspSelect, BspFolderDict
|
||||||
from utility.mib_file_management import copy_file, move_file
|
|
||||||
|
|
||||||
# TODO: Ask from user or store in json file?
|
# TODO: Ask from user or store in json file?
|
||||||
BSP_SELECT = BspSelect.BSP_LINUX.value
|
BSP_SELECT = BspSelect.BSP_LINUX.value
|
||||||
|
@ -10,10 +10,10 @@ On Windows, Build Tools installation might be necessary
|
|||||||
"""
|
"""
|
||||||
import datetime
|
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
|
export_object_file, write_translation_header_file
|
||||||
from modgen.utility.printer import PrettyPrinter
|
from fsfw_generators.utility.printer import PrettyPrinter
|
||||||
from modgen.utility.file_management import copy_file, move_file
|
from fsfw_generators.utility.file_management import copy_file, move_file
|
||||||
from definitions import DATABASE_NAME, BspSelect, BspFolderDict
|
from definitions import DATABASE_NAME, BspSelect, BspFolderDict
|
||||||
|
|
||||||
DATE_TODAY = datetime.datetime.now()
|
DATE_TODAY = datetime.datetime.now()
|
||||||
|
@ -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)
|
|
@ -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:
|
|
||||||
"""
|
|
@ -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.
|
To use MySQLdb, run pip install mysqlclient or install in IDE. On Windows, Build Tools installation might be necessary.
|
||||||
:data: 21.11.2019
|
:data: 21.11.2019
|
||||||
"""
|
"""
|
||||||
from modgen.parserbase.file_list_parser import FileListParser
|
from fsfw_generators.parserbase.file_list_parser import FileListParser
|
||||||
from modgen.returnvalues.returnvalues_parser import InterfaceParser, ReturnValueParser
|
from fsfw_generators.returnvalues.returnvalues_parser import InterfaceParser, ReturnValueParser
|
||||||
from modgen.utility.sql_writer import SqlWriter
|
from fsfw_generators.utility.sql_writer import SqlWriter
|
||||||
from modgen.utility.file_management import move_file
|
from fsfw_generators.utility.file_management import move_file
|
||||||
|
|
||||||
from definitions import DATABASE_NAME, BspSelect, BspFolderDict
|
from definitions import DATABASE_NAME, BspSelect, BspFolderDict
|
||||||
|
|
||||||
|
@ -21,8 +21,8 @@ enum Subservice: uint8_t {
|
|||||||
import re
|
import re
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from parserbase.mib_file_list_parser import FileListParser
|
from fsfw_generators.parserbase.file_list_parser import FileListParser
|
||||||
from parserbase.mib_parser import FileParser
|
from fsfw_generators.parserbase.parser import FileParser
|
||||||
from utility.mib_csv_writer import CsvWriter
|
from utility.mib_csv_writer import CsvWriter
|
||||||
from utility.mib_printer import Printer
|
from utility.mib_printer import Printer
|
||||||
|
|
||||||
|
@ -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)
|
|
||||||
|
|
||||||
|
|
@ -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)
|
|
@ -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="")
|
|
||||||
|
|
@ -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()
|
|
Reference in New Issue
Block a user