introduced logger
This commit is contained in:
parent
2043b92cd4
commit
8e805d2408
50
core.py
Normal file
50
core.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import enum
|
||||||
|
|
||||||
|
import colorlog
|
||||||
|
import logging
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
|
CONSOLE_LOGGER_NAME = 'FSFW Generator Logger'
|
||||||
|
LOGGER_INSTANCE = None
|
||||||
|
|
||||||
|
|
||||||
|
def get_console_logger():
|
||||||
|
global LOGGER_INSTANCE
|
||||||
|
if LOGGER_INSTANCE is None:
|
||||||
|
LOGGER_INSTANCE = init_console_logger()
|
||||||
|
return LOGGER_INSTANCE
|
||||||
|
|
||||||
|
|
||||||
|
def init_console_logger():
|
||||||
|
handler = colorlog.StreamHandler()
|
||||||
|
handler.setFormatter(colorlog.ColoredFormatter(
|
||||||
|
'%(log_color)s%(levelname)s: %(message)s'))
|
||||||
|
|
||||||
|
logger = colorlog.getLogger(CONSOLE_LOGGER_NAME)
|
||||||
|
logger.addHandler(handler)
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
return logger
|
||||||
|
|
||||||
|
|
||||||
|
class ParserTypes(enum.Enum):
|
||||||
|
EVENTS = 'events',
|
||||||
|
OBJECTS = 'objects',
|
||||||
|
RETVALS = 'returnvalues',
|
||||||
|
SUBSERVICES = 'subservices'
|
||||||
|
|
||||||
|
|
||||||
|
def init_printout():
|
||||||
|
global LOGGER_INSTANCE
|
||||||
|
LOGGER_INSTANCE = get_console_logger()
|
||||||
|
print('-- FSFW MOD Generator --')
|
||||||
|
|
||||||
|
|
||||||
|
def return_generic_args_parser() -> argparse.ArgumentParser:
|
||||||
|
parser = argparse.ArgumentParser('Arguments for FSFW MOD generation')
|
||||||
|
choices = ("events", "objects", "returnvalues", "subservices")
|
||||||
|
parser.add_argument(
|
||||||
|
'type', metavar='type', choices=choices,
|
||||||
|
help=f'Type of MOD data to generate. Choices: {choices}'
|
||||||
|
)
|
||||||
|
return parser
|
@ -2,6 +2,9 @@ import re
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from fsfwgen.parserbase.parser import FileParser
|
from fsfwgen.parserbase.parser import FileParser
|
||||||
|
from fsfwgen.core import get_console_logger
|
||||||
|
|
||||||
|
LOGGER = get_console_logger()
|
||||||
|
|
||||||
EVENT_ENTRY_NAME_IDX = 0
|
EVENT_ENTRY_NAME_IDX = 0
|
||||||
EVENT_ENTRY_SEVERITY_IDX = 1
|
EVENT_ENTRY_SEVERITY_IDX = 1
|
||||||
@ -280,7 +283,6 @@ def handle_csv_export(file_name: str, event_list: list, 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.
|
||||||
"""
|
"""
|
||||||
print("EventParser: Exporting to file: " + file_name)
|
|
||||||
export_to_file(filename=file_name, event_list=event_list, file_separator=file_separator)
|
export_to_file(filename=file_name, event_list=event_list, file_separator=file_separator)
|
||||||
|
|
||||||
|
|
||||||
@ -288,7 +290,6 @@ def handle_cpp_export(
|
|||||||
event_list: list, date_string: str, file_name: str = "translateEvents.cpp",
|
event_list: list, date_string: str, file_name: str = "translateEvents.cpp",
|
||||||
generate_header: bool = True, header_file_name: str = "translateEvents.h"
|
generate_header: bool = True, header_file_name: str = "translateEvents.h"
|
||||||
):
|
):
|
||||||
print("EventParser: Generating translation cpp file.")
|
|
||||||
write_translation_source_file(event_list=event_list, date_string=date_string, filename=file_name)
|
write_translation_source_file(event_list=event_list, date_string=date_string, filename=file_name)
|
||||||
if generate_header:
|
if generate_header:
|
||||||
write_translation_header_file(filename=header_file_name)
|
write_translation_header_file(filename=header_file_name)
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from fsfwgen.parserbase.parser import FileParser
|
from fsfwgen.parserbase.parser import FileParser
|
||||||
|
from fsfwgen.core import get_console_logger
|
||||||
from fsfwgen.utility.sql_writer import SqlWriter
|
from fsfwgen.utility.sql_writer import SqlWriter
|
||||||
|
|
||||||
|
|
||||||
|
LOGGER = get_console_logger()
|
||||||
|
|
||||||
|
|
||||||
class ObjectDefinitionParser(FileParser):
|
class ObjectDefinitionParser(FileParser):
|
||||||
|
|
||||||
def __init__(self, file_list: list):
|
def __init__(self, file_list: list):
|
||||||
@ -35,7 +39,7 @@ 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")
|
outputfile = open(filename, "w")
|
||||||
print('ObjectParser: Writing translation file ' + filename)
|
LOGGER.info('ObjectParser: Writing translation file ' + filename)
|
||||||
definitions = ""
|
definitions = ""
|
||||||
function = "const char* translateObject(object_id_t object) " \
|
function = "const char* translateObject(object_id_t object) " \
|
||||||
"{\n\tswitch( (object & 0xFFFFFFFF) ) {\n"
|
"{\n\tswitch( (object & 0xFFFFFFFF) ) {\n"
|
||||||
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
colorlog>=5.0.0
|
@ -1,17 +1,23 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
|
from fsfwgen.core import get_console_logger
|
||||||
|
LOGGER = get_console_logger()
|
||||||
|
|
||||||
|
|
||||||
def copy_file(filename: str, destination: str = "", delete_existing_file: bool = False):
|
def copy_file(filename: str, destination: str = "", delete_existing_file: bool = False):
|
||||||
if os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
|
LOGGER.warning(f'File {filename} does not exist')
|
||||||
|
return
|
||||||
|
if not os.path.exists(destination):
|
||||||
|
LOGGER.warning(f'Destination directory {destination} does not exist')
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
shutil.copy2(filename, destination)
|
shutil.copy2(filename, destination)
|
||||||
except FileNotFoundError as error:
|
except FileNotFoundError:
|
||||||
print("copy_file: File not found!")
|
LOGGER.exception('File not found!')
|
||||||
print(error)
|
|
||||||
except shutil.SameFileError:
|
except shutil.SameFileError:
|
||||||
print("copy_file: Source and destination are the same!")
|
LOGGER.exception('Source and destination are the same!')
|
||||||
|
|
||||||
|
|
||||||
def move_file(file_name: str, destination: str = ""):
|
def move_file(file_name: str, destination: str = ""):
|
||||||
@ -25,9 +31,7 @@ def move_file(file_name: str, destination: str = ""):
|
|||||||
shutil.copy2(file_name, destination)
|
shutil.copy2(file_name, destination)
|
||||||
os.remove(file_name)
|
os.remove(file_name)
|
||||||
return
|
return
|
||||||
except FileNotFoundError as error:
|
except FileNotFoundError:
|
||||||
print(error)
|
LOGGER.exception('File not found!')
|
||||||
print('move_file: File not found')
|
except shutil.SameFileError:
|
||||||
except shutil.SameFileError as error:
|
LOGGER.exception('Source and destination are the same!')
|
||||||
print(error)
|
|
||||||
print('move_file: Files are the same!')
|
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
from fsfwgen.core import get_console_logger
|
||||||
|
|
||||||
|
LOGGER = get_console_logger()
|
||||||
|
|
||||||
|
|
||||||
class SqlWriter:
|
class SqlWriter:
|
||||||
def __init__(self, db_filename: str):
|
def __init__(self, db_filename: str):
|
||||||
@ -7,11 +11,11 @@ class SqlWriter:
|
|||||||
self.conn = sqlite3.connect(self.filename)
|
self.conn = sqlite3.connect(self.filename)
|
||||||
|
|
||||||
def open(self, sql_creation_command: str):
|
def open(self, sql_creation_command: str):
|
||||||
print("SQL Writer: Opening " + self.filename)
|
LOGGER.info(f'SQL Writer: Opening {self.filename}')
|
||||||
self.conn.execute(sql_creation_command)
|
self.conn.execute(sql_creation_command)
|
||||||
|
|
||||||
def delete(self, sql_deletion_command):
|
def delete(self, sql_deletion_command):
|
||||||
print("SQL Writer: Deleting SQL table")
|
LOGGER.info("SQL Writer: Deleting SQL table")
|
||||||
self.conn.execute(sql_deletion_command)
|
self.conn.execute(sql_deletion_command)
|
||||||
|
|
||||||
def write_entries(self, sql_insertion_command, current_entry):
|
def write_entries(self, sql_insertion_command, current_entry):
|
||||||
@ -20,13 +24,15 @@ class SqlWriter:
|
|||||||
return cur.lastrowid
|
return cur.lastrowid
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
print("SQL Writer: Commiting SQL table")
|
LOGGER.info("SQL Writer: Commiting SQL table")
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.conn.close()
|
self.conn.close()
|
||||||
|
|
||||||
def sql_writing_helper(self, creation_cmd, insertion_cmd, mib_table: dict, deletion_cmd: str=""):
|
def sql_writing_helper(
|
||||||
|
self, creation_cmd, insertion_cmd, mib_table: dict, deletion_cmd: str = ""
|
||||||
|
):
|
||||||
if deletion_cmd != "":
|
if deletion_cmd != "":
|
||||||
self.delete(deletion_cmd)
|
self.delete(deletion_cmd)
|
||||||
self.open(creation_cmd)
|
self.open(creation_cmd)
|
||||||
|
Loading…
Reference in New Issue
Block a user