From 5fd149781ecba4b4ba69cae0d59d28a849635db1 Mon Sep 17 00:00:00 2001 From: Etienne Pallier Date: Fri, 13 Dec 2019 12:38:16 +0100 Subject: [PATCH] Agent lit config de base depuis objet config --- config/config_base.py | 14 +++++++++++++- src/core/pyros_django/agent/Agent.py | 36 ++++++++++++++---------------------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/config/config_base.py b/config/config_base.py index be58088..05bbfd4 100644 --- a/config/config_base.py +++ b/config/config_base.py @@ -2,6 +2,10 @@ import os +from logpyros import LogPyros + + + APP_NAME = "PYROS" # Conveniences to always have a quick reference to the @@ -10,9 +14,11 @@ ROOT_DIR = os.path.join( os.path.dirname(os.path.realpath(__file__)), os.pardir, # '..' ) -ROOT_DIR = os.path.realpath(ROOT_DIR) +ROOT_DIR = os.path.normpath(ROOT_DIR) +#ROOT_DIR = os.path.realpath(ROOT_DIR) # root directories +CONFIG_DIR = os.path.join(ROOT_DIR, "config") DOC_DIR = os.path.join(ROOT_DIR, "doc") INSTALL_DIR = os.path.join(ROOT_DIR, "install") LOG_DIR = os.path.join(ROOT_DIR, "config", "logs") @@ -20,8 +26,14 @@ SOURCE_DIR = os.path.join(ROOT_DIR, "src") # source sub-directories CELME_DIR = os.path.join(SOURCE_DIR, "core", "celme") +#PYROS_DJANGO_BASE_DIR = Path("src/core/pyros_django") # pathlib PYROS_DJANGO_DIR = os.path.join(SOURCE_DIR, "core", "pyros_django") DEVICES_DIR = os.path.join(SOURCE_DIR, "device_controller") +DEFAULT_CONFIG_FILE_NAME = "config_unit_simulunit1.xml" +#CONFIG_DIR_NAME = "config" + +# Default LOG level is INFO +PYROS_DEFAULT_GLOBAL_LOG_LEVEL = LogPyros.LOG_LEVEL_INFO # INFO SYSTEM_REBOOT_COMMAND = "sudo systemctl restart foo.service" \ No newline at end of file diff --git a/src/core/pyros_django/agent/Agent.py b/src/core/pyros_django/agent/Agent.py index 07c2d2b..667667f 100755 --- a/src/core/pyros_django/agent/Agent.py +++ b/src/core/pyros_django/agent/Agent.py @@ -238,7 +238,7 @@ class Agent: TEST_MODE = False # Default LOG level is INFO - PYROS_DEFAULT_GLOBAL_LOG_LEVEL = LogPyros.LOG_LEVEL_INFO # INFO + #PYROS_DEFAULT_GLOBAL_LOG_LEVEL = LogPyros.LOG_LEVEL_INFO # INFO # To be overriden by subclasses (empty by default, no agent specific command) AGENT_SPECIFIC_COMMANDS = [ @@ -370,9 +370,11 @@ class Agent: MODE_ACTIVE = "ACTIVE" MODE_IDLE = "IDLE" + ''' Moved to more central file : config.config_base PYROS_DJANGO_BASE_DIR = Path("src/core/pyros_django") # pathlib DEFAULT_CONFIG_FILE_NAME = "config_unit_simulunit1.xml" CONFIG_DIR_NAME = "config" + ''' # Parameters from config file # for /src/ @@ -431,35 +433,21 @@ class Agent: log_level = LogPyros.LOG_LEVEL_INFO # INFO self.log.set_global_log_level(LogPyros.LOG_LEVEL_DEBUG) if self.DEBUG_MODE else self.log.set_global_log_level(log_level) ''' - global_log_level = LogPyros.LOG_LEVEL_DEBUG if self.DEBUG_MODE else self.PYROS_DEFAULT_GLOBAL_LOG_LEVEL + #global_log_level = LogPyros.LOG_LEVEL_DEBUG if self.DEBUG_MODE else self.PYROS_DEFAULT_GLOBAL_LOG_LEVEL + global_log_level = LogPyros.LOG_LEVEL_DEBUG if self.DEBUG_MODE else config.PYROS_DEFAULT_GLOBAL_LOG_LEVEL self.log.set_global_log_level(global_log_level) ##self.printd("LOG LEVEL IS:", self.log.debug_level) self.print("LOG LEVEL IS:", self.log.get_global_log_level()) + # Est-ce bien utile ??? # New way with PathLib my_parent_abs_dir = Path(__file__).resolve().parent #TODO: on doit pouvoir faire mieux avec pathlib (sans utiliser str()) - self._path_data = str( Path( str(my_parent_abs_dir).split(str(self.PYROS_DJANGO_BASE_DIR))[0] ) / self.CONFIG_DIR_NAME ) + ##self._path_data = str( Path( str(my_parent_abs_dir).split(str(self.PYROS_DJANGO_BASE_DIR))[0] ) / self.CONFIG_DIR_NAME ) + self._path_data = config.CONFIG_DIR + #self._set_mode(self.MODE_IDLE) config_filename = self.get_config_filename(config_filename) - ''' - if not config_filename: - config_filename = self.DEFAULT_CONFIG_FILE_NAME - - # If config file name is RELATIVE (i.e. without path, just the file name) - # => give it an absolute path (and remove "src/agent/" from it) - if config_filename == os.path.basename(config_filename): - # Build abs path including current agent dir - config_filename = os.path.abspath(self.CONFIG_DIR_NAME + os.sep + config_filename) - # Remove "src/agent_name/" from abs dir : - # (1) Remove "src/core/pyros_django/" - config_filename = config_filename.replace(str(self.PYROS_DJANGO_BASE_DIR)+os.sep, os.sep) - # (2) Remove "agent_name/" - #TODO: bidouille, faire plus propre - config_filename = config_filename.replace(os.sep+"agent"+os.sep, os.sep) - config_filename = config_filename.replace(os.sep+"monitoring"+os.sep, os.sep) - config_filename = os.path.normpath(config_filename) - ''' self.printd(f"*** Config file used is={config_filename}") self.config = ConfigPyros(config_filename) if self.config.get_last_errno() != self.config.NO_ERROR: @@ -501,10 +489,13 @@ class Agent: def get_config_filename(self, config_filename: str): if not config_filename: - config_filename = self.DEFAULT_CONFIG_FILE_NAME + #config_filename = self.DEFAULT_CONFIG_FILE_NAME + config_filename = config.DEFAULT_CONFIG_FILE_NAME # If config file name is RELATIVE (i.e. without path, just the file name) # => give it an absolute path (and remove "src/agent/" from it) if config_filename == os.path.basename(config_filename): + config_filename = os.path.join(config.CONFIG_DIR, config_filename) + ''' # Build abs path including current agent dir config_filename = os.path.abspath(self.CONFIG_DIR_NAME + os.sep + config_filename) # Remove "src/agent_name/" from abs dir : @@ -514,6 +505,7 @@ class Agent: #TODO: bidouille, faire plus propre config_filename = config_filename.replace(os.sep+"agent"+os.sep, os.sep) config_filename = config_filename.replace(os.sep+"monitoring"+os.sep, os.sep) + ''' return os.path.normpath(config_filename) def __repr__(self): -- libgit2 0.21.2