add changelog and removing logging module
This commit is contained in:
parent
b1e5a2d40a
commit
66e31885a7
11
CHANGELOG.md
Normal file
11
CHANGELOG.md
Normal file
@ -0,0 +1,11 @@
|
||||
Change Log
|
||||
=======
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
# [unreleased]
|
||||
|
||||
- Remove `logging` module and move to more pythonic logging usage.
|
@ -1,5 +1,5 @@
|
||||
__version__ = "0.2.0"
|
||||
|
||||
VERSION_MAJOR = 0
|
||||
VERSION_MINOR = 1
|
||||
VERSION_REVISION = 0
|
||||
|
||||
__version__ = "0.1.0"
|
||||
|
@ -4,9 +4,8 @@ from pathlib import Path
|
||||
from typing import List, Optional, Dict
|
||||
|
||||
from fsfwgen.parserbase.parser import FileParser
|
||||
from fsfwgen.logging import get_console_logger
|
||||
|
||||
LOGGER = get_console_logger()
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
FSFW_EVENT_HEADER_INCLUDE = '#include "fsfw/events/Event.h"'
|
||||
@ -167,8 +166,8 @@ class EventParser(FileParser):
|
||||
if self.obsw_root_path is not None:
|
||||
file_name = file_name.relative_to(self.obsw_root_path)
|
||||
if self.mib_table.get(full_id) is not None:
|
||||
LOGGER.warning(f"Duplicate event ID {full_id} detected")
|
||||
LOGGER.info(
|
||||
_LOGGER.warning(f"Duplicate event ID {full_id} detected")
|
||||
_LOGGER.info(
|
||||
f"Name: {self.mib_table.get(full_id).name}| "
|
||||
f"Description: {self.mib_table.get(full_id).description}"
|
||||
)
|
||||
|
@ -1,97 +0,0 @@
|
||||
import logging
|
||||
import sys
|
||||
from typing import Optional
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
|
||||
FSFWGEN_LOGGER_NAME = "fsfwgen"
|
||||
__CONSOLE_LOGGER_SET_UP: Optional[logging.Logger] = None
|
||||
|
||||
|
||||
def get_console_logger() -> logging.Logger:
|
||||
global __CONSOLE_LOGGER_SET_UP
|
||||
"""Get the global console logger instance. Error logs will still be saved to an error file
|
||||
"""
|
||||
logger = logging.getLogger(FSFWGEN_LOGGER_NAME)
|
||||
if not __CONSOLE_LOGGER_SET_UP:
|
||||
__CONSOLE_LOGGER_SET_UP = True
|
||||
__setup_tmtc_console_logger()
|
||||
return logger
|
||||
|
||||
|
||||
def init_console_logger(log_level: int = logging.INFO) -> logging.Logger:
|
||||
global __CONSOLE_LOGGER_SET_UP
|
||||
if not __CONSOLE_LOGGER_SET_UP:
|
||||
__CONSOLE_LOGGER_SET_UP = True
|
||||
return __setup_tmtc_console_logger(log_level=log_level)
|
||||
return get_console_logger()
|
||||
|
||||
|
||||
def __setup_tmtc_console_logger(log_level: int = logging.INFO) -> logging.Logger:
|
||||
"""Sets the LOGGER object which will be used globally. This needs to be called before
|
||||
using the logger.
|
||||
:return: Returns the instance of the global logger
|
||||
"""
|
||||
logger = logging.getLogger(FSFWGEN_LOGGER_NAME)
|
||||
# Use colorlog for now because it allows more flexibility and custom messages
|
||||
# for different levels
|
||||
set_up_colorlog_logger(logger=logger)
|
||||
logger.setLevel(level=log_level)
|
||||
# set_up_coloredlogs_logger(logger=logger)
|
||||
return logger
|
||||
|
||||
|
||||
# Custom formatter. Allows different strings for info, error and debug output
|
||||
class CustomTmtccmdFormatter(ColoredFormatter):
|
||||
def __init__(
|
||||
self, info_fmt: str, dbg_fmt: str, err_fmt: str, warn_fmt: str, datefmt=None
|
||||
):
|
||||
self.err_fmt = err_fmt
|
||||
self.info_fmt = info_fmt
|
||||
self.dbg_fmt = dbg_fmt
|
||||
self.warn_fmt = warn_fmt
|
||||
super().__init__(fmt="%(levelno)d: %(msg)s", datefmt=datefmt, style="%")
|
||||
|
||||
def format(self, record):
|
||||
|
||||
# Save the original format configured by the user
|
||||
# when the logger formatter was instantiated
|
||||
format_orig = self._style._fmt
|
||||
|
||||
# Replace the original format with one customized by logging level
|
||||
if record.levelno == logging.DEBUG:
|
||||
self._style._fmt = self.dbg_fmt
|
||||
|
||||
elif record.levelno == logging.INFO:
|
||||
self._style._fmt = self.info_fmt
|
||||
|
||||
elif record.levelno == logging.ERROR:
|
||||
self._style._fmt = self.err_fmt
|
||||
|
||||
elif record.levelno == logging.WARNING:
|
||||
self._style._fmt = self.warn_fmt
|
||||
|
||||
# Call the original formatter class to do the grunt work
|
||||
result = logging.Formatter.format(self, record)
|
||||
|
||||
# Restore the original format configured by the user
|
||||
self._style._fmt = format_orig
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def set_up_colorlog_logger(logger: logging.Logger):
|
||||
from colorlog import StreamHandler
|
||||
|
||||
dbg_fmt = "%(log_color)s%(levelname)-8s %(cyan)s [%(filename)s:%(lineno)d] %(reset)s%(message)s"
|
||||
custom_formatter = CustomTmtccmdFormatter(
|
||||
info_fmt="%(log_color)s%(levelname)-8s %(cyan)s %(reset)s%(message)s",
|
||||
dbg_fmt=dbg_fmt,
|
||||
err_fmt=dbg_fmt,
|
||||
warn_fmt=dbg_fmt,
|
||||
)
|
||||
|
||||
console_handler = StreamHandler(stream=sys.stdout)
|
||||
console_handler.setFormatter(custom_formatter)
|
||||
logger.addHandler(console_handler)
|
||||
logger.propagate = False
|
@ -1,13 +1,13 @@
|
||||
import logging
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from fsfwgen.parserbase.parser import FileParser
|
||||
from fsfwgen.logging import get_console_logger
|
||||
from fsfwgen.utility.sql_writer import SqlWriter
|
||||
|
||||
|
||||
LOGGER = get_console_logger()
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ObjectDefinitionParser(FileParser):
|
||||
@ -45,7 +45,7 @@ def export_object_file(filename, object_list, file_separator: str = ","):
|
||||
|
||||
def write_translation_file(filename: str, list_of_entries, date_string_full: str):
|
||||
with open(filename, "w") as out:
|
||||
LOGGER.info("ObjectParser: Writing translation file " + filename)
|
||||
_LOGGER.info("ObjectParser: Writing translation file " + filename)
|
||||
definitions = ""
|
||||
function = (
|
||||
"const char *translateObject(object_id_t object) "
|
||||
|
@ -1,13 +1,12 @@
|
||||
"""Generic File Parser class
|
||||
Used by parse header files. Implemented as class in case header parser becomes more complex
|
||||
"""
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Union, List
|
||||
|
||||
from fsfwgen.logging import get_console_logger
|
||||
from logging import DEBUG
|
||||
|
||||
LOGGER = get_console_logger()
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
@ -24,7 +23,7 @@ class FileListParser:
|
||||
elif isinstance(directory_list_or_name, List):
|
||||
self.directory_list.extend(directory_list_or_name)
|
||||
else:
|
||||
LOGGER.warning(
|
||||
_LOGGER.warning(
|
||||
"Header Parser: Passed directory list is not a header name or list of header names"
|
||||
)
|
||||
self.header_files = []
|
||||
|
@ -16,7 +16,7 @@ import re
|
||||
from abc import abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import Dict, List
|
||||
from enum import Enum, auto
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class VerbosityLevels(enum.Enum):
|
||||
|
@ -1,14 +1,14 @@
|
||||
import logging
|
||||
import re
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import List, Tuple, Optional, Dict, Union
|
||||
from typing import List, Optional, Dict
|
||||
|
||||
from fsfwgen.parserbase.parser import FileParser, VerbosityLevels
|
||||
from fsfwgen.utility.printer import PrettyPrinter
|
||||
from fsfwgen.logging import get_console_logger
|
||||
|
||||
LOGGER = get_console_logger()
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# Intermediate solution
|
||||
MAX_STRING_LEN = 80
|
||||
@ -342,10 +342,10 @@ class ReturnValueParser(FileParser):
|
||||
if returnvalue_match:
|
||||
description = self.__search_for_descrip_string(moving_window=moving_window)
|
||||
if number_match == INVALID_IF_ID:
|
||||
LOGGER.warning(f"Invalid number match detected for file {file_name}")
|
||||
LOGGER.warning(f"Match groups:")
|
||||
_LOGGER.warning(f"Invalid number match detected for file {file_name}")
|
||||
_LOGGER.warning(f"Match groups:")
|
||||
for group in returnvalue_match.groups():
|
||||
LOGGER.info(group)
|
||||
_LOGGER.info(group)
|
||||
self.__handle_returnvalue_match(
|
||||
name_match=returnvalue_match.group(1),
|
||||
file_name=file_name,
|
||||
@ -398,14 +398,14 @@ class ReturnValueParser(FileParser):
|
||||
Returns whether the interface ID was found successfully in the IF ID header files
|
||||
"""
|
||||
if self.get_verbosity() == VerbosityLevels.DEBUG:
|
||||
LOGGER.info(
|
||||
_LOGGER.info(
|
||||
f"Interface ID {interface_id_match.group(1)} found in {file_name}"
|
||||
)
|
||||
if_id_entry = self.interfaces.get(interface_id_match.group(1))
|
||||
if if_id_entry is not None:
|
||||
self.current_interface_id_entries["ID"] = if_id_entry[0]
|
||||
else:
|
||||
LOGGER.warning(
|
||||
_LOGGER.warning(
|
||||
f"Interface ID {interface_id_match.group(1)} not found in IF ID dictionary"
|
||||
)
|
||||
return False
|
||||
@ -415,7 +415,7 @@ class ReturnValueParser(FileParser):
|
||||
self.current_interface_id_entries["FullName"] = interface_id_match.group(1)
|
||||
if self.get_verbosity() == VerbosityLevels.DEBUG:
|
||||
current_id = self.current_interface_id_entries["ID"]
|
||||
LOGGER.info(f"Current ID: {current_id}")
|
||||
_LOGGER.info(f"Current ID: {current_id}")
|
||||
return True
|
||||
|
||||
def __handle_returnvalue_match(
|
||||
@ -479,7 +479,7 @@ class ReturnValueParser(FileParser):
|
||||
my_str = first_part + "_" + self.convert(second_part)
|
||||
if len(my_str) > max_string_len:
|
||||
if print_truncated_entries:
|
||||
LOGGER.warning(f"Entry {my_str} too long. Will truncate.")
|
||||
_LOGGER.warning(f"Entry {my_str} too long. Will truncate.")
|
||||
my_str = my_str[0:max_string_len]
|
||||
else:
|
||||
# print("Entry: " + myStr + " is all right.")
|
||||
@ -509,5 +509,5 @@ def get_number_from_dec_or_hex_str(a_string):
|
||||
return int(a_string, 16)
|
||||
if a_string.isdigit():
|
||||
return int(a_string)
|
||||
LOGGER.warning(f"Illegal number representation: {a_string}")
|
||||
_LOGGER.warning(f"Illegal number representation: {a_string}")
|
||||
return 0
|
||||
|
@ -1,31 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
import shutil
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from fsfwgen.logging import get_console_logger
|
||||
|
||||
LOGGER = get_console_logger()
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def copy_file(
|
||||
filename: Path, destination: Path = "", delete_existing_file: bool = False
|
||||
):
|
||||
if not os.path.exists(filename):
|
||||
LOGGER.warning(f"File {filename} does not exist")
|
||||
_LOGGER.warning(f"File {filename} does not exist")
|
||||
return
|
||||
if not os.path.isdir(destination) and os.path.exists(destination):
|
||||
if delete_existing_file:
|
||||
os.remove(destination)
|
||||
else:
|
||||
LOGGER.warning(f"Destination file {destination} already exists")
|
||||
_LOGGER.warning(f"Destination file {destination} already exists")
|
||||
return
|
||||
try:
|
||||
shutil.copy2(src=filename, dst=destination)
|
||||
except FileNotFoundError:
|
||||
LOGGER.exception("File not found!")
|
||||
_LOGGER.exception("File not found!")
|
||||
except shutil.SameFileError:
|
||||
LOGGER.exception("Source and destination are the same!")
|
||||
_LOGGER.exception("Source and destination are the same!")
|
||||
|
||||
|
||||
def move_file(file_name: Path, destination: Path = ""):
|
||||
@ -40,6 +40,6 @@ def move_file(file_name: Path, destination: Path = ""):
|
||||
os.remove(file_name)
|
||||
return
|
||||
except FileNotFoundError:
|
||||
LOGGER.exception("File not found!")
|
||||
_LOGGER.exception("File not found!")
|
||||
except shutil.SameFileError:
|
||||
LOGGER.exception("Source and destination are the same!")
|
||||
_LOGGER.exception("Source and destination are the same!")
|
||||
|
@ -1,8 +1,7 @@
|
||||
import logging
|
||||
import sqlite3
|
||||
|
||||
from fsfwgen.logging import get_console_logger
|
||||
|
||||
LOGGER = get_console_logger()
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SqlWriter:
|
||||
@ -11,11 +10,11 @@ class SqlWriter:
|
||||
self.conn = sqlite3.connect(self.filename)
|
||||
|
||||
def open(self, sql_creation_command: str):
|
||||
LOGGER.info(f"SQL Writer: Opening {self.filename}")
|
||||
_LOGGER.info(f"SQL Writer: Opening {self.filename}")
|
||||
self.conn.execute(sql_creation_command)
|
||||
|
||||
def delete(self, sql_deletion_command):
|
||||
LOGGER.info("SQL Writer: Deleting SQL table")
|
||||
_LOGGER.info("SQL Writer: Deleting SQL table")
|
||||
self.conn.execute(sql_deletion_command)
|
||||
|
||||
def write_entries(self, sql_insertion_command, current_entry):
|
||||
@ -24,7 +23,7 @@ class SqlWriter:
|
||||
return cur.lastrowid
|
||||
|
||||
def commit(self):
|
||||
LOGGER.info("SQL Writer: Commiting SQL table")
|
||||
_LOGGER.info("SQL Writer: Commiting SQL table")
|
||||
self.conn.commit()
|
||||
|
||||
def close(self):
|
||||
|
Loading…
Reference in New Issue
Block a user