Commit 5b21ebadb2a876405321aaa06c58d8ad9acf159f

Authored by Etienne Pallier
1 parent dd33eedf
Exists in dev

Utilisation de pathlib pour les paths (à généraliser au fur et à mesure)

README.md
... ... @@ -77,14 +77,17 @@ Comment :
77 77 - Restructuration du projet - phase 4 : /src/core/pyros_django/utils/celme/ => /src/core/celme/
78 78  
79 79 TODO (coming) :
80   -- Restructuration du projet - phase 5 : /devices_controller/ => réorganisation interne :
81   - - a) sortir devices_controller/client/channel => src/channel/
82   - - b) rename channel/ => channels/
83   - - c) sortir devices_controller/client/devices_abstract/ => devices_controller/devices_abstract/ et supprimer dossier client/
84   - - d) rename devices_abstract/ => devices_controller_abstract_component/
85   - - e) create folder devices_controller/devices_controller_concrete/
86   - - f) migrer le dossier devices_controller/server/ => devices_controller/devices_controller_concrete/server/
87   - - g) rename server/ => device_simulator_common/
  80 +- Restructuration du projet - phase 5 : /src/devices_controller/ => réorganisation interne :
  81 + - a)
  82 + - sortir /src/devices_controller/client/channel => /src/devices_controller/channel/
  83 + - sortir /src/devices_controller/client/devices_abstract/ => /src/devices_controller/devices_abstract/
  84 + - supprimer dossier client/
  85 + - rename channel/ => channels/
  86 + - rename devices_abstract/ => devices_controller_abstract_component/
  87 + - b)
  88 + - create folder devices_controller/devices_controller_concrete/
  89 + - migrer le dossier devices_controller/server/ => devices_controller/devices_controller_concrete/server/
  90 + - rename server/ => device_simulator_common/
88 91  
89 92  
90 93 RAPPELS SUR L'UTILISATION :
... ...
src/core/pyros_django/agent/Agent.py
... ... @@ -24,6 +24,7 @@ DEBUG=True
24 24 """
25 25  
26 26 import os
  27 +from pathlib import Path
27 28 import sys
28 29  
29 30 from django.conf import settings as djangosettings
... ... @@ -335,7 +336,7 @@ class Agent:
335 336 MODE_ACTIVE = "ACTIVE"
336 337 MODE_IDLE = "IDLE"
337 338  
338   - PYROS_DJANGO_BASE_DIR = "src/core/pyros_django"
  339 + PYROS_DJANGO_BASE_DIR = Path("src/core/pyros_django") # pathlib
339 340 DEFAULT_CONFIG_FILE_NAME = "config_unit_simulunit1.xml"
340 341 CONFIG_DIR_NAME = "config"
341 342  
... ... @@ -374,6 +375,7 @@ class Agent:
374 375 self._log = LogPyros()
375 376 self._log.set_agent_alias(self.name)
376 377  
  378 + ''' (old way)
377 379 #print(os.path.dirname(__file__))
378 380 my_parent_abs_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
379 381 #print(os.path.dirname(os.path.realpath(__file__)))
... ... @@ -381,6 +383,11 @@ class Agent:
381 383 self.BASE_DIR = my_parent_abs_dir.split(self.PYROS_DJANGO_BASE_DIR)[0]
382 384 #print(self.BASE_DIR)
383 385 self._path_data = os.path.join(self.BASE_DIR, self.CONFIG_DIR_NAME)
  386 + '''
  387 + # New way with PathLib
  388 + my_parent_abs_dir = Path(__file__).resolve().parent
  389 + #TODO: on doit pouvoir faire mieux avec pathlib (sans utiliser str())
  390 + self._path_data = str( Path( str(my_parent_abs_dir).split(str(self.PYROS_DJANGO_BASE_DIR))[0] ) / self.CONFIG_DIR_NAME )
384 391  
385 392 #self.set_mode(self.MODE_IDLE)
386 393 if not config_filename:
... ... @@ -395,7 +402,7 @@ class Agent:
395 402 config_filename = os.path.abspath(self.CONFIG_DIR_NAME + os.sep + config_filename)
396 403 # Remove "src/agent_name/" from abs dir :
397 404 # (1) Remove "src/core/pyros_django/"
398   - config_filename = config_filename.replace(self.PYROS_DJANGO_BASE_DIR+os.sep, os.sep)
  405 + config_filename = config_filename.replace(str(self.PYROS_DJANGO_BASE_DIR)+os.sep, os.sep)
399 406 # (2) Remove "agent_name/"
400 407 #TODO: bidouille, faire plus propre
401 408 config_filename = config_filename.replace(os.sep+"agent"+os.sep, os.sep)
... ...
src/core/pyros_django/agent/logpyros.py
... ... @@ -146,7 +146,7 @@ class LogPyros:
146 146  
147 147 def get_home(self):
148 148 return self._home.gps
149   -
  149 +
150 150 def print(self, msg):
151 151 # --- classical print
152 152 print(msg)
... ... @@ -155,7 +155,7 @@ class LogPyros:
155 155 return
156 156 # ---
157 157 self.file(msg)
158   -
  158 +
159 159 def file(self, msg):
160 160 # --- no more if the agent name is not defined
161 161 if self._agent_alias=="":
... ... @@ -178,7 +178,7 @@ class LogPyros:
178 178 # --- write super_msg in the log file
179 179 with open(file,'a') as fic:
180 180 fic.write(super_msg+"\n")
181   -
  181 +
182 182 def db(self, msg):
183 183 self._date.date("now");
184 184 print(f"{self._date.iso()} {msg}")
... ...