improved logger and applied black formatter

This commit is contained in:
2022-02-26 13:16:09 +01:00
parent 24fa9a3fe3
commit 1be773a20f
10 changed files with 396 additions and 213 deletions

View File

@ -16,6 +16,7 @@ class FileListParser:
and parses all included header files recursively.
TODO: Filter functionality for each directory to filter out files or folders
"""
def __init__(self, directory_list_or_name: Union[str, list]):
self.directory_list = []
if isinstance(directory_list_or_name, str):
@ -28,9 +29,12 @@ class FileListParser:
)
self.header_files = []
def parse_header_files(self, search_recursively: bool = False,
printout_string: str = "Parsing header files: ",
print_current_dir: bool = False):
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:
@ -39,15 +43,21 @@ class FileListParser:
"""
print(printout_string, end="")
for directory in self.directory_list:
self.__get_header_file_list(directory, search_recursively, print_current_dir)
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 += '/'
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)
@ -58,7 +68,7 @@ class FileListParser:
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] == '_':
if match_string[0] == "." or match_string[0] == "_":
pass
else:
local_header_files.append(base_directory + entry)

View File

@ -18,13 +18,13 @@ from typing import Dict, List
class VerbosityLevels(enum.Enum):
REDUCED = 0,
REGULAR = 1,
REDUCED = (0,)
REGULAR = (1,)
DEBUG = 2
class FileParserModes(enum.Enum):
REGULAR = enum.auto(),
REGULAR = (enum.auto(),)
MOVING_WINDOW = enum.auto()
@ -38,6 +38,7 @@ class FileParser:
3. Call parse_files. Additional arguments and keyword arguments can be supplied as well and
will be passed through to the abstract function implementations.
"""
def __init__(self, file_list):
if len(file_list) == 0:
print("File list is empty !")
@ -123,8 +124,14 @@ class FileParser:
@abstractmethod
def _handle_file_parsing_moving_window(
self, file_name: str, current_line: int, moving_window_size: int, moving_window: list,
*args, **kwargs):
self,
file_name: str,
current_line: int,
moving_window_size: int,
moving_window: list,
*args,
**kwargs,
):
"""
This will be called for the MOVING_WINDOW parser mode.
:param file_name: Current file name
@ -152,7 +159,10 @@ class FileParser:
return
moving_window = [""] * moving_window_size
for line_idx, line in enumerate(all_lines):
if self.__debug_moving_window and self.__debug_moving_window_filename in file_name:
if (
self.__debug_moving_window
and self.__debug_moving_window_filename in file_name
):
print(f"Moving window pre line anaylsis line {line_idx}")
print(moving_window)
# The moving window will start with only the bottom being in the file
@ -161,15 +171,19 @@ class FileParser:
# More and more of the window is inside the file now
elif line_idx < moving_window_size:
for idx in range(line_idx, 0, -1):
moving_window[moving_window_size - 1 - idx] = \
moving_window[moving_window_size - idx]
moving_window[moving_window_size - 1 - idx] = moving_window[
moving_window_size - idx
]
moving_window[moving_window_size - 1] = line
# The full window is inside the file now.
elif line_idx >= moving_window_size:
for idx in range(moving_window_size - 1):
moving_window[idx] = moving_window[idx + 1]
moving_window[moving_window_size - 1] = line
if self.__debug_moving_window and self.__debug_moving_window_filename in file_name:
if (
self.__debug_moving_window
and self.__debug_moving_window_filename in file_name
):
print(f"Moving window post line anaylsis line {line_idx}")
print(moving_window)
self._handle_file_parsing_moving_window(
@ -178,7 +192,10 @@ class FileParser:
# Now the moving window moved past the end of the file. Sections which are outside
# the file are assigned an empty string until the window has moved out of file completely
for remaining_windows_idx in range(moving_window_size):
if self.__debug_moving_window and self.__debug_moving_window_filename in file_name:
if (
self.__debug_moving_window
and self.__debug_moving_window_filename in file_name
):
print(f"Moving window pre line analysis post EOF")
print(moving_window)
num_entries_to_clear = remaining_windows_idx + 1
@ -186,7 +203,10 @@ class FileParser:
moving_window[moving_window_size - 1 - idx_to_clear] = ""
for idx_to_reassign in range(moving_window_size - 1 - num_entries_to_clear):
moving_window[idx_to_reassign] = moving_window[idx_to_reassign + 1]
if self.__debug_moving_window and self.__debug_moving_window_filename in file_name:
if (
self.__debug_moving_window
and self.__debug_moving_window_filename in file_name
):
print(f"Moving window post line anaylsis post EOF")
print(moving_window)
pass
@ -199,16 +219,16 @@ class FileParser:
:return:
"""
try:
file = open(file_name, 'r', encoding='utf-8')
file = open(file_name, "r", encoding="utf-8")
all_lines = file.readlines()
except UnicodeDecodeError:
print("ReturnValueParser: Decoding error with file " + file_name)
file = open(file_name, 'r', encoding='cp1252')
file = open(file_name, "r", encoding="cp1252")
all_lines = file.readlines()
return all_lines
def _build_multi_line_string_generic(
self, first_line: str, moving_window: List[str]
self, first_line: str, moving_window: List[str]
) -> str:
"""This function transforms a multi line match into a one line match by searching for the
semicolon at the string end"""
@ -227,7 +247,7 @@ class FileParser:
return all_lines
def _search_for_descrip_string_generic(
self, moving_window: List[str], break_pattern: str
self, moving_window: List[str], break_pattern: str
) -> str:
current_idx = self._moving_window_center_idx - 1
# Look at the line above first
@ -236,9 +256,7 @@ class FileParser:
)
if not descrip_match:
while True:
if re.search(
break_pattern, moving_window[current_idx]
):
if re.search(break_pattern, moving_window[current_idx]):
break
descrip_match = re.search(
r"\[EXPORT][\s]*:[\s]*\[COMMENT]", moving_window[current_idx]