Commit 8e15e89371420cf8b0e530192a3a8e29e450bc0f

Authored by Etienne Pallier
1 parent 1957c45d
Exists in dev

Renommé classes Command => AgentCmd et DeviceCommand => DeviceCmd

Et introduction de la nouvelle classe Cmd pour définir une nouvelle
commande
src/core/pyros_django/agent/Agent.py
@@ -115,7 +115,7 @@ import config @@ -115,7 +115,7 @@ import config
115 #from config import PYROS_ENV, ROOT_DIR, DOC_DIR 115 #from config import PYROS_ENV, ROOT_DIR, DOC_DIR
116 #from config import * 116 #from config import *
117 117
118 -from common.models import AgentSurvey, Command, AgentLogs 118 +from common.models import AgentSurvey, AgentCmd, AgentLogs
119 from config.configpyros import ConfigPyros 119 from config.configpyros import ConfigPyros
120 #from dashboard.views import get_sunelev 120 #from dashboard.views import get_sunelev
121 #from devices.TelescopeRemoteControlDefault import TelescopeRemoteControlDefault 121 #from devices.TelescopeRemoteControlDefault import TelescopeRemoteControlDefault
@@ -389,7 +389,7 @@ class Agent: @@ -389,7 +389,7 @@ class Agent:
389 _computer_description = '' 389 _computer_description = ''
390 390
391 # Current and next command to send 391 # Current and next command to send
392 - _cmdts:Command = None 392 + _cmdts:AgentCmd = None
393 _next_cmdts = None 393 _next_cmdts = None
394 394
395 _agent_survey = None 395 _agent_survey = None
@@ -606,7 +606,7 @@ class Agent: @@ -606,7 +606,7 @@ class Agent:
606 606
607 # Avoid blocking on false "running" commands 607 # Avoid blocking on false "running" commands
608 # (old commands that stayed with "running" status when agent was killed) 608 # (old commands that stayed with "running" status when agent was killed)
609 - Command.delete_commands_with_running_status_for_agent(self.name) 609 + AgentCmd.delete_commands_with_running_status_for_agent(self.name)
610 610
611 self._iter_num = 1 611 self._iter_num = 1
612 self._DO_MAIN_LOOP = True 612 self._DO_MAIN_LOOP = True
@@ -715,7 +715,7 @@ class Agent: @@ -715,7 +715,7 @@ class Agent:
715 N=5 715 N=5
716 if ((self._iter_num-1) % N) == 0: 716 if ((self._iter_num-1) % N) == 0:
717 self.print("Purging old commands if exists") 717 self.print("Purging old commands if exists")
718 - #Command.purge_old_commands_for_agent(self.name) 718 + #AgentCmd.purge_old_commands_for_agent(self.name)
719 self._purge_old_commands_sent_to_me() 719 self._purge_old_commands_sent_to_me()
720 720
721 # Get next command and process it (if exists) 721 # Get next command and process it (if exists)
@@ -778,14 +778,14 @@ class Agent: @@ -778,14 +778,14 @@ class Agent:
778 if self.TEST_MODE: 778 if self.TEST_MODE:
779 self.printd("[IN TEST MODE]") 779 self.printd("[IN TEST MODE]")
780 self.print("Flush previous commands to be sure to start in clean state") 780 self.print("Flush previous commands to be sure to start in clean state")
781 - Command.delete_pending_commands_for_agent(self.name) 781 + AgentCmd.delete_pending_commands_for_agent(self.name)
782 else: 782 else:
783 self.printd("[IN NORMAL MODE]") 783 self.printd("[IN NORMAL MODE]")
784 self.TEST_MAX_DURATION_SEC=None 784 self.TEST_MAX_DURATION_SEC=None
785 785
786 786
787 def _purge_old_commands_sent_to_me(self): 787 def _purge_old_commands_sent_to_me(self):
788 - Command.purge_old_commands_sent_to_agent(self.name) 788 + AgentCmd.purge_old_commands_sent_to_agent(self.name)
789 789
790 790
791 def _routine_process(self): 791 def _routine_process(self):
@@ -822,14 +822,14 @@ class Agent: @@ -822,14 +822,14 @@ class Agent:
822 ### 822 ###
823 COMMAND_PEREMPTION_DATE_FROM_NOW = datetime.utcnow() - timedelta(hours = self.COMMANDS_PEREMPTION_HOURS) 823 COMMAND_PEREMPTION_DATE_FROM_NOW = datetime.utcnow() - timedelta(hours = self.COMMANDS_PEREMPTION_HOURS)
824 #self.printd("peremption date", COMMAND_PEREMPTION_DATE_FROM_NOW) 824 #self.printd("peremption date", COMMAND_PEREMPTION_DATE_FROM_NOW)
825 - old_commands = Command.objects.filter( 825 + old_commands = AgentCmd.objects.filter(
826 # only commands for me 826 # only commands for me
827 recipient = self.name, 827 recipient = self.name,
828 # only pending commands 828 # only pending commands
829 sender_deposit_time__lt = COMMAND_PEREMPTION_DATE_FROM_NOW, 829 sender_deposit_time__lt = COMMAND_PEREMPTION_DATE_FROM_NOW,
830 ) 830 )
831 ### 831 ###
832 - old_commands = Command.get_old_commands_for_agent(self.name) 832 + old_commands = AgentCmd.get_old_commands_for_agent(self.name)
833 if old_commands.exists(): 833 if old_commands.exists():
834 self.printd("Found old commands to delete:") 834 self.printd("Found old commands to delete:")
835 for cmd in old_commands: self.printd(cmd) 835 for cmd in old_commands: self.printd(cmd)
@@ -1037,7 +1037,7 @@ class Agent: @@ -1037,7 +1037,7 @@ class Agent:
1037 """ 1037 """
1038 def send_command(self, cmd_name): 1038 def send_command(self, cmd_name):
1039 recipient_agent = self.name if self.TEST_COMMANDS_DEST=="myself" else self.TEST_COMMANDS_DEST 1039 recipient_agent = self.name if self.TEST_COMMANDS_DEST=="myself" else self.TEST_COMMANDS_DEST
1040 - Command.objects.create(sender=self.name, recipient=recipient_agent, name=cmd_name) 1040 + AgentCmd.objects.create(sender=self.name, recipient=recipient_agent, name=cmd_name)
1041 """ 1041 """
1042 #def send_command(self, to_agent, cmd_type, cmd_name, cmd_args=None): 1042 #def send_command(self, to_agent, cmd_type, cmd_name, cmd_args=None):
1043 def send_cmd_to(self, to_agent, cmd_name, cmd_args=None): 1043 def send_cmd_to(self, to_agent, cmd_name, cmd_args=None):
@@ -1045,19 +1045,19 @@ class Agent: @@ -1045,19 +1045,19 @@ class Agent:
1045 #ex: send_command(“AgentX”,”GENERIC”,”EVAL”,“3+4”) 1045 #ex: send_command(“AgentX”,”GENERIC”,”EVAL”,“3+4”)
1046 ex: send_command(“AgentX”,"EVAL”,“3+4”) 1046 ex: send_command(“AgentX”,"EVAL”,“3+4”)
1047 """ 1047 """
1048 - #return Command.send_cmd(self.name, self._get_real_agent_name_for_alias(to_agent), cmd_name, cmd_args) 1048 + #return AgentCmd.send_cmd(self.name, self._get_real_agent_name_for_alias(to_agent), cmd_name, cmd_args)
1049 cmd = self.create_cmd_for(to_agent, cmd_name, cmd_args) 1049 cmd = self.create_cmd_for(to_agent, cmd_name, cmd_args)
1050 cmd.send() 1050 cmd.send()
1051 return cmd 1051 return cmd
1052 1052
1053 - def create_cmd_for(self, to_agent, cmd_name, cmd_args=None)->Command: 1053 + def create_cmd_for(self, to_agent, cmd_name, cmd_args=None)->AgentCmd:
1054 ''' 1054 '''
1055 real_agent_name = self._get_real_agent_name(to_agent) 1055 real_agent_name = self._get_real_agent_name(to_agent)
1056 real_cmd_name = cmd_name 1056 real_cmd_name = cmd_name
1057 if '.' in real_agent_name: 1057 if '.' in real_agent_name:
1058 real_agent_name, component_name = real_agent_name.split('.') 1058 real_agent_name, component_name = real_agent_name.split('.')
1059 real_cmd_name = component_name+'.'+cmd_name 1059 real_cmd_name = component_name+'.'+cmd_name
1060 - return Command.create(self.name, real_agent_name, real_cmd_name, cmd_args) 1060 + return AgentCmd.create(self.name, real_agent_name, real_cmd_name, cmd_args)
1061 try: 1061 try:
1062 real_agent_name = self._get_real_agent_name(to_agent) 1062 real_agent_name = self._get_real_agent_name(to_agent)
1063 except KeyError as e: 1063 except KeyError as e:
@@ -1068,16 +1068,16 @@ class Agent: @@ -1068,16 +1068,16 @@ class Agent:
1068 #self.log_e("Exception raised", e) 1068 #self.log_e("Exception raised", e)
1069 self.log_e(f"=> Thus, I do not send this command '{cmd_name}'") 1069 self.log_e(f"=> Thus, I do not send this command '{cmd_name}'")
1070 return None 1070 return None
1071 - return Command.create(self.name, real_agent_name, cmd_name, cmd_args) 1071 + return AgentCmd.create(self.name, real_agent_name, cmd_name, cmd_args)
1072 ''' 1072 '''
1073 - return Command( 1073 + return AgentCmd(
1074 sender=self.name, 1074 sender=self.name,
1075 recipient=self._get_real_agent_name_for_alias(recipient_agent_alias_name), 1075 recipient=self._get_real_agent_name_for_alias(recipient_agent_alias_name),
1076 name=cmd_name 1076 name=cmd_name
1077 ) 1077 )
1078 ''' 1078 '''
1079 1079
1080 - def _get_next_valid_and_not_running_command(self)->Command: 1080 + def _get_next_valid_and_not_running_command(self)->AgentCmd:
1081 """ 1081 """
1082 Return next VALID (not expired) command (read from the DB command table) 1082 Return next VALID (not expired) command (read from the DB command table)
1083 which is relevant to this agent. 1083 which is relevant to this agent.
@@ -1091,13 +1091,13 @@ class Agent: @@ -1091,13 +1091,13 @@ class Agent:
1091 # but there might be a risk 1091 # but there might be a risk
1092 # that a command status is modified while we are reading... 1092 # that a command status is modified while we are reading...
1093 with transaction.atomic(): 1093 with transaction.atomic():
1094 - self._pending_commands = Command.get_pending_and_running_commands_for_agent(self.name) 1094 + self._pending_commands = AgentCmd.get_pending_and_running_commands_for_agent(self.name)
1095 commands = self._pending_commands 1095 commands = self._pending_commands
1096 if not commands.exists(): 1096 if not commands.exists():
1097 self.print("<None>") 1097 self.print("<None>")
1098 return None 1098 return None
1099 self.printd("Current pending (or running) commands are (time ordered):") 1099 self.printd("Current pending (or running) commands are (time ordered):")
1100 - Command.show_commands(commands) 1100 + AgentCmd.show_commands(commands)
1101 1101
1102 # 2) If there is a "do_exit" or "do_abort" command pending (even at the end of the list), 1102 # 2) If there is a "do_exit" or "do_abort" command pending (even at the end of the list),
1103 # which is VALID (not expired), 1103 # which is VALID (not expired),
@@ -1165,7 +1165,7 @@ class Agent: @@ -1165,7 +1165,7 @@ class Agent:
1165 1165
1166 1166
1167 #def _exec_agent_general_cmd(self, cmd:Command): 1167 #def _exec_agent_general_cmd(self, cmd:Command):
1168 - def _exec_agent_cmd(self, cmd:Command): 1168 + def _exec_agent_cmd(self, cmd:AgentCmd):
1169 1169
1170 #self.print(f"Starting execution of an AGENT LEVEL cmd {cmd}...") 1170 #self.print(f"Starting execution of an AGENT LEVEL cmd {cmd}...")
1171 self.print(f"Starting execution of an AGENT LEVEL cmd...") 1171 self.print(f"Starting execution of an AGENT LEVEL cmd...")
@@ -1210,7 +1210,7 @@ class Agent: @@ -1210,7 +1210,7 @@ class Agent:
1210 time.sleep(1) 1210 time.sleep(1)
1211 elif cmd_name in ("do_flush_commands"): 1211 elif cmd_name in ("do_flush_commands"):
1212 self.printd("flush_commands received: Delete all pending commands") 1212 self.printd("flush_commands received: Delete all pending commands")
1213 - Command.delete_pending_commands_for_agent(self.name) 1213 + AgentCmd.delete_pending_commands_for_agent(self.name)
1214 cmd.set_result('DONE') 1214 cmd.set_result('DONE')
1215 elif cmd_name in ("do_abort", "do_exit", "do_restart_init"): 1215 elif cmd_name in ("do_abort", "do_exit", "do_restart_init"):
1216 #self.printd("Current pending commands are:") 1216 #self.printd("Current pending commands are:")
@@ -1243,8 +1243,8 @@ class Agent: @@ -1243,8 +1243,8 @@ class Agent:
1243 # This "do_exit" should normally kill any current thread (to be checked...) 1243 # This "do_exit" should normally kill any current thread (to be checked...)
1244 if cmd.name == "do_exit": 1244 if cmd.name == "do_exit":
1245 self.print("Before exiting, Here are (if exists) the current (still) pending commands (time ordered) :") 1245 self.print("Before exiting, Here are (if exists) the current (still) pending commands (time ordered) :")
1246 - commands = Command.get_pending_and_running_commands_for_agent(self.name)  
1247 - Command.show_commands(commands, True) 1246 + commands = AgentCmd.get_pending_and_running_commands_for_agent(self.name)
  1247 + AgentCmd.show_commands(commands, True)
1248 #if self.TEST_MODE and self.TEST_WITH_FINAL_TEST and self.TEST_COMMANDS_DEST == "myself": self.simulator_test_results() 1248 #if self.TEST_MODE and self.TEST_WITH_FINAL_TEST and self.TEST_COMMANDS_DEST == "myself": self.simulator_test_results()
1249 if self.TEST_MODE and self.TEST_WITH_FINAL_TEST: 1249 if self.TEST_MODE and self.TEST_WITH_FINAL_TEST:
1250 self._TEST_test_results() 1250 self._TEST_test_results()
@@ -1264,14 +1264,14 @@ class Agent: @@ -1264,14 +1264,14 @@ class Agent:
1264 self.printd("Logging data...") 1264 self.printd("Logging data...")
1265 ''' 1265 '''
1266 1266
1267 - def exec_cmd_from_its_name(self, cmd:Command): 1267 + def exec_cmd_from_its_name(self, cmd:AgentCmd):
1268 func = cmd.name 1268 func = cmd.name
1269 if cmd.args: 1269 if cmd.args:
1270 return getattr(self, func)(*cmd.args) 1270 return getattr(self, func)(*cmd.args)
1271 else: 1271 else:
1272 return getattr(self, func)() 1272 return getattr(self, func)()
1273 1273
1274 - def is_agent_level_cmd(self, cmd:Command): 1274 + def is_agent_level_cmd(self, cmd:AgentCmd):
1275 return cmd.is_agent_general_cmd() or self._is_agent_specific_cmd(cmd) 1275 return cmd.is_agent_general_cmd() or self._is_agent_specific_cmd(cmd)
1276 1276
1277 ''' 1277 '''
@@ -1292,7 +1292,7 @@ class Agent: @@ -1292,7 +1292,7 @@ class Agent:
1292 self._exec_agent_specific_cmd(cmd) 1292 self._exec_agent_specific_cmd(cmd)
1293 ''' 1293 '''
1294 1294
1295 - def _is_agent_specific_cmd(self, cmd:Command): 1295 + def _is_agent_specific_cmd(self, cmd:AgentCmd):
1296 return cmd.name in self.AGENT_SPECIFIC_COMMANDS 1296 return cmd.name in self.AGENT_SPECIFIC_COMMANDS
1297 1297
1298 ''' 1298 '''
@@ -1318,12 +1318,12 @@ class Agent: @@ -1318,12 +1318,12 @@ class Agent:
1318 1318
1319 # to be overriden by subclass (AgentDevice) 1319 # to be overriden by subclass (AgentDevice)
1320 # @abstract 1320 # @abstract
1321 - def exec_device_cmd_if_possible(self, cmd:Command): 1321 + def exec_device_cmd_if_possible(self, cmd:AgentCmd):
1322 pass 1322 pass
1323 1323
1324 # TO BE OVERRIDEN by subclass (AgentDevice) 1324 # TO BE OVERRIDEN by subclass (AgentDevice)
1325 # @abstract 1325 # @abstract
1326 - def exec_device_cmd(self, cmd:Command): 1326 + def exec_device_cmd(self, cmd:AgentCmd):
1327 #self.exec_cmd_from_its_name(cmd) 1327 #self.exec_cmd_from_its_name(cmd)
1328 pass 1328 pass
1329 1329
@@ -1344,7 +1344,7 @@ class Agent: @@ -1344,7 +1344,7 @@ class Agent:
1344 def _set_test_mode(self, mode:bool): 1344 def _set_test_mode(self, mode:bool):
1345 self.TEST_MODE=mode 1345 self.TEST_MODE=mode
1346 1346
1347 - def _TEST_get_next_command_to_send(self)->Command: 1347 + def _TEST_get_next_command_to_send(self)->AgentCmd:
1348 cmd_full_name = next(self.TEST_COMMANDS, None) 1348 cmd_full_name = next(self.TEST_COMMANDS, None)
1349 #return cmd_name 1349 #return cmd_name
1350 if cmd_full_name is None: return None 1350 if cmd_full_name is None: return None
@@ -1519,8 +1519,8 @@ class Agent: @@ -1519,8 +1519,8 @@ class Agent:
1519 #commands = Command.get_last_N_commands_sent_to_agent(self.name, 16) 1519 #commands = Command.get_last_N_commands_sent_to_agent(self.name, 16)
1520 nb_commands = len(self.TEST_COMMANDS_LIST) 1520 nb_commands = len(self.TEST_COMMANDS_LIST)
1521 if "ad_unknown get_dec" in self.TEST_COMMANDS_LIST: nb_commands -= 1 1521 if "ad_unknown get_dec" in self.TEST_COMMANDS_LIST: nb_commands -= 1
1522 - commands = Command.get_last_N_commands_sent_by_agent(self.name, nb_commands)  
1523 - Command.show_commands(commands) 1522 + commands = AgentCmd.get_last_N_commands_sent_by_agent(self.name, nb_commands)
  1523 + AgentCmd.show_commands(commands)
1524 return nb_commands, commands 1524 return nb_commands, commands
1525 """ OLD SCENARIO 1525 """ OLD SCENARIO
1526 nb_asserted = 0 1526 nb_asserted = 0
src/core/pyros_django/agent/AgentDevice.py
@@ -10,13 +10,13 @@ import time @@ -10,13 +10,13 @@ import time
10 ##from .Agent import Agent 10 ##from .Agent import Agent
11 sys.path.append("..") 11 sys.path.append("..")
12 from agent.Agent import Agent, build_agent, StoppableThreadEvenWhenSleeping 12 from agent.Agent import Agent, build_agent, StoppableThreadEvenWhenSleeping
13 -from common.models import AgentDeviceStatus, Command, get_or_create_unique_row_from_model 13 +from common.models import AgentDeviceStatus, AgentCmd, get_or_create_unique_row_from_model
14 14
15 15
16 sys.path.append("../../..") 16 sys.path.append("../../..")
17 from device_controller.abstract_component.device_controller import ( 17 from device_controller.abstract_component.device_controller import (
18 DeviceController, 18 DeviceController,
19 - DeviceCommand, 19 + DeviceCmd,
20 DeviceTimeoutException, 20 DeviceTimeoutException,
21 UnknownGenericCmdException, UnimplementedGenericCmdException, DCCNotFoundException, UnknownNativeCmdException 21 UnknownGenericCmdException, UnimplementedGenericCmdException, DCCNotFoundException, UnknownNativeCmdException
22 ) 22 )
@@ -217,11 +217,11 @@ class AgentDevice(Agent): @@ -217,11 +217,11 @@ class AgentDevice(Agent):
217 """ 217 """
218 218
219 # @override superclass (Agent) method 219 # @override superclass (Agent) method
220 - def is_device_level_cmd(self, cmd:Command):  
221 - return self._device_ctrl.is_valid_cmd(DeviceCommand(cmd.full_name)) 220 + def is_device_level_cmd(self, cmd:AgentCmd):
  221 + return self._device_ctrl.is_valid_cmd(DeviceCmd(cmd.full_name))
222 222
223 - def is_device_generic_but_UNIMPLEMENTED_cmd(self, cmd:Command):  
224 - return self._device_ctrl.is_generic_but_UNIMPLEMENTED_cmd(DeviceCommand(cmd.full_name)) 223 + def is_device_generic_but_UNIMPLEMENTED_cmd(self, cmd:AgentCmd):
  224 + return self._device_ctrl.is_generic_but_UNIMPLEMENTED_cmd(DeviceCmd(cmd.full_name))
225 225
226 def _is_running_device_cmd(self): 226 def _is_running_device_cmd(self):
227 #return (self._current_device_cmd_thread is not None) or self._current_device_cmd_thread.is_alive() 227 #return (self._current_device_cmd_thread is not None) or self._current_device_cmd_thread.is_alive()
@@ -229,7 +229,7 @@ class AgentDevice(Agent): @@ -229,7 +229,7 @@ class AgentDevice(Agent):
229 return self._current_device_cmd_thread and self._current_device_cmd_thread.is_alive() 229 return self._current_device_cmd_thread and self._current_device_cmd_thread.is_alive()
230 230
231 # @override superclass (Agent) method 231 # @override superclass (Agent) method
232 - def exec_device_cmd_if_possible(self, cmd:Command): 232 + def exec_device_cmd_if_possible(self, cmd:AgentCmd):
233 233
234 self._set_status(self.STATUS_SPECIFIC_PROCESS) 234 self._set_status(self.STATUS_SPECIFIC_PROCESS)
235 #self.print(f"Starting execution of a DEVICE cmd {cmd}") 235 #self.print(f"Starting execution of a DEVICE cmd {cmd}")
@@ -567,7 +567,7 @@ class AgentDevice(Agent): @@ -567,7 +567,7 @@ class AgentDevice(Agent):
567 567
568 # This method is also called DIRECTLY from routine_process().get_device_status() (NOT FROM A THREAD) 568 # This method is also called DIRECTLY from routine_process().get_device_status() (NOT FROM A THREAD)
569 # @override parent class (Agent) 569 # @override parent class (Agent)
570 - def exec_device_cmd(self, cmd:Command): 570 + def exec_device_cmd(self, cmd:AgentCmd):
571 #cmd = self._current_device_cmd 571 #cmd = self._current_device_cmd
572 self.tprintd("*** DEVICE cmd name is", cmd.name) 572 self.tprintd("*** DEVICE cmd name is", cmd.name)
573 self.tprintd("*** PASS IT TO DEVICE TYPE", cmd.device_type) 573 self.tprintd("*** PASS IT TO DEVICE TYPE", cmd.device_type)
src/core/pyros_django/common/admin.py
@@ -233,7 +233,7 @@ class AlbumAdmin(PyrosModelAdmin): @@ -233,7 +233,7 @@ class AlbumAdmin(PyrosModelAdmin):
233 # Link the models to the admin interface 233 # Link the models to the admin interface
234 234
235 # (EP added 10/7/19) 235 # (EP added 10/7/19)
236 -admin.site.register(Command) 236 +admin.site.register(AgentCmd)
237 admin.site.register(AgentLogs) 237 admin.site.register(AgentLogs)
238 admin.site.register(AgentSurvey) 238 admin.site.register(AgentSurvey)
239 admin.site.register(AgentDeviceStatus) 239 admin.site.register(AgentDeviceStatus)
src/core/pyros_django/common/models.py
@@ -17,7 +17,7 @@ from model_utils import Choices @@ -17,7 +17,7 @@ from model_utils import Choices
17 # Project imports 17 # Project imports
18 # DeviceCommand is used by class Command 18 # DeviceCommand is used by class Command
19 sys.path.append("../../..") 19 sys.path.append("../../..")
20 -from src.device_controller.abstract_component.device_controller import DeviceCommand 20 +from src.device_controller.abstract_component.device_controller import DeviceCmd
21 21
22 ''' 22 '''
23 NOT USED - to be removed 23 NOT USED - to be removed
@@ -401,7 +401,7 @@ class Alert(Request): @@ -401,7 +401,7 @@ class Alert(Request):
401 401
402 402
403 403
404 -class Command(models.Model): 404 +class AgentCmd(models.Model):
405 405
406 """ 406 """
407 | id | sender | recipient | name | validity_duration (default=60) | s_deposit_time | r_read_time 407 | id | sender | recipient | name | validity_duration (default=60) | s_deposit_time | r_read_time
@@ -539,7 +539,7 @@ class Command(models.Model): @@ -539,7 +539,7 @@ class Command(models.Model):
539 #s_deposit_time__gte = cls.get_peremption_date_from_now(), 539 #s_deposit_time__gte = cls.get_peremption_date_from_now(),
540 ) 540 )
541 if running_commands: 541 if running_commands:
542 - Command.show_commands(running_commands) 542 + AgentCmd.show_commands(running_commands)
543 running_commands.delete() 543 running_commands.delete()
544 else: printd("<None>") 544 else: printd("<None>")
545 545
@@ -565,7 +565,7 @@ class Command(models.Model): @@ -565,7 +565,7 @@ class Command(models.Model):
565 s_deposit_time__lt = now_minus_2sec 565 s_deposit_time__lt = now_minus_2sec
566 ) 566 )
567 if pending_commands: 567 if pending_commands:
568 - Command.show_commands(pending_commands) 568 + AgentCmd.show_commands(pending_commands)
569 pending_commands.delete() 569 pending_commands.delete()
570 else: printd("<None>") 570 else: printd("<None>")
571 571
@@ -649,7 +649,7 @@ class Command(models.Model): @@ -649,7 +649,7 @@ class Command(models.Model):
649 else: printd("-", cmd.name, cmd) 649 else: printd("-", cmd.name, cmd)
650 650
651 651
652 - # -------------- Command INSTANCE METHODS -------------- 652 + # -------------- AgentCmd INSTANCE METHODS --------------
653 653
654 def __str__(self): 654 def __str__(self):
655 #return (f"Commmand '{self.name}' ({self.state}) sent by agent {self.sender} to agent {self.recipient} at {self.s_deposit_time}") 655 #return (f"Commmand '{self.name}' ({self.state}) sent by agent {self.sender} to agent {self.recipient} at {self.s_deposit_time}")
@@ -659,7 +659,7 @@ class Command(models.Model): @@ -659,7 +659,7 @@ class Command(models.Model):
659 @property 659 @property
660 def device_command(self): 660 def device_command(self):
661 if not self._device_command: 661 if not self._device_command:
662 - self._device_command = DeviceCommand(self.full_name) 662 + self._device_command = DeviceCmd(self.full_name)
663 #dc = self._device_command 663 #dc = self._device_command
664 #print("...DEVICE CMD:", dc.full_name, dc.name, dc.devtype, dc.args) 664 #print("...DEVICE CMD:", dc.full_name, dc.name, dc.devtype, dc.args)
665 return self._device_command 665 return self._device_command
src/core/pyros_django/monitoring/views.py
1 from django.http import HttpResponse 1 from django.http import HttpResponse
2 from django.shortcuts import render 2 from django.shortcuts import render
3 -from common.models import Command 3 +from common.models import AgentCmd
4 4
5 # Create your views here. 5 # Create your views here.
6 6
@@ -41,7 +41,7 @@ def weather_config_update(request): @@ -41,7 +41,7 @@ def weather_config_update(request):
41 # <class 'list'>: ['monitor_name_switch', 'None', 'Came:/S/N_A5EM:/Power_input', 'Rain_boolean'] 41 # <class 'list'>: ['monitor_name_switch', 'None', 'Came:/S/N_A5EM:/Power_input', 'Rain_boolean']
42 if "Error_code" in cmd_args: 42 if "Error_code" in cmd_args:
43 something = 5/0 43 something = 5/0
44 - Command.send_command('Dashboard', 'AgentM', cmd_name, cmd_args) 44 + AgentCmd.send_command('Dashboard', 'AgentM', cmd_name, cmd_args)
45 45
46 #TODO: Pour l'instant, on ne recupere pas encore ce retour 46 #TODO: Pour l'instant, on ne recupere pas encore ce retour
47 47
src/device_controller/abstract_component/device_controller.py
@@ -9,6 +9,7 @@ To be used as a base class (interface) for any concrete socket client telescope @@ -9,6 +9,7 @@ To be used as a base class (interface) for any concrete socket client telescope
9 # Standard library imports 9 # Standard library imports
10 #from enum import Enum 10 #from enum import Enum
11 import copy 11 import copy
  12 +from dataclasses import dataclass, field
12 import functools 13 import functools
13 #import inspect 14 #import inspect
14 import logging 15 import logging
@@ -18,6 +19,9 @@ import socket @@ -18,6 +19,9 @@ import socket
18 import sys 19 import sys
19 import threading 20 import threading
20 import time 21 import time
  22 +from typing import Dict
  23 +
  24 +
21 25
22 # Third party imports 26 # Third party imports
23 27
@@ -99,7 +103,7 @@ def recursive_search(f): @@ -99,7 +103,7 @@ def recursive_search(f):
99 return wrapped 103 return wrapped
100 104
101 105
102 -class DeviceCommand: 106 +class DeviceCmd:
103 107
104 full_name:str = '' 108 full_name:str = ''
105 name = None 109 name = None
@@ -141,7 +145,7 @@ class DeviceCommand: @@ -141,7 +145,7 @@ class DeviceCommand:
141 def is_generic(self): 145 def is_generic(self):
142 #return type(self).is_generic_cmd_name(self.full_name) 146 #return type(self).is_generic_cmd_name(self.full_name)
143 return self.is_generic_cmd_name(self.full_name) 147 return self.is_generic_cmd_name(self.full_name)
144 - #return DeviceCommand.is_generic_cmd_name(self.full_name) 148 + #return DeviceCmd.is_generic_cmd_name(self.full_name)
145 #return self.name.startswith('do_') or self.name.startswith('get_') or self.name.startswith('set_') 149 #return self.name.startswith('do_') or self.name.startswith('get_') or self.name.startswith('set_')
146 ''' 150 '''
147 151
@@ -251,11 +255,8 @@ class UnexpectedCommandReturnCode(Exception): @@ -251,11 +255,8 @@ class UnexpectedCommandReturnCode(Exception):
251 class DeviceTimeoutException(Exception): 255 class DeviceTimeoutException(Exception):
252 pass 256 pass
253 257
254 -#from dataclasses import dataclass, field  
255 -from typing import Dict  
256 258
257 259
258 -'''  
259 @dataclass 260 @dataclass
260 class Cmd: 261 class Cmd:
261 generic_name: str = 'generic name' 262 generic_name: str = 'generic name'
@@ -265,7 +266,6 @@ class Cmd: @@ -265,7 +266,6 @@ class Cmd:
265 final_simul_response: str = 'simulator response' 266 final_simul_response: str = 'simulator response'
266 immediate_responses: Dict[str, str] = field(default_factory=dict) 267 immediate_responses: Dict[str, str] = field(default_factory=dict)
267 errors: Dict[str, str] = field(default_factory=dict) 268 errors: Dict[str, str] = field(default_factory=dict)
268 -'''  
269 269
270 class Gen2NatCmds: 270 class Gen2NatCmds:
271 # To be set by constructor 271 # To be set by constructor
@@ -800,7 +800,7 @@ class DeviceController(): @@ -800,7 +800,7 @@ class DeviceController():
800 return dcc 800 return dcc
801 raise DCCNotFoundException("DEVICE CONTROLLER COMPONENT NOT FOUND: "+dc_component_type) 801 raise DCCNotFoundException("DEVICE CONTROLLER COMPONENT NOT FOUND: "+dc_component_type)
802 802
803 - def is_valid_cmd(self, cmd:DeviceCommand): 803 + def is_valid_cmd(self, cmd:DeviceCmd):
804 self.printd("cmd.name is", cmd.name) 804 self.printd("cmd.name is", cmd.name)
805 self.printd(cmd) 805 self.printd(cmd)
806 self.printd("generic ?", cmd.is_generic()) 806 self.printd("generic ?", cmd.is_generic())
@@ -811,23 +811,23 @@ class DeviceController(): @@ -811,23 +811,23 @@ class DeviceController():
811 self.is_valid_native_cmd(cmd) 811 self.is_valid_native_cmd(cmd)
812 ) 812 )
813 813
814 - def is_generic_but_UNIMPLEMENTED_cmd(self, cmd:DeviceCommand): 814 + def is_generic_but_UNIMPLEMENTED_cmd(self, cmd:DeviceCmd):
815 return cmd.is_generic() and not self.is_implemented_generic_cmd(cmd) 815 return cmd.is_generic() and not self.is_implemented_generic_cmd(cmd)
816 816
817 # WRAPPER methods 817 # WRAPPER methods
818 - def has_generic_cmd(self, cmd:DeviceCommand): 818 + def has_generic_cmd(self, cmd:DeviceCmd):
819 #return self._my_cmds.get(cmd.name) is not None 819 #return self._my_cmds.get(cmd.name) is not None
820 return cmd.name in self._my_cmds.get() 820 return cmd.name in self._my_cmds.get()
821 821
822 - def has_native_cmd(self, cmd:DeviceCommand)->bool: 822 + def has_native_cmd(self, cmd:DeviceCmd)->bool:
823 #return self._my_cmds.get(cmd.name) is not None 823 #return self._my_cmds.get(cmd.name) is not None
824 return self._my_cmds.has_native_cmd(cmd.name) 824 return self._my_cmds.has_native_cmd(cmd.name)
825 825
826 - def has_native_cmd_for_generic(self, generic_cmd:DeviceCommand): 826 + def has_native_cmd_for_generic(self, generic_cmd:DeviceCmd):
827 return self._my_cmds.get_native_infos_for_generic_cmd(generic_cmd.name) not in [None, []] 827 return self._my_cmds.get_native_infos_for_generic_cmd(generic_cmd.name) not in [None, []]
828 828
829 # check if generic cmd exists 829 # check if generic cmd exists
830 - def is_valid_generic_cmd(self, cmd:DeviceCommand): 830 + def is_valid_generic_cmd(self, cmd:DeviceCmd):
831 #printd("_my_cmds", self._my_cmds) 831 #printd("_my_cmds", self._my_cmds)
832 # 1) If a DCC given, return search result in this DCC commands 832 # 1) If a DCC given, return search result in this DCC commands
833 if cmd.devtype: 833 if cmd.devtype:
@@ -849,7 +849,7 @@ class DeviceController(): @@ -849,7 +849,7 @@ class DeviceController():
849 ''' 849 '''
850 850
851 # check if generic cmd exists and is implemented as a native cmd (in dictionary) 851 # check if generic cmd exists and is implemented as a native cmd (in dictionary)
852 - def is_implemented_generic_cmd(self, cmd:DeviceCommand): 852 + def is_implemented_generic_cmd(self, cmd:DeviceCmd):
853 self.printd("is implemented generic ?") 853 self.printd("is implemented generic ?")
854 self.printd("cmd.devtype", cmd.devtype) 854 self.printd("cmd.devtype", cmd.devtype)
855 #printd("_my_cmds", self._my_cmds) 855 #printd("_my_cmds", self._my_cmds)
@@ -877,7 +877,7 @@ class DeviceController(): @@ -877,7 +877,7 @@ class DeviceController():
877 return self.get_dc_component_for_type(cmd.devtype).has_native_cmd_for_generic(cmd) 877 return self.get_dc_component_for_type(cmd.devtype).has_native_cmd_for_generic(cmd)
878 ''' 878 '''
879 879
880 - def is_valid_native_cmd(self, cmd:DeviceCommand)->bool: 880 + def is_valid_native_cmd(self, cmd:DeviceCmd)->bool:
881 ##return self._my_cmds.is_valid_native_cmd(cmd.name) 881 ##return self._my_cmds.is_valid_native_cmd(cmd.name)
882 # 1) If a DCC given, return search result in this DCC commands 882 # 1) If a DCC given, return search result in this DCC commands
883 if cmd.devtype: 883 if cmd.devtype:
@@ -995,14 +995,14 @@ class DeviceController(): @@ -995,14 +995,14 @@ class DeviceController():
995 or 995 or
996 - FROM A THREAD from AgentDevice._thread_exec_specific_cmd().exec_specific_cmd() 996 - FROM A THREAD from AgentDevice._thread_exec_specific_cmd().exec_specific_cmd()
997 ''' 997 '''
998 - #def execute_cmd(self, cmd:DeviceCommand)->GenericResult: 998 + #def execute_cmd(self, cmd:DeviceCmd)->GenericResult:
999 def exec_cmd(self, raw_input_cmd:str)->GenericResult: 999 def exec_cmd(self, raw_input_cmd:str)->GenericResult:
1000 ''' 1000 '''
1001 :param raw_input_cmd: 1001 :param raw_input_cmd:
1002 ''' 1002 '''
1003 1003
1004 #generic_cmd, args = self.is_generic_cmd(raw_input_cmd) 1004 #generic_cmd, args = self.is_generic_cmd(raw_input_cmd)
1005 - cmd = DeviceCommand(raw_input_cmd) 1005 + cmd = DeviceCmd(raw_input_cmd)
1006 self.tprintd("cmd is", cmd, raw_input_cmd) 1006 self.tprintd("cmd is", cmd, raw_input_cmd)
1007 1007
1008 # GENERIC command (pyros grammar) 1008 # GENERIC command (pyros grammar)
@@ -1176,7 +1176,7 @@ class DeviceController(): @@ -1176,7 +1176,7 @@ class DeviceController():
1176 1176
1177 1177
1178 1178
1179 - #def exec_generic_cmd(self, generic_cmd:DeviceCommand)->str: 1179 + #def exec_generic_cmd(self, generic_cmd:DeviceCmd)->str:
1180 ##def exec_generic_cmd(self, generic_cmd:str, values_to_set:str=None, dcc_type:str=None)->str: 1180 ##def exec_generic_cmd(self, generic_cmd:str, values_to_set:str=None, dcc_type:str=None)->str:
1181 def exec_generic_cmd(self, generic_cmd:str, values_to_set:str=None)->str: 1181 def exec_generic_cmd(self, generic_cmd:str, values_to_set:str=None)->str:
1182 ''' Execute a generic command 1182 ''' Execute a generic command
src/device_controller/concrete_component/gemini/gemini_controller.py
@@ -22,7 +22,7 @@ from device_controller.abstract_component.device_controller import ( @@ -22,7 +22,7 @@ from device_controller.abstract_component.device_controller import (
22 printd, 22 printd,
23 DeviceController, 23 DeviceController,
24 Gen2NatCmds, 24 Gen2NatCmds,
25 - #Cmd, 25 + Cmd,
26 UnknownNativeCmdException, UnknownGenericCmdArgException 26 UnknownNativeCmdException, UnknownGenericCmdArgException
27 ) 27 )
28 28
@@ -346,7 +346,6 @@ class DC_Gemini(DeviceController): @@ -346,7 +346,6 @@ class DC_Gemini(DeviceController):
346 # 346 #
347 # VERSION 4 : Command class (Cmd) 347 # VERSION 4 : Command class (Cmd)
348 # 348 #
349 - '''  
350 get_ack2 = Cmd( 349 get_ack2 = Cmd(
351 #generic_name = 350 #generic_name =
352 'get_ack2', 351 'get_ack2',
@@ -370,7 +369,6 @@ class DC_Gemini(DeviceController): @@ -370,7 +369,6 @@ class DC_Gemini(DeviceController):
370 '1' : 'pb 1 ...', 369 '1' : 'pb 1 ...',
371 } 370 }
372 ) 371 )
373 - '''  
374 372
375 373
376 # Utilisation, affichage 374 # Utilisation, affichage