Commit 7f61826d2b5bf6188cc1016a18ab6dbc7fd38fcb
1 parent
c806f79b
Exists in
dev
Fixing Agent.py init and build_agent methods, adapt AgentM and AgentSP to it
Showing
4 changed files
with
283 additions
and
174 deletions
Show diff stats
CHANGELOG
... | ... | @@ -2,6 +2,10 @@ |
2 | 2 | - Adding SP_Period in API |
3 | 3 | - Adding guitastro gitclone and installation of guitastro's python package in docker_build |
4 | 4 | - Addind git pull of guitastro in pyros.py |
5 | + - Adding check if guitastro folder already exists in PYROS_DOCKER_BUILD | |
6 | + - Removing vendor folder from .dockerignore"Removing vendor folder from .dockerignore | |
7 | + - Fixing warning of current_uid variable for pyros_docker_start | |
8 | + - Fixing Agent's init and build agent methods, adapt agentM and agentSP to it" | |
5 | 9 | |
6 | 10 | 08-04-2022 (AKo): v0.4.2.0 |
7 | 11 | - Fixing pyros.py for classic installation (without docker) | ... | ... |
src/core/pyros_django/agent/Agent.py
... | ... | @@ -426,96 +426,26 @@ class Agent: |
426 | 426 | # Log object |
427 | 427 | _log = None |
428 | 428 | |
429 | - #def __init__(self, name:str="Agent", config_filename:str=None, RUN_IN_THREAD=True): | |
430 | - #def __init__(self, config_filename:str=None, RUN_IN_THREAD=True, DEBUG_MODE=False): | |
431 | - def __init__(self, config_filename:str=None, RUN_IN_THREAD=True): | |
432 | - | |
433 | - ''' | |
434 | - print('PYROS_ENV', PYROS_ENV) | |
435 | - print('ROOT_DIR', ROOT_DIR) | |
436 | - print('DOC_DIR', DOC_DIR) | |
437 | - ''' | |
438 | - | |
439 | - # Set logger | |
440 | - ##pyros_logger.set_logger_config() | |
441 | - ##logg = logging.getLogger('pyroslogger') | |
429 | + # new obsconfig init for agent: | |
430 | + def __init__(self, RUN_IN_THREAD=True): | |
442 | 431 | log.addHandler(handler_filebyagent(logging.INFO, self.__class__.__name__)) |
443 | - | |
444 | 432 | log.debug("start Agent init") |
445 | - | |
446 | - # SET CONFIG INSTANCE | |
447 | - | |
448 | - # - OLD CONFIG | |
449 | - log.debug(f'config file is {config_filename}') | |
450 | - ##log.info('PYROS_ENV', config.PYROS_ENV) | |
451 | - log.debug('PYROS_ENV' + config_old.PYROS_ENV) | |
452 | - log.debug('ROOT_DIR' + config_old.ROOT_DIR) | |
453 | - log.debug('DOC_DIR' + config_old.DOC_DIR) | |
454 | - ##if config.is_dev_env(): print("DEV ENV") | |
455 | - if config_old.is_dev_env(): log.debug("DEV ENV") | |
456 | - if config_old.is_prod_env(): log.debug("PROD ENV") | |
457 | - if config_old.is_debug(): log.debug("IN DEBUG MODE") | |
458 | - | |
459 | - # - NEW CONFIG | |
460 | 433 | obs_config_file_path = os.environ["PATH_TO_OBSCONF_FILE"] |
461 | 434 | path_to_obs_config_folder = os.environ["PATH_TO_OBSCONF_FOLDER"] |
462 | 435 | unit = os.environ["unit_name"] |
463 | - oc = OBSConfig(obs_config_file_path) | |
436 | + oc = OBSConfig(obs_config_file_path,unit) | |
464 | 437 | self.set_config(oc, obs_config_file_path, path_to_obs_config_folder, unit) |
465 | 438 | |
466 | - #self.name = name | |
467 | 439 | self.name = self.__class__.__name__ |
468 | - | |
469 | - | |
470 | - ''' | |
471 | - printd("*** ENVIRONMENT VARIABLE PYROS_DEBUG is:", os.environ.get('PYROS_DEBUG'), '***') | |
472 | - ##self.DEBUG_MODE = DEBUG_MODE | |
473 | - self.DEBUG_MODE = os.environ.get('PYROS_DEBUG', '0')=='1' | |
474 | - ''' | |
475 | - #self.DEBUG_MODE = config.PYROS_ENV | |
476 | - ##self.log = LogPyros(self.name, AgentLogs) | |
477 | - ##self.DEBUG_MODE = config.is_debug() | |
478 | - self.DEBUG_MODE = config_old.is_debug() | |
479 | - ##self.log.debug_level = DEBUG_MODE | |
480 | - ''' | |
481 | - # Default LOG level is INFO | |
482 | - log_level = LogPyros.LOG_LEVEL_INFO # INFO | |
483 | - self.log.set_global_log_level(LogPyros.LOG_LEVEL_DEBUG) if self.DEBUG_MODE else self.log.set_global_log_level(log_level) | |
484 | - ''' | |
485 | - #global_log_level = LogPyros.LOG_LEVEL_DEBUG if self.DEBUG_MODE else self.PYROS_DEFAULT_GLOBAL_LOG_LEVEL | |
486 | - ##global_log_level = LogPyros.LOG_LEVEL_DEBUG if self.DEBUG_MODE else config.PYROS_DEFAULT_GLOBAL_LOG_LEVEL | |
487 | - ##global_log_level = LogPyros.LOG_LEVEL_DEBUG if self.DEBUG_MODE else config_old.PYROS_DEFAULT_GLOBAL_LOG_LEVEL | |
488 | - ##self.log.set_global_log_level(global_log_level) | |
489 | - ##self.printd("LOG LEVEL IS:", self.log.debug_level) | |
490 | - ##self.print("LOG LEVEL IS:", self.log.get_global_log_level()) | |
491 | - | |
492 | - # Est-ce bien utile ??? | |
493 | - # New way with PathLib | |
494 | - my_parent_abs_dir = Path(__file__).resolve().parent | |
495 | - #TODO: on doit pouvoir faire mieux avec pathlib (sans utiliser str()) | |
496 | - ##self._path_data = str( Path( str(my_parent_abs_dir).split(str(self.PYROS_DJANGO_BASE_DIR))[0] ) / self.CONFIG_DIR_NAME ) | |
497 | - ##self._path_data = config.CONFIG_DIR | |
498 | - self._path_data = config_old.CONFIG_DIR | |
499 | - | |
500 | - #self._set_mode(self.MODE_IDLE) | |
501 | - config_filename = self.get_config_filename(config_filename) | |
502 | - #self.printd(f"*** Config file used is={config_filename}") | |
503 | - log.debug(f"*** Config file used is={config_filename}") | |
504 | - self.config = ConfigPyrosOld(config_filename) | |
505 | - if self.config.get_last_errno() != self.config.NO_ERROR: | |
506 | - raise Exception(f"Bad config file name '{config_filename}', error {str(self.config.get_last_errno())}: {str(self.config.get_last_errmsg())}") | |
507 | - | |
508 | - #TODO: : ร mettre dans la config | |
509 | - ''' | |
510 | - 'AgentDeviceTelescope1': 'AgentDeviceTelescopeGemini', | |
511 | - 'AgentDeviceFilterSelector1': 'AgentDeviceSBIG', | |
512 | - 'AgentDeviceShutter1': 'AgentDeviceSBIG', | |
513 | - 'AgentDeviceSensor1': 'AgentDeviceSBIG', | |
514 | - ''' | |
515 | - #self._my_client_agents = {} | |
516 | - | |
517 | - ### self._agent_logs = AgentLogs.objects.create(name=self.name, message="Step __init__") | |
518 | - #self.printdb("Step __init__") | |
440 | + # set real unit name (the current unit used) | |
441 | + if unit == "": | |
442 | + unit = oc.unit_name | |
443 | + | |
444 | + self.unit = unit | |
445 | + print(f"Agent name : {self.name}") | |
446 | + print(f"Unit name : {self.unit}") | |
447 | + self._set_agent_device_aliases_from_config(self.name) | |
448 | + self._set_mode_from_config(self.name) | |
519 | 449 | log.debug("Step __init__") |
520 | 450 | |
521 | 451 | self.TEST_COMMANDS = iter(self.TEST_COMMANDS_LIST) |
... | ... | @@ -523,12 +453,6 @@ class Agent: |
523 | 453 | self._set_status(self.STATUS_LAUNCH) |
524 | 454 | self._set_idle() |
525 | 455 | |
526 | - self._set_agent_device_aliases_from_config(self.name) | |
527 | - self._set_mode_from_config(self.name) | |
528 | - # TODO: remove | |
529 | - #self._set_idle() | |
530 | - self._set_active() | |
531 | - | |
532 | 456 | # Create 1st survey if none |
533 | 457 | #tmp = AgentSurvey.objects.filter(name=self.name) |
534 | 458 | #if len(tmp) == 0: |
... | ... | @@ -544,6 +468,134 @@ class Agent: |
544 | 468 | ("end Agent init") |
545 | 469 | |
546 | 470 | |
471 | + #def __init__(self, name:str="Agent", config_filename:str=None, RUN_IN_THREAD=True): | |
472 | + #def __init__(self, config_filename:str=None, RUN_IN_THREAD=True, DEBUG_MODE=False): | |
473 | + # def __init__(self, config_filename:str=None, RUN_IN_THREAD=True): | |
474 | + | |
475 | + # ''' | |
476 | + # print('PYROS_ENV', PYROS_ENV) | |
477 | + # print('ROOT_DIR', ROOT_DIR) | |
478 | + # print('DOC_DIR', DOC_DIR) | |
479 | + # ''' | |
480 | + | |
481 | + # # Set logger | |
482 | + # ##pyros_logger.set_logger_config() | |
483 | + # ##logg = logging.getLogger('pyroslogger') | |
484 | + # log.addHandler(handler_filebyagent(logging.INFO, self.__class__.__name__)) | |
485 | + | |
486 | + # log.debug("start Agent init") | |
487 | + | |
488 | + # # SET CONFIG INSTANCE | |
489 | + | |
490 | + # # - OLD CONFIG | |
491 | + # log.debug(f'config file is {config_filename}') | |
492 | + # ##log.info('PYROS_ENV', config.PYROS_ENV) | |
493 | + # log.debug('PYROS_ENV' + config_old.PYROS_ENV) | |
494 | + # log.debug('ROOT_DIR' + config_old.ROOT_DIR) | |
495 | + # log.debug('DOC_DIR' + config_old.DOC_DIR) | |
496 | + # ##if config.is_dev_env(): print("DEV ENV") | |
497 | + # if config_old.is_dev_env(): log.debug("DEV ENV") | |
498 | + # if config_old.is_prod_env(): log.debug("PROD ENV") | |
499 | + # if config_old.is_debug(): log.debug("IN DEBUG MODE") | |
500 | + | |
501 | + # # - NEW CONFIG | |
502 | + # obs_config_file_path = os.environ["PATH_TO_OBSCONF_FILE"] | |
503 | + # path_to_obs_config_folder = os.environ["PATH_TO_OBSCONF_FOLDER"] | |
504 | + # unit = os.environ["unit_name"] | |
505 | + # oc = OBSConfig(obs_config_file_path) | |
506 | + # self.set_config(oc, obs_config_file_path, path_to_obs_config_folder, unit) | |
507 | + # log.debug("Step __init__") | |
508 | + | |
509 | + # self.TEST_COMMANDS = iter(self.TEST_COMMANDS_LIST) | |
510 | + # self.RUN_IN_THREAD = RUN_IN_THREAD | |
511 | + # self._set_status(self.STATUS_LAUNCH) | |
512 | + # self._set_idle() | |
513 | + | |
514 | + # self._set_agent_device_aliases_from_config(self.name) | |
515 | + # self._set_mode_from_config(self.name) | |
516 | + # #self.name = name | |
517 | + # self.name = self.__class__.__name__ | |
518 | + | |
519 | + | |
520 | + # ''' | |
521 | + # printd("*** ENVIRONMENT VARIABLE PYROS_DEBUG is:", os.environ.get('PYROS_DEBUG'), '***') | |
522 | + # ##self.DEBUG_MODE = DEBUG_MODE | |
523 | + # self.DEBUG_MODE = os.environ.get('PYROS_DEBUG', '0')=='1' | |
524 | + # ''' | |
525 | + # #self.DEBUG_MODE = config.PYROS_ENV | |
526 | + # ##self.log = LogPyros(self.name, AgentLogs) | |
527 | + # ##self.DEBUG_MODE = config.is_debug() | |
528 | + # self.DEBUG_MODE = config_old.is_debug() | |
529 | + # ##self.log.debug_level = DEBUG_MODE | |
530 | + # ''' | |
531 | + # # Default LOG level is INFO | |
532 | + # log_level = LogPyros.LOG_LEVEL_INFO # INFO | |
533 | + # self.log.set_global_log_level(LogPyros.LOG_LEVEL_DEBUG) if self.DEBUG_MODE else self.log.set_global_log_level(log_level) | |
534 | + # ''' | |
535 | + # #global_log_level = LogPyros.LOG_LEVEL_DEBUG if self.DEBUG_MODE else self.PYROS_DEFAULT_GLOBAL_LOG_LEVEL | |
536 | + # ##global_log_level = LogPyros.LOG_LEVEL_DEBUG if self.DEBUG_MODE else config.PYROS_DEFAULT_GLOBAL_LOG_LEVEL | |
537 | + # ##global_log_level = LogPyros.LOG_LEVEL_DEBUG if self.DEBUG_MODE else config_old.PYROS_DEFAULT_GLOBAL_LOG_LEVEL | |
538 | + # ##self.log.set_global_log_level(global_log_level) | |
539 | + # ##self.printd("LOG LEVEL IS:", self.log.debug_level) | |
540 | + # ##self.print("LOG LEVEL IS:", self.log.get_global_log_level()) | |
541 | + | |
542 | + | |
543 | + # # ------------- OLD CONFIG ------------------- | |
544 | + # # Est-ce bien utile ??? | |
545 | + # # New way with PathLib | |
546 | + # # my_parent_abs_dir = Path(__file__).resolve().parent | |
547 | + # #TODO: on doit pouvoir faire mieux avec pathlib (sans utiliser str()) | |
548 | + # ##self._path_data = str( Path( str(my_parent_abs_dir).split(str(self.PYROS_DJANGO_BASE_DIR))[0] ) / self.CONFIG_DIR_NAME ) | |
549 | + # ##self._path_data = config.CONFIG_DIR | |
550 | + # # self._path_data = config_old.CONFIG_DIR | |
551 | + | |
552 | + # #self._set_mode(self.MODE_IDLE) | |
553 | + # # config_filename = self.get_config_filename(config_filename) | |
554 | + # #self.printd(f"*** Config file used is={config_filename}") | |
555 | + # # log.debug(f"*** Config file used is={config_filename}") | |
556 | + # # self.config = ConfigPyrosOld(config_filename) | |
557 | + # # if self.config.get_last_errno() != self.config.NO_ERROR: | |
558 | + # # raise Exception(f"Bad config file name '{config_filename}', error {str(self.config.get_last_errno())}: {str(self.config.get_last_errmsg())}") | |
559 | + | |
560 | + # #TODO: : ร mettre dans la config | |
561 | + # ''' | |
562 | + # 'AgentDeviceTelescope1': 'AgentDeviceTelescopeGemini', | |
563 | + # 'AgentDeviceFilterSelector1': 'AgentDeviceSBIG', | |
564 | + # 'AgentDeviceShutter1': 'AgentDeviceSBIG', | |
565 | + # 'AgentDeviceSensor1': 'AgentDeviceSBIG', | |
566 | + # ''' | |
567 | + # #self._my_client_agents = {} | |
568 | + | |
569 | + # ### self._agent_logs = AgentLogs.objects.create(name=self.name, message="Step __init__") | |
570 | + # #self.printdb("Step __init__") | |
571 | + # log.debug("Step __init__") | |
572 | + | |
573 | + # self.TEST_COMMANDS = iter(self.TEST_COMMANDS_LIST) | |
574 | + # self.RUN_IN_THREAD = RUN_IN_THREAD | |
575 | + # self._set_status(self.STATUS_LAUNCH) | |
576 | + # self._set_idle() | |
577 | + | |
578 | + # self._set_agent_device_aliases_from_config(self.name) | |
579 | + # self._set_mode_from_config(self.name) | |
580 | + # # TODO: remove | |
581 | + # #self._set_idle() | |
582 | + # self._set_active() | |
583 | + | |
584 | + # # Create 1st survey if none | |
585 | + # #tmp = AgentSurvey.objects.filter(name=self.name) | |
586 | + # #if len(tmp) == 0: | |
587 | + # #nb_agents = AgentSurvey.objects.filter(name=self.name).count() | |
588 | + # #if nb_agents == 0: | |
589 | + # if AgentSurvey.objects.filter(name=self.name).exists(): | |
590 | + # self._agent_survey = AgentSurvey.objects.get(name=self.name) | |
591 | + # else: | |
592 | + # self._agent_survey = AgentSurvey.objects.create(name=self.name, validity_duration=60, mode=self.mode, status=self.status, iteration=-1) | |
593 | + # log.debug("Agent survey is" + str(self._agent_survey)) | |
594 | + # #self.printd("Agent survey is", self._agent_survey) | |
595 | + | |
596 | + # ("end Agent init") | |
597 | + | |
598 | + | |
547 | 599 | |
548 | 600 | def set_config(self, oc: OBSConfig, obs_config_file_path: str, path_to_obs_config_folder: str, unit: str): |
549 | 601 | self._oc = { |
... | ... | @@ -727,7 +779,7 @@ class Agent: |
727 | 779 | # IF in test mode but with REAL devices (no SIMULATOR), delete all dangerous commands from the test commands list scenario: |
728 | 780 | if self.TEST_MODE: |
729 | 781 | log.debug("\n!!! In TEST mode !!! => preparing to run a scenario of test commands") |
730 | - log.debug("- Current test commands list scenario is:\n" + self.TEST_COMMANDS_LIST) | |
782 | + log.debug("- Current test commands list scenario is:\n" + str(self.TEST_COMMANDS_LIST)) | |
731 | 783 | if not self.WITH_SIMULATOR: |
732 | 784 | log.debug("\n!!! In TEST but no SIMULATOR mode (using REAL device) !!! => removing dangerous commands for real devices... :") |
733 | 785 | TEST_COMMANDS_LIST_copy = self.TEST_COMMANDS_LIST.copy() |
... | ... | @@ -1056,19 +1108,27 @@ class Agent: |
1056 | 1108 | ##self._my_client_agents[a] = self.config.get_paramvalue(a,'general','real_agent_device_name') |
1057 | 1109 | pass |
1058 | 1110 | |
1111 | + # new config (obsconfig) | |
1059 | 1112 | def _set_mode_from_config(self, agent_name): |
1060 | - # --- Get the startmode of the AgentX | |
1061 | - modestr = self.config.get_paramvalue(agent_name,'general','startmode') | |
1062 | - if self.config.get_last_errno() != self.config.NO_ERROR: | |
1063 | - raise Exception(f"error {str(self.config.get_last_errno())}: {str(self.config.get_last_errmsg())}") | |
1064 | - if (modestr == None): | |
1065 | - return True | |
1066 | - # --- Set the mode according the startmode value | |
1067 | - mode = self.MODE_IDLE | |
1068 | - if modestr.upper() == 'RUN': | |
1069 | - mode = self.MODE_ACTIVE | |
1113 | + # all agent are active ? | |
1114 | + | |
1115 | + mode = self.MODE_ACTIVE | |
1070 | 1116 | self._set_mode(mode) |
1071 | 1117 | return True |
1118 | + # old config | |
1119 | + # def _set_mode_from_config(self, agent_name): | |
1120 | + # # --- Get the startmode of the AgentX | |
1121 | + # modestr = self.config.get_paramvalue(agent_name,'general','startmode') | |
1122 | + # if self.config.get_last_errno() != self.config.NO_ERROR: | |
1123 | + # raise Exception(f"error {str(self.config.get_last_errno())}: {str(self.config.get_last_errmsg())}") | |
1124 | + # if (modestr == None): | |
1125 | + # return True | |
1126 | + # # --- Set the mode according the startmode value | |
1127 | + # mode = self.MODE_IDLE | |
1128 | + # if modestr.upper() == 'RUN': | |
1129 | + # mode = self.MODE_ACTIVE | |
1130 | + # self._set_mode(mode) | |
1131 | + # return True | |
1072 | 1132 | |
1073 | 1133 | |
1074 | 1134 | """ |
... | ... | @@ -1107,72 +1167,72 @@ class Agent: |
1107 | 1167 | |
1108 | 1168 | |
1109 | 1169 | # - OLD CONFIG |
1110 | - self.config.load() | |
1111 | - if self.config.get_last_errno() != self.config.NO_ERROR: | |
1112 | - raise Exception(f"error {str(self.config.get_last_errno())}: {str(self.config.get_last_errmsg())}") | |
1113 | - if not self.config.is_config_contents_changed(): | |
1114 | - return | |
1170 | + # self.config.load() | |
1171 | + # if self.config.get_last_errno() != self.config.NO_ERROR: | |
1172 | + # raise Exception(f"error {str(self.config.get_last_errno())}: {str(self.config.get_last_errmsg())}") | |
1173 | + # if not self.config.is_config_contents_changed(): | |
1174 | + # return | |
1115 | 1175 | |
1116 | 1176 | # === display informations |
1117 | 1177 | # --- Get the assembly aliases of the unit |
1118 | - assembled_mount_aliases = [] | |
1119 | - assembled_channel_aliases = [] | |
1120 | - assembled_aliases = [] | |
1121 | - unit_alias = self.config.get_aliases('unit')[0] | |
1122 | - params = self.config.get_params(unit_alias) | |
1123 | - for param in params: | |
1124 | - if param['section']=="assembly" and param['key']=="alias": | |
1125 | - assembled_aliases.append(param['value']) | |
1178 | + # assembled_mount_aliases = [] | |
1179 | + # assembled_channel_aliases = [] | |
1180 | + # assembled_aliases = [] | |
1181 | + # unit_alias = self.config.get_aliases('unit')[0] | |
1182 | + # params = self.config.get_params(unit_alias) | |
1183 | + # for param in params: | |
1184 | + # if param['section']=="assembly" and param['key']=="alias": | |
1185 | + # assembled_aliases.append(param['value']) | |
1126 | 1186 | #self.printd(f"Unit {unit_alias} is the assembly of {assembled_aliases}") |
1127 | 1187 | |
1128 | - log.debug("--------- Components of the unit -----------") | |
1129 | - log.debug("Configuration file is {}".format(self.config.get_configfile())) | |
1130 | - alias = self.config.get_aliases('unit')[0] | |
1131 | - namevalue = self.config.get_paramvalue(alias,'unit','description') | |
1132 | - log.debug(f"Unit alias is {alias}. Description is {namevalue}:") | |
1133 | - unit_subtags = self.config.get_unit_subtags() | |
1134 | - for unit_subtag in unit_subtags: | |
1135 | - aliases = self.config.get_aliases(unit_subtag) | |
1136 | - for alias in aliases: | |
1137 | - namevalue = self.config.get_paramvalue(alias,unit_subtag,'description') | |
1138 | - log.debug(f"- {unit_subtag} alias is {alias}. Description is {namevalue}") | |
1139 | - # --- fill the list of mount and channel assembled | |
1140 | - if alias in assembled_aliases: | |
1141 | - if unit_subtag=="mount": | |
1142 | - assembled_mount_aliases.append(alias) | |
1143 | - elif unit_subtag=="channel": | |
1144 | - assembled_channel_aliases.append(alias) | |
1145 | - | |
1146 | - log.debug("--------- Assembly of the unit -----------") | |
1147 | - log.debug(f"Assembled mount aliases: {assembled_mount_aliases}") | |
1148 | - log.debug(f"Assembled channel aliases: {assembled_channel_aliases}") | |
1188 | + # log.debug("--------- Components of the unit -----------") | |
1189 | + # log.debug("Configuration file is {}".format(self.config.get_configfile())) | |
1190 | + # alias = self.config.get_aliases('unit')[0] | |
1191 | + # namevalue = self.config.get_paramvalue(alias,'unit','description') | |
1192 | + # log.debug(f"Unit alias is {alias}. Description is {namevalue}:") | |
1193 | + # unit_subtags = self.config.get_unit_subtags() | |
1194 | + # for unit_subtag in unit_subtags: | |
1195 | + # aliases = self.config.get_aliases(unit_subtag) | |
1196 | + # for alias in aliases: | |
1197 | + # namevalue = self.config.get_paramvalue(alias,unit_subtag,'description') | |
1198 | + # log.debug(f"- {unit_subtag} alias is {alias}. Description is {namevalue}") | |
1199 | + # # --- fill the list of mount and channel assembled | |
1200 | + # if alias in assembled_aliases: | |
1201 | + # if unit_subtag=="mount": | |
1202 | + # assembled_mount_aliases.append(alias) | |
1203 | + # elif unit_subtag=="channel": | |
1204 | + # assembled_channel_aliases.append(alias) | |
1205 | + | |
1206 | + # log.debug("--------- Assembly of the unit -----------") | |
1207 | + # log.debug(f"Assembled mount aliases: {assembled_mount_aliases}") | |
1208 | + # log.debug(f"Assembled channel aliases: {assembled_channel_aliases}") | |
1149 | 1209 | |
1150 | 1210 | # --- Get the home of the mount[0] |
1151 | - mount_alias = assembled_mount_aliases[0] | |
1152 | - home = self.config.get_paramvalue(mount_alias,'MountPointing','home') | |
1153 | - | |
1154 | - log.debug("------------------------------------------") | |
1155 | - hostname = socket.gethostname() | |
1156 | - self._computer_alias = '' | |
1157 | - unit_subtag = 'computer' | |
1158 | - aliases = self.config.get_aliases(unit_subtag) | |
1159 | - for alias in aliases: | |
1160 | - log.debug("alias" + alias) | |
1161 | - value = self.config.get_paramvalue(alias,'local','hostname') | |
1162 | - log.debug("value" + value) | |
1163 | - if value == hostname: | |
1164 | - log.debug("value" + value) | |
1165 | - self._computer_alias = alias | |
1166 | - value = self.config.get_paramvalue(alias,unit_subtag,'description') | |
1167 | - self._computer_description = value | |
1168 | - value = self.config.get_paramvalue(alias,'path','data') | |
1169 | - # Overrides default value | |
1170 | - self._path_data = value | |
1171 | - break | |
1172 | - log.debug(f"hostname = {hostname}") | |
1173 | - log.debug(f"path_data = {self._path_data}") | |
1174 | - log.debug(f"home = {home}") | |
1175 | - log.debug("------------------------------------------") | |
1211 | + # mount_alias = assembled_mount_aliases[0] | |
1212 | + # home = self.config.get_paramvalue(mount_alias,'MountPointing','home') | |
1213 | + | |
1214 | + # log.debug("------------------------------------------") | |
1215 | + # hostname = socket.gethostname() | |
1216 | + # self._computer_alias = '' | |
1217 | + # unit_subtag = 'computer' | |
1218 | + # aliases = self.config.get_aliases(unit_subtag) | |
1219 | + # for alias in aliases: | |
1220 | + # log.debug("alias" + alias) | |
1221 | + # value = self.config.get_paramvalue(alias,'local','hostname') | |
1222 | + # log.debug("value" + value) | |
1223 | + # if value == hostname: | |
1224 | + # log.debug("value" + value) | |
1225 | + # self._computer_alias = alias | |
1226 | + # value = self.config.get_paramvalue(alias,unit_subtag,'description') | |
1227 | + # self._computer_description = value | |
1228 | + # value = self.config.get_paramvalue(alias,'path','data') | |
1229 | + # # Overrides default value | |
1230 | + # self._path_data = value | |
1231 | + # break | |
1232 | + # log.debug(f"hostname = {hostname}") | |
1233 | + # log.debug(f"path_data = {self._path_data}") | |
1234 | + # log.debug(f"home = {home}") | |
1235 | + # log.debug("------------------------------------------") | |
1176 | 1236 | |
1177 | 1237 | # --- update the log parameters |
1178 | 1238 | ##self.log.path_data = self._path_data |
... | ... | @@ -1760,7 +1820,7 @@ def extract_parameters(): |
1760 | 1820 | elif arg == "-s": WITH_SIM = True |
1761 | 1821 | elif arg == "-d": DEBUG_MODE = True |
1762 | 1822 | elif arg == "-v": VERBOSE_MODE = True |
1763 | - else: configfile = arg | |
1823 | + #else: configfile = arg | |
1764 | 1824 | ''' |
1765 | 1825 | if len(sys.argv) > 1: |
1766 | 1826 | if sys.argv[1] == "-t": |
... | ... | @@ -1770,19 +1830,28 @@ def extract_parameters(): |
1770 | 1830 | else: |
1771 | 1831 | configfile = sys.argv[1] |
1772 | 1832 | ''' |
1773 | - return DEBUG_MODE, WITH_SIM, TEST_MODE, VERBOSE_MODE, configfile | |
1833 | + #return DEBUG_MODE, WITH_SIM, TEST_MODE, VERBOSE_MODE, configfile | |
1834 | + return DEBUG_MODE, TEST_MODE, VERBOSE_MODE | |
1774 | 1835 | |
1775 | 1836 | #def build_agent(Agent_type:Agent, name="GenericAgent", RUN_IN_THREAD=True): |
1776 | 1837 | def build_agent(Agent_type:Agent, RUN_IN_THREAD=True): |
1777 | - DEBUG_MODE, WITH_SIM, TEST_MODE, VERBOSE_MODE, configfile = extract_parameters() | |
1838 | + #DEBUG_MODE, WITH_SIM, TEST_MODE, VERBOSE_MODE, configfile = extract_parameters() | |
1839 | + DEBUG_MODE, TEST_MODE, VERBOSE_MODE = extract_parameters() | |
1778 | 1840 | log.debug("debug mode is" + os.getenv("PYROS_DEBUG")) |
1779 | 1841 | |
1780 | 1842 | #print(logger) |
1781 | 1843 | |
1782 | 1844 | #agent = Agent("GenericAgent", configfile, RUN_IN_THREAD=True) |
1783 | 1845 | #agent = Agent_type(configfile, RUN_IN_THREAD, DEBUG_MODE=DEBUG_MODE) |
1784 | - agent = Agent_type(configfile, RUN_IN_THREAD) | |
1846 | + agent = Agent_type(RUN_IN_THREAD) | |
1847 | + # AgentSP isn't in a config, so to avoid that WITH_SIM returns an error it's a special case | |
1848 | + if agent.name == "AgentSP": | |
1849 | + agent._set_with_simulator(False) | |
1850 | + agent._set_test_mode(TEST_MODE) | |
1851 | + return agent | |
1785 | 1852 | #agent = Agent_type(name, configfile, RUN_IN_THREAD) |
1853 | + # Get the information of the agent name (name of class) within obsconfig and get the "is_real" attribute | |
1854 | + WITH_SIM = not agent.get_config().get_agent_information(agent.unit,agent.name)["is_real"] | |
1786 | 1855 | agent._set_with_simulator(WITH_SIM) |
1787 | 1856 | agent._set_test_mode(TEST_MODE) |
1788 | 1857 | #print(logger) | ... | ... |
src/core/pyros_django/monitoring/AgentM.py
... | ... | @@ -65,13 +65,18 @@ class AgentM(Agent): |
65 | 65 | FUNCTIONS RUN INSIDE MAIN THREAD |
66 | 66 | ================================================================= |
67 | 67 | """ |
68 | - | |
68 | + # old config | |
69 | 69 | # @override |
70 | 70 | #def __init__(self, name:str=None, config_filename=None, RUN_IN_THREAD=True): |
71 | - def __init__(self, config_filename=None, RUN_IN_THREAD=True): | |
72 | - ##if name is None: name = self.__class__.__name__ | |
73 | - super().__init__(config_filename, RUN_IN_THREAD) | |
74 | - | |
71 | + # def __init__(self, config_filename=None, RUN_IN_THREAD=True): | |
72 | + # ##if name is None: name = self.__class__.__name__ | |
73 | + # super().__init__(config_filename, RUN_IN_THREAD) | |
74 | + | |
75 | + # new config (obsconfig) | |
76 | + def __init__(self, name:str=None, RUN_IN_THREAD=True): | |
77 | + if name is None: | |
78 | + name = self.__class__.__name__ | |
79 | + super().__init__(RUN_IN_THREAD) | |
75 | 80 | # @override |
76 | 81 | def init(self): |
77 | 82 | super().init() |
... | ... | @@ -159,9 +164,11 @@ class AgentM(Agent): |
159 | 164 | status_plc = self.plcController.getStatus() |
160 | 165 | if self.parseNewStatus(status_plc): |
161 | 166 | self.saveWeather() |
167 | + #self.saveInternalMonitoring() | |
162 | 168 | |
163 | 169 | def parseNewStatus(self,status_plc): |
164 | 170 | # """ PM 20181009 parse new status for config |
171 | + # Find return string "plc_status" positin within status_plc | |
165 | 172 | if status_plc.find('PLC_STATUS') >= 0: |
166 | 173 | self.plc_checker.chk_config(status_plc) |
167 | 174 | return True |
... | ... | @@ -169,15 +176,27 @@ class AgentM(Agent): |
169 | 176 | |
170 | 177 | def saveWeather(self): |
171 | 178 | outside = WeatherWatch() |
179 | + inside = SiteWatch() | |
172 | 180 | for sensor in self.plc_checker.monitoring_names.keys(): |
173 | - value = self.plc_checker.get_sensor(sensor) | |
174 | - print(sensor, value) | |
175 | - outside.setAttribute(sensor, value) | |
181 | + if self.isInsideMonitoring(sensor): | |
182 | + value = self.plc_checker.get_sensor(sensor) | |
183 | + inside.setAttribute(sensor,value) | |
184 | + else: | |
185 | + value = self.plc_checker.get_sensor(sensor) | |
186 | + print(sensor, value) | |
187 | + outside.setAttribute(sensor, value) | |
188 | + | |
176 | 189 | outside.setGlobalStatus() |
177 | 190 | outside.save() |
191 | + inside.save() | |
178 | 192 | log.debug("saved weather") |
179 | 193 | |
180 | - | |
194 | + def isInsideMonitoring(self,key): | |
195 | + print(key) | |
196 | + if key in ("Power_input","Roof_state"): | |
197 | + return True | |
198 | + else: | |
199 | + return False | |
181 | 200 | # @override |
182 | 201 | def thread_exec_specific_cmd_main(self): |
183 | 202 | # This is optional | ... | ... |
src/core/pyros_django/scientific_program/AgentSP.py
... | ... | @@ -17,12 +17,24 @@ class AgentSP(Agent): |
17 | 17 | |
18 | 18 | period = None |
19 | 19 | |
20 | - def __init__(self, config_filename=None, RUN_IN_THREAD=True,use_db_test=False): | |
20 | + # old config init | |
21 | + # def __init__(self, config_filename=None, RUN_IN_THREAD=True,use_db_test=False): | |
22 | + # ##if name is None: name = self.__class__.__name__ | |
23 | + # if use_db_test: | |
24 | + # print("USE DB TEST") | |
25 | + # setup_test_environment() | |
26 | + # self.TEST_COMMANDS_LIST = [""] | |
27 | + # super().__init__(None, RUN_IN_THREAD) | |
28 | + # next_period = Period.objects.next_period() | |
29 | + # period = next_period | |
30 | + | |
31 | + # new init with obsconfig | |
32 | + def __init__(self, RUN_IN_THREAD=True,use_db_test=False): | |
21 | 33 | ##if name is None: name = self.__class__.__name__ |
22 | 34 | if use_db_test: |
23 | 35 | print("USE DB TEST") |
24 | 36 | setup_test_environment() |
25 | - super().__init__(None, RUN_IN_THREAD) | |
37 | + super().__init__(RUN_IN_THREAD) | |
26 | 38 | next_period = Period.objects.next_period() |
27 | 39 | period = next_period |
28 | 40 | |
... | ... | @@ -196,6 +208,7 @@ class AgentSP(Agent): |
196 | 208 | def routine_process_body(self): |
197 | 209 | print("routine automatic period workflow") |
198 | 210 | print(SP_PeriodWorkflow.objects.all()) |
211 | + print(PyrosUser.objects.all()) | |
199 | 212 | for sp_period_workflow in SP_PeriodWorkflow.objects.all(): |
200 | 213 | print(sp_period_workflow.period) |
201 | 214 | print(sp_period_workflow.action) |
... | ... | @@ -208,8 +221,12 @@ if __name__ == "__main__": |
208 | 221 | RUN_IN_THREAD=True |
209 | 222 | # with process |
210 | 223 | #RUN_IN_THREAD=False |
224 | + print("ARGV OF AGENT SP :",sys.argv) | |
211 | 225 | if len(sys.argv) > 1 and sys.argv[1] == "test": |
212 | - agent = AgentSP(None,RUN_IN_THREAD=RUN_IN_THREAD,use_db_test=True) | |
226 | + print("i'm in test") | |
227 | + agentSP = AgentSP(use_db_test=True) | |
228 | + agentSP.run() | |
229 | + #agent = build_agent(agentSP, RUN_IN_THREAD=True) | |
213 | 230 | else: |
214 | 231 | agent = build_agent(AgentSP, RUN_IN_THREAD=RUN_IN_THREAD) |
215 | 232 | ''' | ... | ... |