diff --git a/README.md b/README.md index 4ddafc0..80f81e1 100644 --- a/README.md +++ b/README.md @@ -77,14 +77,17 @@ Comment : - Restructuration du projet - phase 4 : /src/core/pyros_django/utils/celme/ => /src/core/celme/ TODO (coming) : -- Restructuration du projet - phase 5 : /devices_controller/ => réorganisation interne : - - a) sortir devices_controller/client/channel => src/channel/ - - b) rename channel/ => channels/ - - c) sortir devices_controller/client/devices_abstract/ => devices_controller/devices_abstract/ et supprimer dossier client/ - - d) rename devices_abstract/ => devices_controller_abstract_component/ - - e) create folder devices_controller/devices_controller_concrete/ - - f) migrer le dossier devices_controller/server/ => devices_controller/devices_controller_concrete/server/ - - g) rename server/ => device_simulator_common/ +- Restructuration du projet - phase 5 : /src/devices_controller/ => réorganisation interne : + - a) + - sortir /src/devices_controller/client/channel => /src/devices_controller/channel/ + - sortir /src/devices_controller/client/devices_abstract/ => /src/devices_controller/devices_abstract/ + - supprimer dossier client/ + - rename channel/ => channels/ + - rename devices_abstract/ => devices_controller_abstract_component/ + - b) + - create folder devices_controller/devices_controller_concrete/ + - migrer le dossier devices_controller/server/ => devices_controller/devices_controller_concrete/server/ + - rename server/ => device_simulator_common/ RAPPELS SUR L'UTILISATION : diff --git a/src/core/pyros_django/agent/Agent.py b/src/core/pyros_django/agent/Agent.py index e59278f..7f98ba8 100755 --- a/src/core/pyros_django/agent/Agent.py +++ b/src/core/pyros_django/agent/Agent.py @@ -24,6 +24,7 @@ DEBUG=True """ import os +from pathlib import Path import sys from django.conf import settings as djangosettings @@ -335,7 +336,7 @@ class Agent: MODE_ACTIVE = "ACTIVE" MODE_IDLE = "IDLE" - PYROS_DJANGO_BASE_DIR = "src/core/pyros_django" + PYROS_DJANGO_BASE_DIR = Path("src/core/pyros_django") # pathlib DEFAULT_CONFIG_FILE_NAME = "config_unit_simulunit1.xml" CONFIG_DIR_NAME = "config" @@ -374,6 +375,7 @@ class Agent: self._log = LogPyros() self._log.set_agent_alias(self.name) + ''' (old way) #print(os.path.dirname(__file__)) my_parent_abs_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) #print(os.path.dirname(os.path.realpath(__file__))) @@ -381,6 +383,11 @@ class Agent: self.BASE_DIR = my_parent_abs_dir.split(self.PYROS_DJANGO_BASE_DIR)[0] #print(self.BASE_DIR) self._path_data = os.path.join(self.BASE_DIR, self.CONFIG_DIR_NAME) + ''' + # 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.set_mode(self.MODE_IDLE) if not config_filename: @@ -395,7 +402,7 @@ class Agent: 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(self.PYROS_DJANGO_BASE_DIR+os.sep, os.sep) + 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) diff --git a/src/core/pyros_django/agent/logpyros.py b/src/core/pyros_django/agent/logpyros.py index adca014..e407c4b 100644 --- a/src/core/pyros_django/agent/logpyros.py +++ b/src/core/pyros_django/agent/logpyros.py @@ -146,7 +146,7 @@ class LogPyros: def get_home(self): return self._home.gps - + def print(self, msg): # --- classical print print(msg) @@ -155,7 +155,7 @@ class LogPyros: return # --- self.file(msg) - + def file(self, msg): # --- no more if the agent name is not defined if self._agent_alias=="": @@ -178,7 +178,7 @@ class LogPyros: # --- write super_msg in the log file with open(file,'a') as fic: fic.write(super_msg+"\n") - + def db(self, msg): self._date.date("now"); print(f"{self._date.iso()} {msg}") -- libgit2 0.21.2