Adding new classes, todo: fix jsonrpc module

This commit is contained in:
adator
2025-08-19 03:06:56 +02:00
parent a15a5b1026
commit 4c327940dd
9 changed files with 373 additions and 450 deletions

View File

@@ -3,13 +3,13 @@ from sys import exit
from os import sep
from typing import Union
from core.definition import MConfig
from logging import Logger
class Configuration:
def __init__(self) -> None:
def __init__(self, logs: Logger) -> None:
self.Logs = logs
self.ConfigObject: MConfig = self.__load_service_configuration()
return None
@@ -22,18 +22,18 @@ class Configuration:
return configuration
except FileNotFoundError as fe:
print(f'FileNotFound: {fe}')
print('Configuration file not found please create config/configuration.json')
self.Logs.error(f'FileNotFound: {fe}')
self.Logs.error('Configuration file not found please create config/configuration.json')
exit(0)
except KeyError as ke:
print(f'Key Error: {ke}')
print('The key must be defined in core/configuration.json')
self.Logs.error(f'Key Error: {ke}')
self.Logs.error('The key must be defined in core/configuration.json')
def __load_service_configuration(self) -> MConfig:
try:
import_config = self.__load_json_service_configuration()
Model_keys = MConfig().__dict__
Model_keys = MConfig().to_dict()
model_key_list: list = []
json_config_key_list: list = []
@@ -46,12 +46,13 @@ class Configuration:
for json_conf in json_config_key_list:
if not json_conf in model_key_list:
import_config.pop(json_conf, None)
print(f"\!/ The key {json_conf} is not expected, it has been removed from the system ! please remove it from configuration.json file \!/")
self.Logs.warning(f"[!] The key {json_conf} is not expected, it has been removed from the system ! please remove it from configuration.json file [!]")
ConfigObject: MConfig = MConfig(
**import_config
)
return ConfigObject
except TypeError as te:
print(te)
self.Logs.error(te)

View File

@@ -233,9 +233,10 @@ class Irc:
self.Logs.warning('--* Waiting for socket to close ...')
# Reload configuration
self.Loader.Logs = self.Loader.LoggingModule.ServiceLogging().get_logger()
self.Logs.debug('Reloading configuration')
self.Config = self.Loader.ConfModule.Configuration().ConfigObject
self.Base = self.Loader.BaseModule.Base(self.Config, self.Settings)
self.Config = self.Loader.ConfModule.Configuration(self.Logs).ConfigObject
self.Base = self.Loader.BaseModule.Base(self.Loader)
self.Protocol = Protocol(self.Config.SERVEUR_PROTOCOL, ircInstance).Protocol
self.init_service_user()
@@ -1488,18 +1489,23 @@ class Irc:
self.User.UID_DB.clear() # Clear User Object
self.Channel.UID_CHANNEL_DB.clear() # Clear Channel Object
self.Base.delete_logger(self.Config.LOGGING_NAME)
self.Base.garbage_collector_thread()
self.Protocol.send_squit(server_id=self.Config.SERVEUR_ID, server_link=self.Config.SERVEUR_LINK, reason=final_reason)
self.Logs.info(f'Redémarrage du server {dnickname}')
self.loaded_classes.clear()
self.Config.DEFENDER_RESTART = 1 # Set restart status to 1 saying that the service will restart
self.Config.DEFENDER_INIT = 1 # set init to 1 saying that the service will be re initiated
self.Loader.ServiceLogging.remove_logger()
case 'rehash':
self.Loader.ServiceLogging.remove_logger()
self.Loader.ServiceLogging = self.Loader.LoggingModule.ServiceLogging()
self.Loader.Logs = self.Loader.ServiceLogging.get_logger()
need_a_restart = ["SERVEUR_ID"]
restart_flag = False
Config_bakcup = self.Config.__dict__.copy()
Config_bakcup = self.Config.to_dict().copy()
serveur_id = self.Config.SERVEUR_ID
service_nickname = self.Config.SERVICE_NICKNAME
hsid = self.Config.HSID
@@ -1519,7 +1525,7 @@ class Irc:
importlib.reload(mod_definition)
importlib.reload(mod_config)
self.Config = self.Loader.ConfModule.Configuration().ConfigObject
self.Config = self.Loader.ConfModule.Configuration(self.Loader.Logs).ConfigObject
self.Config.HSID = hsid
self.Config.DEFENDER_INIT = defender_init
self.Config.DEFENDER_RESTART = defender_restart
@@ -1529,7 +1535,7 @@ class Irc:
importlib.reload(mod_base)
conf_bkp_dict: dict = Config_bakcup
config_dict: dict = self.Config.__dict__
config_dict: dict = self.Config.to_dict()
for key, value in conf_bkp_dict.items():
if config_dict[key] != value and key != 'COLORS':
@@ -1548,9 +1554,6 @@ class Irc:
self.Config.SERVEUR_ID = serveur_id
self.Protocol.send_priv_msg(nick_from=self.Config.SERVICE_NICKNAME, msg='You need to restart defender !', channel=self.Config.SERVICE_CHANLOG)
self.Loader.ServiceLogging.remove_logger()
self.Loader.ServiceLogging = self.Loader.LoggingModule.ServiceLogging()
self.Loader.Logs = self.Loader.ServiceLogging.get_logger()
self.Base = self.Loader.BaseModule.Base(self.Loader)
importlib.reload(mod_unreal6)

View File

@@ -28,7 +28,7 @@ class Loader:
self.Settings: settings.Settings = settings.Settings()
self.Config: df.MConfig = self.ConfModule.Configuration().ConfigObject
self.Config: df.MConfig = self.ConfModule.Configuration(self.Logs).ConfigObject
self.Base: base_module.Base = self.BaseModule.Base(self)

View File

@@ -1,5 +1,6 @@
import logging
from os import path, makedirs, sep
from typing import Optional
class ServiceLogging:
@@ -25,10 +26,13 @@ class ServiceLogging:
return logs_obj
def remove_logger(self) -> None:
def remove_logger(self, logger_name: Optional[str] = None) -> None:
if logger_name is None:
logger_name = self.LOGGING_NAME
# Récupérer le logger
logger = logging.getLogger(self.LOGGING_NAME)
logger = logging.getLogger(logger_name)
# Retirer tous les gestionnaires du logger et les fermer
for handler in logger.handlers[:]: # Utiliser une copie de la liste
@@ -37,7 +41,7 @@ class ServiceLogging:
handler.close()
# Supprimer le logger du dictionnaire global
logging.Logger.manager.loggerDict.pop(self.LOGGING_NAME, None)
logging.Logger.manager.loggerDict.pop(logger_name, None)
return None