Commit ad6d274a4a73f7cb55ccc25f46d18cca5051b7f7
1 parent
1cffbf1c
Exists in
dev
Restructuration du projet - phase 2 :
pyros_django/ => src/core/pyros_django/ il a fallu faire des changements un peu partout... pour que tout remarche
Showing
14 changed files
with
120 additions
and
68 deletions
Show diff stats
.pydevproject
1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> | 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> |
2 | <?eclipse-pydev version="1.0"?><pydev_project> | 2 | <?eclipse-pydev version="1.0"?><pydev_project> |
3 | - | 3 | + |
4 | + | ||
4 | 5 | ||
5 | 6 | ||
6 | 7 | ||
7 | 8 | ||
8 | <pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property> | 9 | <pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property> |
9 | - | 10 | + |
11 | + | ||
10 | 12 | ||
11 | 13 | ||
12 | 14 | ||
13 | 15 | ||
14 | <pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property> | 16 | <pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property> |
15 | - | 17 | + |
18 | + | ||
16 | 19 | ||
17 | 20 | ||
18 | 21 | ||
19 | 22 | ||
20 | <pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH"> | 23 | <pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH"> |
21 | - | ||
22 | - <path>/${PROJECT_DIR_NAME}/pyros_django</path> | ||
23 | - | 24 | + <path>/${PROJECT_DIR_NAME}/src</path> |
24 | <path>/${PROJECT_DIR_NAME}/simulators</path> | 25 | <path>/${PROJECT_DIR_NAME}/simulators</path> |
25 | - | ||
26 | </pydev_pathproperty> | 26 | </pydev_pathproperty> |
27 | - | 27 | + |
28 | + | ||
28 | 29 | ||
29 | 30 | ||
30 | 31 | ||
31 | 32 | ||
32 | <pydev_variables_property name="org.python.pydev.PROJECT_VARIABLE_SUBSTITUTION"> | 33 | <pydev_variables_property name="org.python.pydev.PROJECT_VARIABLE_SUBSTITUTION"> |
33 | - | 34 | + |
35 | + | ||
34 | 36 | ||
35 | 37 | ||
36 | 38 | ||
37 | 39 | ||
38 | <key>DJANGO_MANAGE_LOCATION</key> | 40 | <key>DJANGO_MANAGE_LOCATION</key> |
39 | - | 41 | + |
42 | + | ||
40 | 43 | ||
41 | 44 | ||
42 | 45 | ||
43 | 46 | ||
44 | - <value>pyros_django/manage.py</value> | ||
45 | - | 47 | + <value>src/core/pyros_django/manage.py</value> |
48 | + | ||
49 | + | ||
46 | 50 | ||
47 | 51 | ||
48 | 52 | ||
49 | 53 | ||
50 | <key>DJANGO_SETTINGS_MODULE</key> | 54 | <key>DJANGO_SETTINGS_MODULE</key> |
51 | - | 55 | + |
56 | + | ||
52 | 57 | ||
53 | 58 | ||
54 | 59 | ||
55 | 60 | ||
56 | <value>pyros.settings</value> | 61 | <value>pyros.settings</value> |
57 | - | 62 | + |
63 | + | ||
58 | 64 | ||
59 | 65 | ||
60 | 66 | ||
61 | 67 | ||
62 | </pydev_variables_property> | 68 | </pydev_variables_property> |
63 | - | 69 | + |
70 | + | ||
64 | 71 | ||
65 | 72 | ||
66 | 73 |
devices_channel/README.md
1 | 1 | ||
2 | -VERSION: 0.30.3 | 2 | +VERSION: 0.30.4 |
3 | 3 | ||
4 | -Date: 13/06/2019 | 4 | +Date: 14/06/2019 |
5 | 5 | ||
6 | By: epallier@irap.omp.eu | 6 | By: epallier@irap.omp.eu |
7 | 7 | ||
8 | -Comment : Restructuration du projet - phase 1 : src/ => pyros_django/ | 8 | +Comment : Restructuration du projet - phase 2 : pyros_django/ => src/core/pyros_django/ |
9 | 9 | ||
10 | 10 | ||
11 | 11 | ||
@@ -13,7 +13,10 @@ Comment : Restructuration du projet - phase 1 : src/ => pyros_django/ | @@ -13,7 +13,10 @@ Comment : Restructuration du projet - phase 1 : src/ => pyros_django/ | ||
13 | ******************************************************************************************** | 13 | ******************************************************************************************** |
14 | HISTORY | 14 | HISTORY |
15 | 15 | ||
16 | -11/06/2019 | 16 | +14/06/2019 (v0.30.3) |
17 | + - Restructuration du projet - phase 1 : src/ => pyros_django/ | ||
18 | + | ||
19 | +11/06/2019 (v0.30.2) | ||
17 | - Ajoutรฉ options "test" et "testall" dans pyros.py pour exรฉcution des (anciens) tests unitaires | 20 | - Ajoutรฉ options "test" et "testall" dans pyros.py pour exรฉcution des (anciens) tests unitaires |
18 | - Restructuring : private/ => venv/ | 21 | - Restructuring : private/ => venv/ |
19 | 22 |
devices_channel/client/devices_abstract/device_controller_abstract.py
@@ -22,7 +22,7 @@ import time | @@ -22,7 +22,7 @@ import time | ||
22 | sys.path.append("..") | 22 | sys.path.append("..") |
23 | # from src_socket/client/ | 23 | # from src_socket/client/ |
24 | sys.path.append("../../..") | 24 | sys.path.append("../../..") |
25 | -import pyros_django.utils.celme as celme | 25 | +import src.core.pyros_django.utils.celme as celme |
26 | from devices_channel.client.logs import * | 26 | from devices_channel.client.logs import * |
27 | 27 | ||
28 | 28 |
devices_channel/client/devices_abstract/plc_controller_abstract.py
@@ -20,7 +20,7 @@ import time | @@ -20,7 +20,7 @@ import time | ||
20 | sys.path.append("..") | 20 | sys.path.append("..") |
21 | # from src_socket/client/ | 21 | # from src_socket/client/ |
22 | sys.path.append("../../..") | 22 | sys.path.append("../../..") |
23 | -import pyros_django.utils.celme as celme | 23 | +import src.core.pyros_django.utils.celme as celme |
24 | 24 | ||
25 | 25 | ||
26 | # Local application imports | 26 | # Local application imports |
devices_channel/client/devices_abstract/telescope_controller_abstract.py
@@ -20,7 +20,7 @@ import time | @@ -20,7 +20,7 @@ import time | ||
20 | sys.path.append("..") | 20 | sys.path.append("..") |
21 | # from src_socket/client/ | 21 | # from src_socket/client/ |
22 | sys.path.append("../../..") | 22 | sys.path.append("../../..") |
23 | -import pyros_django.utils.celme as celme | 23 | +import src.core.pyros_django.utils.celme as celme |
24 | 24 | ||
25 | 25 | ||
26 | # Local application imports | 26 | # Local application imports |
pyros.py
@@ -21,8 +21,12 @@ import time | @@ -21,8 +21,12 @@ import time | ||
21 | 21 | ||
22 | DEBUG = False | 22 | DEBUG = False |
23 | 23 | ||
24 | +PYROS_DJANGO_BASE_DIR = "src/core/pyros_django" | ||
25 | + | ||
24 | INIT_FIXTURE = "initial_fixture.json" | 26 | INIT_FIXTURE = "initial_fixture.json" |
25 | 27 | ||
28 | +_previous_dir = None | ||
29 | + | ||
26 | AGENTS = { | 30 | AGENTS = { |
27 | #"agentX" : "agent", | 31 | #"agentX" : "agent", |
28 | "agent" : "Agent", | 32 | "agent" : "Agent", |
@@ -243,7 +247,7 @@ def shell(): | @@ -243,7 +247,7 @@ def shell(): | ||
243 | print(" >>> agent.run(2) (=> will run 2 iterations)") | 247 | print(" >>> agent.run(2) (=> will run 2 iterations)") |
244 | print(" >>> cmd = agent.send_command('AgentB','eval 2+2')") | 248 | print(" >>> cmd = agent.send_command('AgentB','eval 2+2')") |
245 | print(" >>> cmd") | 249 | print(" >>> cmd") |
246 | - print(" >>> cmd1.get_updated_result()") | 250 | + print(" >>> cmd.get_updated_result()") |
247 | print(" >>> ...") | 251 | print(" >>> ...") |
248 | print(" - See documentation, section 'Play with a pyros agent' inside the chapter 'Running pyros' for more details") | 252 | print(" - See documentation, section 'Play with a pyros agent' inside the chapter 'Running pyros' for more details") |
249 | print() | 253 | print() |
@@ -259,11 +263,13 @@ def shell(): | @@ -259,11 +263,13 @@ def shell(): | ||
259 | print() | 263 | print() |
260 | print("Type 'exit()' to quit") | 264 | print("Type 'exit()' to quit") |
261 | print() | 265 | print() |
262 | - os.chdir("pyros_django/") | 266 | + change_dir(PYROS_DJANGO_BASE_DIR) |
267 | + | ||
263 | # execProcess("python install.py install") | 268 | # execProcess("python install.py install") |
264 | if not test_mode(): execProcessFromVenv("manage.py shell") | 269 | if not test_mode(): execProcessFromVenv("manage.py shell") |
265 | # Go back to the initial dir | 270 | # Go back to the initial dir |
266 | - os.chdir("../") | 271 | + #os.chdir("../") |
272 | + change_dir("PREVIOUS") | ||
267 | return True | 273 | return True |
268 | 274 | ||
269 | 275 | ||
@@ -276,7 +282,7 @@ def dbshell(): | @@ -276,7 +282,7 @@ def dbshell(): | ||
276 | print("Type 'exit' to quit") | 282 | print("Type 'exit' to quit") |
277 | print() | 283 | print() |
278 | # execProcess("python install.py install") | 284 | # execProcess("python install.py install") |
279 | - if not test_mode(): execProcessFromVenv("pyros_django/manage.py dbshell") | 285 | + if not test_mode(): execProcessFromVenv(PYROS_DJANGO_BASE_DIR+"/manage.py dbshell") |
280 | # Go back to the initial dir | 286 | # Go back to the initial dir |
281 | return True | 287 | return True |
282 | 288 | ||
@@ -307,17 +313,17 @@ def test(): | @@ -307,17 +313,17 @@ def test(): | ||
307 | apps = ['common', 'scheduler', 'routine_manager', 'user_manager', 'alert_manager.tests.TestStrategyChange'] | 313 | apps = ['common', 'scheduler', 'routine_manager', 'user_manager', 'alert_manager.tests.TestStrategyChange'] |
308 | for app in apps: | 314 | for app in apps: |
309 | _loaddata() or die() | 315 | _loaddata() or die() |
310 | - change_dir("pyros_django") | 316 | + change_dir(PYROS_DJANGO_BASE_DIR) |
311 | execProcessFromVenv('manage.py test ' + app) or die() | 317 | execProcessFromVenv('manage.py test ' + app) or die() |
312 | - change_dir("..") | 318 | + change_dir("PREVIOUS") |
313 | # execProcess("python install.py install") | 319 | # execProcess("python install.py install") |
314 | return True | 320 | return True |
315 | 321 | ||
316 | @pyros_launcher.command(help="Run ALL tests") | 322 | @pyros_launcher.command(help="Run ALL tests") |
317 | def testall(): | 323 | def testall(): |
318 | - change_dir("pyros_django") | 324 | + change_dir(PYROS_DJANGO_BASE_DIR) |
319 | execProcessFromVenvAsync("manage.py test") | 325 | execProcessFromVenvAsync("manage.py test") |
320 | - change_dir("..") | 326 | + change_dir("PREVIOUS") |
321 | return True | 327 | return True |
322 | 328 | ||
323 | 329 | ||
@@ -386,7 +392,7 @@ def start(agent:str, configfile:str): | @@ -386,7 +392,7 @@ def start(agent:str, configfile:str): | ||
386 | if configfile: | 392 | if configfile: |
387 | print("With config file", configfile) | 393 | print("With config file", configfile) |
388 | else: | 394 | else: |
389 | - configfile = '' | 395 | + configfile = '' |
390 | #if test_mode(): print("in test mode") | 396 | #if test_mode(): print("in test mode") |
391 | #if verbose_mode(): print("in verbose mode") | 397 | #if verbose_mode(): print("in verbose mode") |
392 | 398 | ||
@@ -425,11 +431,11 @@ def start(agent:str, configfile:str): | @@ -425,11 +431,11 @@ def start(agent:str, configfile:str): | ||
425 | # Agent "webserver" | 431 | # Agent "webserver" |
426 | if agent_name == "webserver": | 432 | if agent_name == "webserver": |
427 | cmd = "manage.py runserver" | 433 | cmd = "manage.py runserver" |
428 | - os.chdir("pyros_django") | 434 | + os.chdir(PYROS_DJANGO_BASE_DIR) |
429 | #if not test_mode(): execProcessFromVenv("start_agent.py " + agent_name + " " + configfile) | 435 | #if not test_mode(): execProcessFromVenv("start_agent.py " + agent_name + " " + configfile) |
430 | 436 | ||
431 | elif agent_name == "agentM": | 437 | elif agent_name == "agentM": |
432 | - os.chdir("pyros_django/monitoring/") | 438 | + os.chdir(PYROS_DJANGO_BASE_DIR+"/monitoring/") |
433 | cmd = f"Agent{agent_name[5:]}.py" | 439 | cmd = f"Agent{agent_name[5:]}.py" |
434 | if test_mode(): cmd += " -t" | 440 | if test_mode(): cmd += " -t" |
435 | if configfile: cmd += " {configfile}" | 441 | if configfile: cmd += " {configfile}" |
@@ -438,7 +444,7 @@ def start(agent:str, configfile:str): | @@ -438,7 +444,7 @@ def start(agent:str, configfile:str): | ||
438 | elif agent_name.startswith("agent"): | 444 | elif agent_name.startswith("agent"): |
439 | # Run agent without actual commands sent to devices (FOR_REAL=False) | 445 | # Run agent without actual commands sent to devices (FOR_REAL=False) |
440 | ##agentX.run(FOR_REAL=True) | 446 | ##agentX.run(FOR_REAL=True) |
441 | - os.chdir("pyros_django/agent/") | 447 | + os.chdir(PYROS_DJANGO_BASE_DIR+"/agent/") |
442 | #cmd = "-m AgentX" | 448 | #cmd = "-m AgentX" |
443 | #cmd = f" Agent{agent_name[5:]}.py {configfile}" | 449 | #cmd = f" Agent{agent_name[5:]}.py {configfile}" |
444 | cmd = f"Agent{agent_name[5:]}.py" | 450 | cmd = f"Agent{agent_name[5:]}.py" |
@@ -507,39 +513,42 @@ def _update_python_packages_from_requirements(): | @@ -507,39 +513,42 @@ def _update_python_packages_from_requirements(): | ||
507 | 513 | ||
508 | def _update_plantuml_diags(): | 514 | def _update_plantuml_diags(): |
509 | res = False | 515 | res = False |
510 | - for dirpath, dirnames, files in os.walk('pyros_django'): | 516 | + for dirpath, dirnames, files in os.walk(PYROS_DJANGO_BASE_DIR): |
511 | if os.path.basename(dirpath) == "doc": | 517 | if os.path.basename(dirpath) == "doc": |
512 | diagrams = glob.glob(dirpath+os.sep+"*.pu") | 518 | diagrams = glob.glob(dirpath+os.sep+"*.pu") |
513 | for diag in diagrams: res = execProcessFromVenv("-m plantuml "+diag) | 519 | for diag in diagrams: res = execProcessFromVenv("-m plantuml "+diag) |
514 | return res | 520 | return res |
515 | 521 | ||
516 | def _migrate(): | 522 | def _migrate(): |
517 | - change_dir("pyros_django") | 523 | + change_dir(PYROS_DJANGO_BASE_DIR) |
518 | # Migrate only migrations for the app "common" | 524 | # Migrate only migrations for the app "common" |
519 | #res = execProcessFromVenv("manage.py migrate common") | 525 | #res = execProcessFromVenv("manage.py migrate common") |
520 | # Migrate all migrations for ALL apps | 526 | # Migrate all migrations for ALL apps |
521 | res = execProcessFromVenv("manage.py migrate") | 527 | res = execProcessFromVenv("manage.py migrate") |
522 | - change_dir("..") | 528 | + change_dir("PREVIOUS") |
523 | return res | 529 | return res |
524 | 530 | ||
525 | def _makemigrations(): | 531 | def _makemigrations(): |
526 | - change_dir("pyros_django") | 532 | + change_dir(PYROS_DJANGO_BASE_DIR) |
527 | #execProcessFromVenv(self.venv_bin + " manage.py makemigrations") | 533 | #execProcessFromVenv(self.venv_bin + " manage.py makemigrations") |
528 | #res = execProcessFromVenv("manage.py makemigrations common") | 534 | #res = execProcessFromVenv("manage.py makemigrations common") |
529 | res = execProcessFromVenv("manage.py makemigrations") | 535 | res = execProcessFromVenv("manage.py makemigrations") |
530 | - change_dir("..") | 536 | + change_dir("PREVIOUS") |
531 | return res | 537 | return res |
532 | 538 | ||
533 | #TODO: mettre la fixture en date naive (sans time zone) | 539 | #TODO: mettre la fixture en date naive (sans time zone) |
534 | def _loaddata(): | 540 | def _loaddata(): |
535 | - change_dir("pyros_django") | 541 | + change_dir(PYROS_DJANGO_BASE_DIR) |
536 | #execProcessFromVenv(self.venv_bin + " manage.py loaddata misc" + os.sep + "fixtures" + os.sep + self.INIT_FIXTURE) | 542 | #execProcessFromVenv(self.venv_bin + " manage.py loaddata misc" + os.sep + "fixtures" + os.sep + self.INIT_FIXTURE) |
537 | res = execProcessFromVenv("manage.py loaddata misc" + os.sep + "fixtures" + os.sep + INIT_FIXTURE) | 543 | res = execProcessFromVenv("manage.py loaddata misc" + os.sep + "fixtures" + os.sep + INIT_FIXTURE) |
538 | - change_dir("..") | 544 | + change_dir("PREVIOUS") |
539 | return res | 545 | return res |
540 | 546 | ||
541 | 547 | ||
542 | def change_dir(path): | 548 | def change_dir(path): |
549 | + global _previous_dir | ||
550 | + if path == "PREVIOUS": path=_previous_dir | ||
551 | + _previous_dir = os.getcwd() | ||
543 | if DEBUG: print("Moving to : " + path) | 552 | if DEBUG: print("Moving to : " + path) |
544 | os.chdir(path) | 553 | os.chdir(path) |
545 | if DEBUG: print("Current directory : " + str(os.getcwd())) | 554 | if DEBUG: print("Current directory : " + str(os.getcwd())) |
src/core/pyros_django/agent/Agent.py
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | VERSION = "0.5" | 3 | VERSION = "0.5" |
4 | 4 | ||
5 | DEBUG=True | 5 | DEBUG=True |
6 | -DEBUG=False | 6 | +#DEBUG=False |
7 | 7 | ||
8 | """TODO: | 8 | """TODO: |
9 | 9 | ||
@@ -45,6 +45,8 @@ from django.conf import settings as djangosettings | @@ -45,6 +45,8 @@ from django.conf import settings as djangosettings | ||
45 | # To avoid a "ModuleNotFoundError: No module named 'src'" | 45 | # To avoid a "ModuleNotFoundError: No module named 'src'" |
46 | sys.path.append("..") | 46 | sys.path.append("..") |
47 | sys.path.append("../..") | 47 | sys.path.append("../..") |
48 | +sys.path.append("../../..") | ||
49 | +sys.path.append("../../../..") | ||
48 | ##sys.path.append("src") | 50 | ##sys.path.append("src") |
49 | print("Starting with this sys.path", sys.path) | 51 | print("Starting with this sys.path", sys.path) |
50 | 52 | ||
@@ -56,7 +58,8 @@ print("Starting with this sys.path", sys.path) | @@ -56,7 +58,8 @@ print("Starting with this sys.path", sys.path) | ||
56 | ##os.chdir("src") | 58 | ##os.chdir("src") |
57 | print("Current directory : " + str(os.getcwd())) | 59 | print("Current directory : " + str(os.getcwd())) |
58 | 60 | ||
59 | -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pyros_django.pyros.settings") | 61 | +#os.environ.setdefault("DJANGO_SETTINGS_MODULE", "src.core.pyros_django.pyros.settings") |
62 | +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "src.core.pyros_django.pyros.settings") | ||
60 | # os.environ['SECRET_KEY'] = 'abc' | 63 | # os.environ['SECRET_KEY'] = 'abc' |
61 | # os.environ['ENVIRONMENT'] = 'production' | 64 | # os.environ['ENVIRONMENT'] = 'production' |
62 | import django | 65 | import django |
@@ -332,8 +335,19 @@ class Agent: | @@ -332,8 +335,19 @@ class Agent: | ||
332 | MODE_ACTIVE = "ACTIVE" | 335 | MODE_ACTIVE = "ACTIVE" |
333 | MODE_IDLE = "IDLE" | 336 | MODE_IDLE = "IDLE" |
334 | 337 | ||
338 | + PYROS_DJANGO_BASE_DIR = "src/core/pyros_django" | ||
335 | DEFAULT_CONFIG_FILE_NAME = "config_unit_simulunit1.xml" | 339 | DEFAULT_CONFIG_FILE_NAME = "config_unit_simulunit1.xml" |
336 | - CONFIG_DIR = "config" | 340 | + CONFIG_DIR_NAME = "config" |
341 | + | ||
342 | + # Parameters from config file | ||
343 | + # for /src/ | ||
344 | + #_path_data = '../../config' | ||
345 | + # for /src/core/pyros_django/ | ||
346 | + #_path_data = '../../../../config' | ||
347 | + # Path to config | ||
348 | + _path_data = '' | ||
349 | + _computer_alias = '' | ||
350 | + _computer_description = '' | ||
337 | 351 | ||
338 | # Current and next command to send | 352 | # Current and next command to send |
339 | cmdts = None | 353 | cmdts = None |
@@ -344,10 +358,6 @@ class Agent: | @@ -344,10 +358,6 @@ class Agent: | ||
344 | _current_specific_cmd = None | 358 | _current_specific_cmd = None |
345 | _current_specific_thread = None | 359 | _current_specific_thread = None |
346 | 360 | ||
347 | - # Parameters from config file | ||
348 | - _computer_alias = '' | ||
349 | - _computer_description = '' | ||
350 | - _path_data = '../../config' | ||
351 | 361 | ||
352 | _iter_num = None | 362 | _iter_num = None |
353 | 363 | ||
@@ -364,6 +374,14 @@ class Agent: | @@ -364,6 +374,14 @@ class Agent: | ||
364 | self._log = LogPyros() | 374 | self._log = LogPyros() |
365 | self._log.set_agent_alias(self.name) | 375 | self._log.set_agent_alias(self.name) |
366 | 376 | ||
377 | + #print(os.path.dirname(__file__)) | ||
378 | + my_parent_abs_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) | ||
379 | + #print(os.path.dirname(os.path.realpath(__file__))) | ||
380 | + #print(djangosettings.BASE_DIR) | ||
381 | + self.BASE_DIR = my_parent_abs_dir.split(self.PYROS_DJANGO_BASE_DIR)[0] | ||
382 | + #print(self.BASE_DIR) | ||
383 | + self._path_data = os.path.join(self.BASE_DIR, self.CONFIG_DIR_NAME) | ||
384 | + | ||
367 | #self.set_mode(self.MODE_IDLE) | 385 | #self.set_mode(self.MODE_IDLE) |
368 | if not config_filename: | 386 | if not config_filename: |
369 | config_filename = self.DEFAULT_CONFIG_FILE_NAME | 387 | config_filename = self.DEFAULT_CONFIG_FILE_NAME |
@@ -374,14 +392,14 @@ class Agent: | @@ -374,14 +392,14 @@ class Agent: | ||
374 | # => give it an absolute path (and remove "src/agent/" from it) | 392 | # => give it an absolute path (and remove "src/agent/" from it) |
375 | if config_filename == os.path.basename(config_filename): | 393 | if config_filename == os.path.basename(config_filename): |
376 | # Build abs path including current agent dir | 394 | # Build abs path including current agent dir |
377 | - config_filename = os.path.abspath(self.CONFIG_DIR + os.sep + config_filename) | 395 | + config_filename = os.path.abspath(self.CONFIG_DIR_NAME + os.sep + config_filename) |
378 | # Remove "src/agent_name/" from abs dir : | 396 | # Remove "src/agent_name/" from abs dir : |
379 | - # (1) Remove "src/" | ||
380 | - config_filename = config_filename.replace(os.sep+"pyros_django"+os.sep,os.sep) | 397 | + # (1) Remove "src/core/pyros_django/" |
398 | + config_filename = config_filename.replace(self.PYROS_DJANGO_BASE_DIR+os.sep, os.sep) | ||
381 | # (2) Remove "agent_name/" | 399 | # (2) Remove "agent_name/" |
382 | #TODO: bidouille, faire plus propre | 400 | #TODO: bidouille, faire plus propre |
383 | - config_filename = config_filename.replace(os.sep+"agent"+os.sep,os.sep) | ||
384 | - config_filename = config_filename.replace(os.sep+"monitoring"+os.sep,os.sep) | 401 | + config_filename = config_filename.replace(os.sep+"agent"+os.sep, os.sep) |
402 | + config_filename = config_filename.replace(os.sep+"monitoring"+os.sep, os.sep) | ||
385 | self.printd("Config file used is", config_filename) | 403 | self.printd("Config file used is", config_filename) |
386 | #self.printd("current path", os.getcwd()) | 404 | #self.printd("current path", os.getcwd()) |
387 | #self.printd("this file path :", __file__) | 405 | #self.printd("this file path :", __file__) |
@@ -446,6 +464,7 @@ class Agent: | @@ -446,6 +464,7 @@ class Agent: | ||
446 | while self.DO_RESTART: | 464 | while self.DO_RESTART: |
447 | self.DO_RESTART = False | 465 | self.DO_RESTART = False |
448 | 466 | ||
467 | + self.printd("on est ici: ", os.getcwd()) | ||
449 | self.load_config() | 468 | self.load_config() |
450 | 469 | ||
451 | if self.SIMULATOR_MODE: | 470 | if self.SIMULATOR_MODE: |
@@ -746,12 +765,16 @@ class Agent: | @@ -746,12 +765,16 @@ class Agent: | ||
746 | unit_subtag = 'computer' | 765 | unit_subtag = 'computer' |
747 | aliases = self.config.get_aliases(unit_subtag) | 766 | aliases = self.config.get_aliases(unit_subtag) |
748 | for alias in aliases: | 767 | for alias in aliases: |
768 | + self.printd("alias", alias) | ||
749 | value = self.config.get_paramvalue(alias,'local','hostname') | 769 | value = self.config.get_paramvalue(alias,'local','hostname') |
770 | + self.printd("value", value) | ||
750 | if value == hostname: | 771 | if value == hostname: |
772 | + self.printd("value", value) | ||
751 | self._computer_alias = alias | 773 | self._computer_alias = alias |
752 | value = self.config.get_paramvalue(alias,unit_subtag,'description') | 774 | value = self.config.get_paramvalue(alias,unit_subtag,'description') |
753 | self._computer_description = value | 775 | self._computer_description = value |
754 | value = self.config.get_paramvalue(alias,'path','data') | 776 | value = self.config.get_paramvalue(alias,'path','data') |
777 | + # Overrides default value | ||
755 | self._path_data = value | 778 | self._path_data = value |
756 | break | 779 | break |
757 | print(f"hostname = {hostname}") | 780 | print(f"hostname = {hostname}") |
src/core/pyros_django/monitoring/AgentM.py
@@ -10,11 +10,11 @@ import sys | @@ -10,11 +10,11 @@ import sys | ||
10 | 10 | ||
11 | sys.path.append("..") | 11 | sys.path.append("..") |
12 | sys.path.append("../..") | 12 | sys.path.append("../..") |
13 | -from pyros_django.agent.Agent import Agent, extract_parameters | 13 | +from src.core.pyros_django.agent.Agent import Agent, extract_parameters |
14 | 14 | ||
15 | # PM 20190416 recycle code | 15 | # PM 20190416 recycle code |
16 | -from pyros_django.devices.PLC import PLCController | ||
17 | -from pyros_django.monitoring.plc_checker import PlcChecker | 16 | +from src.core.pyros_django.devices.PLC import PLCController |
17 | +from src.core.pyros_django.monitoring.plc_checker import PlcChecker | ||
18 | from common.models import * | 18 | from common.models import * |
19 | 19 | ||
20 | ##log = L.setupLogger("AgentXTaskLogger", "AgentX") | 20 | ##log = L.setupLogger("AgentXTaskLogger", "AgentX") |
src/core/pyros_django/monitoring/tasks.py
@@ -2,7 +2,7 @@ from __future__ import absolute_import | @@ -2,7 +2,7 @@ from __future__ import absolute_import | ||
2 | from django.conf import settings | 2 | from django.conf import settings |
3 | from common.models import * | 3 | from common.models import * |
4 | 4 | ||
5 | -from pyros_django.monitoring.plc_checker import PlcChecker | 5 | +from src.core.pyros_django.monitoring.plc_checker import PlcChecker |
6 | from devices.PLC import PLCController | 6 | from devices.PLC import PLCController |
7 | from utils.JDManipulator import * | 7 | from utils.JDManipulator import * |
8 | import json | 8 | import json |
src/core/pyros_django/pyros/settings.py
@@ -50,6 +50,7 @@ import os | @@ -50,6 +50,7 @@ import os | ||
50 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 50 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
51 | 51 | ||
52 | # Output folder for images | 52 | # Output folder for images |
53 | +#TODO: c'est quoi ce dossier ? existe-t-il vraiment ??? | ||
53 | OUTPUT_FOLDER = os.path.join(BASE_DIR, "../images_folder") | 54 | OUTPUT_FOLDER = os.path.join(BASE_DIR, "../images_folder") |
54 | 55 | ||
55 | # Quick-start development settings - unsuitable for production | 56 | # Quick-start development settings - unsuitable for production |
@@ -144,10 +145,10 @@ LOGIN_URL = "/" | @@ -144,10 +145,10 @@ LOGIN_URL = "/" | ||
144 | 145 | ||
145 | # DATABASE CONFIG | 146 | # DATABASE CONFIG |
146 | ''' | 147 | ''' |
147 | -From MySQL 5.7 onwards and on fresh installs of MySQL 5.6, | ||
148 | -the default value of the sql_mode option contains STRICT_TRANS_TABLES. | ||
149 | -That option escalates warnings into errors when data are truncated upon insertion, | ||
150 | -so Django highly recommends activating a strict mode for MySQL to prevent data loss | 148 | +From MySQL 5.7 onwards and on fresh installs of MySQL 5.6, |
149 | +the default value of the sql_mode option contains STRICT_TRANS_TABLES. | ||
150 | +That option escalates warnings into errors when data are truncated upon insertion, | ||
151 | +so Django highly recommends activating a strict mode for MySQL to prevent data loss | ||
151 | (either STRICT_TRANS_TABLES or STRICT_ALL_TABLES) | 152 | (either STRICT_TRANS_TABLES or STRICT_ALL_TABLES) |
152 | ''' | 153 | ''' |
153 | mysql_options = { 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'" } | 154 | mysql_options = { 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'" } |
src/core/pyros_django/utils/Logger.py
1 | from django.conf import settings | 1 | from django.conf import settings |
2 | import logging | 2 | import logging |
3 | 3 | ||
4 | -logging.basicConfig(filename='%s/../logs/pyros.log'%(settings.BASE_DIR), format='-> At : [%(asctime)s]\n\t By module [%(module)s] logger : [%(name)s] : "%(message)s"', level=logging.DEBUG) | 4 | +# If django project is in /src/ : |
5 | +#RELATIVE_PATH_TO_LOG_DIR = '../logs/' | ||
6 | +#logging.basicConfig(filename='%s/../logs/pyros.log'%(settings.BASE_DIR), format='-> At : [%(asctime)s]\n\t By module [%(module)s] logger : [%(name)s] : "%(message)s"', level=logging.DEBUG) | ||
7 | +# If django project is in /src/core/pyros_django/ : | ||
8 | +RELATIVE_PATH_TO_LOG_DIR = '../../../logs' | ||
9 | +logging.basicConfig(filename = f'{settings.BASE_DIR}/{RELATIVE_PATH_TO_LOG_DIR}/pyros.log', | ||
10 | + format = '-> At : [%(asctime)s]\n\t By module [%(module)s] logger : [%(name)s] : "%(message)s"', | ||
11 | + level = logging.DEBUG) | ||
12 | +#logging.basicConfig(filename='%s/../../../logs/pyros.log'%(settings.BASE_DIR), format='-> At : [%(asctime)s]\n\t By module [%(module)s] logger : [%(name)s] : "%(message)s"', level=logging.DEBUG) | ||
5 | 13 | ||
6 | def setupLogger(logger_name, log_file, level=logging.INFO): | 14 | def setupLogger(logger_name, log_file, level=logging.INFO): |
7 | l = logging.getLogger(logger_name) | 15 | l = logging.getLogger(logger_name) |
8 | formatter = logging.Formatter('[%(message)s] at %(filename)s : %(lineno)s') | 16 | formatter = logging.Formatter('[%(message)s] at %(filename)s : %(lineno)s') |
9 | - fileHandler = logging.FileHandler('%s/../logs/%s.log'%(settings.BASE_DIR, log_file), mode='w') | 17 | + #fileHandler = logging.FileHandler('%s/../logs/%s.log'%(settings.BASE_DIR, log_file), mode='w') |
18 | + fileHandler = logging.FileHandler(f'{settings.BASE_DIR}/{RELATIVE_PATH_TO_LOG_DIR}/{log_file}.log', mode='w') | ||
10 | fileHandler.setFormatter(formatter) | 19 | fileHandler.setFormatter(formatter) |
11 | # streamHandler = logging.StreamHandler() | 20 | # streamHandler = logging.StreamHandler() |
12 | # streamHandler.setFormatter(formatter) | 21 | # streamHandler.setFormatter(formatter) |
start_agent.py
@@ -85,24 +85,24 @@ if agent_name not in AGENTS: | @@ -85,24 +85,24 @@ if agent_name not in AGENTS: | ||
85 | sys.exit(1) | 85 | sys.exit(1) |
86 | 86 | ||
87 | if agent_name == "majordome": | 87 | if agent_name == "majordome": |
88 | - from pyros_django.majordome.tasks import Majordome | 88 | + from src.core.pyros_django.majordome.tasks import Majordome |
89 | Majordome().run(FOR_REAL=True) | 89 | Majordome().run(FOR_REAL=True) |
90 | sys.exit(0) | 90 | sys.exit(0) |
91 | 91 | ||
92 | if agent_name == "monitoring": | 92 | if agent_name == "monitoring": |
93 | - from pyros_django.monitoring.tasks import Monitoring | 93 | + from src.core.pyros_django.monitoring.tasks import Monitoring |
94 | Monitoring().run() | 94 | Monitoring().run() |
95 | sys.exit(0) | 95 | sys.exit(0) |
96 | 96 | ||
97 | if agent_name == "agentA": | 97 | if agent_name == "agentA": |
98 | - from pyros_django.agent.AgentA import AgentA | 98 | + from src.core.pyros_django.agent.AgentA import AgentA |
99 | agentA = AgentA(name="agentA", config_filename=configfile) | 99 | agentA = AgentA(name="agentA", config_filename=configfile) |
100 | # Run agent without actual commands sent to devices (FOR_REAL=False) | 100 | # Run agent without actual commands sent to devices (FOR_REAL=False) |
101 | agentA.run(FOR_REAL=True) | 101 | agentA.run(FOR_REAL=True) |
102 | sys.exit(0) | 102 | sys.exit(0) |
103 | 103 | ||
104 | if agent_name == "agentM": | 104 | if agent_name == "agentM": |
105 | - from pyros_django.monitoring.AgentM import AgentM | 105 | + from src.core.pyros_django.monitoring.AgentM import AgentM |
106 | agentM = AgentM(name="agentM", config_filename=configfile) | 106 | agentM = AgentM(name="agentM", config_filename=configfile) |
107 | # Run agent without actual commands sent to devices (FOR_REAL=False) | 107 | # Run agent without actual commands sent to devices (FOR_REAL=False) |
108 | agentM.run(FOR_REAL=True) | 108 | agentM.run(FOR_REAL=True) |
@@ -116,7 +116,7 @@ agent.run(FOR_REAL=True) | @@ -116,7 +116,7 @@ agent.run(FOR_REAL=True) | ||
116 | 116 | ||
117 | # Default agent is AgentX | 117 | # Default agent is AgentX |
118 | 118 | ||
119 | -from pyros_django.agent.AgentX import AgentX | 119 | +from src.core.pyros_django.agent.AgentX import AgentX |
120 | # AgentX().run(FOR_REAL=False) | 120 | # AgentX().run(FOR_REAL=False) |
121 | agentX = AgentX(name="agentX", config_filename=configfile) | 121 | agentX = AgentX(name="agentX", config_filename=configfile) |
122 | 122 |