Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5767533668 | ||
|
|
24798f19ca | ||
|
|
26f8249187 | ||
|
|
dcefa564da | ||
|
|
edd35dccea |
@@ -1,7 +1,7 @@
|
|||||||
# MARK: Project info
|
# MARK: Project info
|
||||||
[project]
|
[project]
|
||||||
name = "corelibs"
|
name = "corelibs"
|
||||||
version = "0.15.0"
|
version = "0.17.0"
|
||||||
description = "Collection of utils for Python scripts"
|
description = "Collection of utils for Python scripts"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.13"
|
||||||
|
|||||||
@@ -6,28 +6,39 @@ import traceback
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
def traceback_call_str(start: int = 2, depth: int = 1):
|
def call_stack(
|
||||||
|
start: int = 0,
|
||||||
|
skip_last: int = -1,
|
||||||
|
separator: str = ' -> ',
|
||||||
|
reset_start_if_empty: bool = False
|
||||||
|
) -> str:
|
||||||
"""
|
"""
|
||||||
get the trace for the last entry
|
get the trace for the last entry
|
||||||
|
|
||||||
Keyword Arguments:
|
Keyword Arguments:
|
||||||
start {int} -- _description_ (default: {2})
|
start {int} -- start, if too might output will empty until reset_start_if_empty is set (default: {0})
|
||||||
depth {int} -- _description_ (default: {1})
|
skip_last {int} -- how many of the last are skipped, defaults to -1 for current method (default: {-1})
|
||||||
|
seperator {str} -- add stack separator, if empty defaults to ' -> ' (default: { -> })
|
||||||
|
reset_start_if_empty {bool} -- if no stack returned because of too high start,
|
||||||
|
reset to 0 for full read (default: {False})
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
_type_ -- _description_
|
str -- _description_
|
||||||
"""
|
"""
|
||||||
# can't have more than in the stack for depth
|
# stack = traceback.extract_stack()[start:depth]
|
||||||
depth = min(depth, start)
|
# how many of the last entries we skip (so we do not get self), default is -1
|
||||||
depth = start - depth
|
# start cannot be negative
|
||||||
# 0 is full stack length from start
|
if skip_last > 0:
|
||||||
if depth == 0:
|
skip_last = skip_last * -1
|
||||||
stack = traceback.extract_stack()[-start:]
|
stack = traceback.extract_stack()
|
||||||
else:
|
__stack = stack[start:skip_last]
|
||||||
stack = traceback.extract_stack()[-start:-depth]
|
# start possible to high, reset start to 0
|
||||||
return ' -> '.join(
|
if not __stack and reset_start_if_empty:
|
||||||
f"{os.path.basename(f.filename)}:{f.name}:{f.lineno}"
|
start = 0
|
||||||
for f in stack
|
__stack = stack[start:skip_last]
|
||||||
)
|
if not separator:
|
||||||
|
separator = ' -> '
|
||||||
|
# print(f"* HERE: {dump_data(stack)}")
|
||||||
|
return f"{separator}".join(f"{os.path.basename(f.filename)}:{f.name}:{f.lineno}" for f in __stack)
|
||||||
|
|
||||||
# __END__
|
# __END__
|
||||||
|
|||||||
23
src/corelibs/exceptions/csv_exceptions.py
Normal file
23
src/corelibs/exceptions/csv_exceptions.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
"""
|
||||||
|
Exceptions for csv file reading and processing
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class NoCsvReader(Exception):
|
||||||
|
"""
|
||||||
|
CSV reader is none
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class CsvHeaderDataMissing(Exception):
|
||||||
|
"""
|
||||||
|
The csv reader returned None as headers, the header column in the csv file is missing
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class CompulsoryCsvHeaderCheckFailed(Exception):
|
||||||
|
"""
|
||||||
|
raise if the header is not matching to the excpeted values
|
||||||
|
"""
|
||||||
|
|
||||||
|
# __END__
|
||||||
@@ -12,7 +12,7 @@ from pathlib import Path
|
|||||||
from typing import MutableMapping, TextIO, TypedDict, Any, TYPE_CHECKING, cast
|
from typing import MutableMapping, TextIO, TypedDict, Any, TYPE_CHECKING, cast
|
||||||
from corelibs.logging_handling.logging_level_handling.logging_level import LoggingLevel
|
from corelibs.logging_handling.logging_level_handling.logging_level import LoggingLevel
|
||||||
from corelibs.string_handling.text_colors import Colors
|
from corelibs.string_handling.text_colors import Colors
|
||||||
from corelibs.debug_handling.debug_helpers import traceback_call_str
|
from corelibs.debug_handling.debug_helpers import call_stack
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from multiprocessing import Queue
|
from multiprocessing import Queue
|
||||||
@@ -76,6 +76,7 @@ class CustomConsoleFormatter(logging.Formatter):
|
|||||||
|
|
||||||
# TODO: add custom handlers for stack_trace, if not set fill with %(filename)s:%(funcName)s:%(lineno)d
|
# TODO: add custom handlers for stack_trace, if not set fill with %(filename)s:%(funcName)s:%(lineno)d
|
||||||
# hasattr(record, 'stack_trace')
|
# hasattr(record, 'stack_trace')
|
||||||
|
# also for something like "context" where we add an array of anything to a message
|
||||||
|
|
||||||
|
|
||||||
class CustomHandlerFilter(logging.Filter):
|
class CustomHandlerFilter(logging.Filter):
|
||||||
@@ -130,7 +131,7 @@ class LogParent:
|
|||||||
raise ValueError('Logger is not yet initialized')
|
raise ValueError('Logger is not yet initialized')
|
||||||
if extra is None:
|
if extra is None:
|
||||||
extra = {}
|
extra = {}
|
||||||
extra['stack_trace'] = traceback_call_str(start=3)
|
extra['stack_trace'] = call_stack(skip_last=2)
|
||||||
self.logger.log(level, msg, *args, extra=extra, stacklevel=2)
|
self.logger.log(level, msg, *args, extra=extra, stacklevel=2)
|
||||||
|
|
||||||
# MARK: DEBUG 10
|
# MARK: DEBUG 10
|
||||||
@@ -140,7 +141,7 @@ class LogParent:
|
|||||||
raise ValueError('Logger is not yet initialized')
|
raise ValueError('Logger is not yet initialized')
|
||||||
if extra is None:
|
if extra is None:
|
||||||
extra = {}
|
extra = {}
|
||||||
extra['stack_trace'] = traceback_call_str(start=3)
|
extra['stack_trace'] = call_stack(skip_last=2)
|
||||||
self.logger.debug(msg, *args, extra=extra, stacklevel=2)
|
self.logger.debug(msg, *args, extra=extra, stacklevel=2)
|
||||||
|
|
||||||
# MARK: INFO 20
|
# MARK: INFO 20
|
||||||
@@ -150,7 +151,7 @@ class LogParent:
|
|||||||
raise ValueError('Logger is not yet initialized')
|
raise ValueError('Logger is not yet initialized')
|
||||||
if extra is None:
|
if extra is None:
|
||||||
extra = {}
|
extra = {}
|
||||||
extra['stack_trace'] = traceback_call_str(start=3)
|
extra['stack_trace'] = call_stack(skip_last=2)
|
||||||
self.logger.info(msg, *args, extra=extra, stacklevel=2)
|
self.logger.info(msg, *args, extra=extra, stacklevel=2)
|
||||||
|
|
||||||
# MARK: WARNING 30
|
# MARK: WARNING 30
|
||||||
@@ -160,7 +161,7 @@ class LogParent:
|
|||||||
raise ValueError('Logger is not yet initialized')
|
raise ValueError('Logger is not yet initialized')
|
||||||
if extra is None:
|
if extra is None:
|
||||||
extra = {}
|
extra = {}
|
||||||
extra['stack_trace'] = traceback_call_str(start=3)
|
extra['stack_trace'] = call_stack(skip_last=2)
|
||||||
self.logger.warning(msg, *args, extra=extra, stacklevel=2)
|
self.logger.warning(msg, *args, extra=extra, stacklevel=2)
|
||||||
|
|
||||||
# MARK: ERROR 40
|
# MARK: ERROR 40
|
||||||
@@ -170,7 +171,7 @@ class LogParent:
|
|||||||
raise ValueError('Logger is not yet initialized')
|
raise ValueError('Logger is not yet initialized')
|
||||||
if extra is None:
|
if extra is None:
|
||||||
extra = {}
|
extra = {}
|
||||||
extra['stack_trace'] = traceback_call_str(start=3)
|
extra['stack_trace'] = call_stack(skip_last=2)
|
||||||
self.logger.error(msg, *args, extra=extra, stacklevel=2)
|
self.logger.error(msg, *args, extra=extra, stacklevel=2)
|
||||||
|
|
||||||
# MARK: CRITICAL 50
|
# MARK: CRITICAL 50
|
||||||
@@ -180,7 +181,7 @@ class LogParent:
|
|||||||
raise ValueError('Logger is not yet initialized')
|
raise ValueError('Logger is not yet initialized')
|
||||||
if extra is None:
|
if extra is None:
|
||||||
extra = {}
|
extra = {}
|
||||||
extra['stack_trace'] = traceback_call_str(start=3)
|
extra['stack_trace'] = call_stack(skip_last=2)
|
||||||
self.logger.critical(msg, *args, extra=extra, stacklevel=2)
|
self.logger.critical(msg, *args, extra=extra, stacklevel=2)
|
||||||
|
|
||||||
# MARK: ALERT 55
|
# MARK: ALERT 55
|
||||||
@@ -191,7 +192,7 @@ class LogParent:
|
|||||||
# extra_dict = dict(extra)
|
# extra_dict = dict(extra)
|
||||||
if extra is None:
|
if extra is None:
|
||||||
extra = {}
|
extra = {}
|
||||||
extra['stack_trace'] = traceback_call_str(start=3)
|
extra['stack_trace'] = call_stack(skip_last=2)
|
||||||
self.logger.log(LoggingLevel.ALERT.value, msg, *args, extra=extra, stacklevel=2)
|
self.logger.log(LoggingLevel.ALERT.value, msg, *args, extra=extra, stacklevel=2)
|
||||||
|
|
||||||
# MARK: EMERGECNY: 60
|
# MARK: EMERGECNY: 60
|
||||||
@@ -201,7 +202,7 @@ class LogParent:
|
|||||||
raise ValueError('Logger is not yet initialized')
|
raise ValueError('Logger is not yet initialized')
|
||||||
if extra is None:
|
if extra is None:
|
||||||
extra = {}
|
extra = {}
|
||||||
extra['stack_trace'] = traceback_call_str(start=3)
|
extra['stack_trace'] = call_stack(skip_last=2)
|
||||||
self.logger.log(LoggingLevel.EMERGENCY.value, msg, *args, extra=extra, stacklevel=2)
|
self.logger.log(LoggingLevel.EMERGENCY.value, msg, *args, extra=extra, stacklevel=2)
|
||||||
|
|
||||||
# MARK: EXCEPTION: 70
|
# MARK: EXCEPTION: 70
|
||||||
@@ -223,7 +224,7 @@ class LogParent:
|
|||||||
raise ValueError('Logger is not yet initialized')
|
raise ValueError('Logger is not yet initialized')
|
||||||
if extra is None:
|
if extra is None:
|
||||||
extra = {}
|
extra = {}
|
||||||
extra['stack_trace'] = traceback_call_str(start=3)
|
extra['stack_trace'] = call_stack(skip_last=2)
|
||||||
# write to console first with extra flag for filtering in file
|
# write to console first with extra flag for filtering in file
|
||||||
if log_error:
|
if log_error:
|
||||||
self.logger.log(
|
self.logger.log(
|
||||||
|
|||||||
Reference in New Issue
Block a user