mirror of
https://github.com/norohind/jubilant-system-core.git
synced 2025-06-07 10:53:05 +03:00
main.py: Fix shadowing exceptions by start parameters handling
This commit is contained in:
parent
42fdfd96ec
commit
5dadc8c1c9
41
main.py
41
main.py
@ -7,6 +7,7 @@ import signal
|
|||||||
import DB
|
import DB
|
||||||
import sys
|
import sys
|
||||||
import inspect
|
import inspect
|
||||||
|
import logging
|
||||||
|
|
||||||
logger.remove()
|
logger.remove()
|
||||||
logger.add(sys.stderr, diagnose=False, colorize=False) # Please set debug level by env variable LOGURU_LEVEL
|
logger.add(sys.stderr, diagnose=False, colorize=False) # Please set debug level by env variable LOGURU_LEVEL
|
||||||
@ -15,6 +16,26 @@ shutting_down: bool = False
|
|||||||
can_be_shutdown: bool = False
|
can_be_shutdown: bool = False
|
||||||
|
|
||||||
|
|
||||||
|
class InterceptHandler(logging.Handler):
|
||||||
|
def emit(self, record):
|
||||||
|
# Get corresponding Loguru level if it exists
|
||||||
|
try:
|
||||||
|
level = logger.level(record.levelname).name
|
||||||
|
except ValueError:
|
||||||
|
level = record.levelno
|
||||||
|
|
||||||
|
# Find caller from where originated the logged message
|
||||||
|
frame, depth = logging.currentframe(), 2
|
||||||
|
while frame.f_code.co_filename == logging.__file__:
|
||||||
|
frame = frame.f_back
|
||||||
|
depth += 1
|
||||||
|
|
||||||
|
logger.opt(depth=depth, exception=record.exc_info).log(level, record.getMessage())
|
||||||
|
|
||||||
|
|
||||||
|
# logging.basicConfig(handlers=[InterceptHandler()], level=0)
|
||||||
|
|
||||||
|
|
||||||
def shutdown_callback(sig: int, frame) -> None:
|
def shutdown_callback(sig: int, frame) -> None:
|
||||||
logger.info(f'Planning shutdown by {sig} signal')
|
logger.info(f'Planning shutdown by {sig} signal')
|
||||||
try:
|
try:
|
||||||
@ -194,26 +215,30 @@ def main():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
amount: int = int(sys.argv[3])
|
amount: int = int(sys.argv[3])
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
amount = 0
|
||||||
|
print('Amount must be integer')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
logger.info(f'Entering update amount mode, amount: {amount}')
|
logger.info(f'Entering update amount mode, amount: {amount}')
|
||||||
update(amount_to_update=amount)
|
update(amount_to_update=amount)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
except ValueError:
|
|
||||||
print('Amount must be integer')
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
elif sys.argv[2] == 'id':
|
elif sys.argv[2] == 'id':
|
||||||
# main.py update id <id: int>
|
# main.py update id <id: int>
|
||||||
try:
|
try:
|
||||||
id_for_update: int = int(sys.argv[3])
|
id_for_update: int = int(sys.argv[3])
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
id_for_update = 0
|
||||||
|
print('ID must be integer')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
logger.info(f'Entering update specified squad: {id_for_update} ID')
|
logger.info(f'Entering update specified squad: {id_for_update} ID')
|
||||||
update(squad_id=id_for_update)
|
update(squad_id=id_for_update)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
except ValueError:
|
|
||||||
print('ID must be integer')
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.info(f'Unknown argument {sys.argv[2]}')
|
logger.info(f'Unknown argument {sys.argv[2]}')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user