Commit bf051e5f1ad79d5a10a85c45ed4f37c4e9bf8cdb

Authored by Etienne Pallier
1 parent c84c9d3b
Exists in dev

Premiers exemples de format de doc de fonction (Google/Numpy)

src/devices_controller/devices_controller_abstract_component/device_controller_abstract.py
@@ -249,7 +249,8 @@ class DeviceControllerAbstract(): @@ -249,7 +249,8 @@ class DeviceControllerAbstract():
249 def uncap_received_data(self, data_received:str): 249 def uncap_received_data(self, data_received:str):
250 return self.my_channel.uncap_received_data(data_received) 250 return self.my_channel.uncap_received_data(data_received)
251 ''' 251 '''
252 - 252 +
  253 +
253 def get_utc_date(self): 254 def get_utc_date(self):
254 return celme.Date("now").iso(0) 255 return celme.Date("now").iso(0)
255 #return celme.Date("now").ymdhms() 256 #return celme.Date("now").ymdhms()
@@ -257,13 +258,19 @@ class DeviceControllerAbstract(): @@ -257,13 +258,19 @@ class DeviceControllerAbstract():
257 258
258 def close(self): 259 def close(self):
259 self.my_channel.close() 260 self.my_channel.close()
260 -  
261 - def is_generic_cmd(self, raw_input_cmd:str):  
262 - ''' is this a generic command ?  
263 -  
264 - :param raw_input_cmd: like 'get ra' or 'set ra 20:00:00' or 'set radec 20:00:00 90:00:00" or 'do park' or 'do_park'...  
265 - :return either False or (cmd, [values]) with cmd like "get_ra" (using underscore '_' instead of space ' ')  
266 - ''' 261 +
  262 +
  263 + def is_generic_cmd(self, raw_input_cmd:str) -> bool:
  264 + # Using Google documentation format (https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html#example-google)
  265 + """ Is this a generic command ?
  266 +
  267 + Args:
  268 + raw_input_cmd: a command in raw string format (like 'get ra' or 'set ra 20:00:00' or 'set radec 20:00:00 90:00:00" or 'do park' or 'do_park'...)
  269 +
  270 + Returns:
  271 + either False or (cmd, [values]) with cmd like "get_ra" (using underscore '_' instead of space ' ').
  272 +
  273 + """
267 #return cmd.startswith('get_') or cmd.startswith('set_') or cmd.startswith('do_') 274 #return cmd.startswith('get_') or cmd.startswith('set_') or cmd.startswith('do_')
268 #cmds = ['get ', 'get_', 'set ', 'set_', 'do ', 'do_'] 275 #cmds = ['get ', 'get_', 'set ', 'set_', 'do ', 'do_']
269 ''' 276 '''
@@ -295,8 +302,8 @@ class DeviceControllerAbstract(): @@ -295,8 +302,8 @@ class DeviceControllerAbstract():
295 if len(cmd_splitted) > 2: values_to_set = cmd_splitted[2:] 302 if len(cmd_splitted) > 2: values_to_set = cmd_splitted[2:]
296 # ex: return "set_radec", ["20:00:00", "90:00:00"] 303 # ex: return "set_radec", ["20:00:00", "90:00:00"]
297 return generic_cmd, values_to_set 304 return generic_cmd, values_to_set
298 -  
299 - 305 +
  306 +
300 def execute_cmd(self, raw_input_cmd:str)->GenericResult: 307 def execute_cmd(self, raw_input_cmd:str)->GenericResult:
301 # GENERIC command 308 # GENERIC command
302 generic_cmd, values = self.is_generic_cmd(raw_input_cmd) 309 generic_cmd, values = self.is_generic_cmd(raw_input_cmd)
@@ -319,9 +326,19 @@ class DeviceControllerAbstract(): @@ -319,9 +326,19 @@ class DeviceControllerAbstract():
319 #print("NATIVE COMMAND") 326 #print("NATIVE COMMAND")
320 res_native = self.execute_native_cmd(raw_input_cmd) 327 res_native = self.execute_native_cmd(raw_input_cmd)
321 return GenericResult(res_native) 328 return GenericResult(res_native)
322 - 329 +
  330 +
323 #def execute_native_cmd(self, request:str, awaited_res_if_ok=None)->GenericResult: 331 #def execute_native_cmd(self, request:str, awaited_res_if_ok=None)->GenericResult:
324 - def execute_native_cmd(self, native_cmd:str)->str: 332 + def execute_native_cmd(self, native_cmd:str) -> str:
  333 + """ Execute a native command
  334 +
  335 + Args:
  336 + native_cmd: a native command
  337 +
  338 + Returns:
  339 + the command result
  340 +
  341 + """
325 print("NATIVE Command to send is "+ repr(native_cmd)) 342 print("NATIVE Command to send is "+ repr(native_cmd))
326 #self.send_request(native_cmd) 343 #self.send_request(native_cmd)
327 self.send_native_cmd(native_cmd) 344 self.send_native_cmd(native_cmd)
@@ -331,25 +348,31 @@ class DeviceControllerAbstract(): @@ -331,25 +348,31 @@ class DeviceControllerAbstract():
331 ok = True if not awaited_res_if_ok else (native_res == awaited_res_if_ok) 348 ok = True if not awaited_res_if_ok else (native_res == awaited_res_if_ok)
332 return GenericResult(native_res, ok) 349 return GenericResult(native_res, ok)
333 ''' 350 '''
334 - 351 +
  352 +
335 ''' 353 '''
336 def execute_native_cmd_OLD(self, request:str)->str: 354 def execute_native_cmd_OLD(self, request:str)->str:
337 self.send_request(request) 355 self.send_request(request)
338 native_res = self.receive_data() 356 native_res = self.receive_data()
339 return native_res 357 return native_res
340 ''' 358 '''
341 - def execute_unformated_native_cmd(self, request:str)->str: 359 +
  360 +
  361 + def execute_unformated_native_cmd(self, request:str) -> str:
342 request = self.formated_cmd(request) 362 request = self.formated_cmd(request)
343 #return self.execute_native_cmd_OLD(request) 363 #return self.execute_native_cmd_OLD(request)
344 return self.execute_native_cmd(request) 364 return self.execute_native_cmd(request)
345 365
  366 +
346 def send_native_cmd(self, native_cmd:str)->str: 367 def send_native_cmd(self, native_cmd:str)->str:
347 return self.send_data(native_cmd) 368 return self.send_data(native_cmd)
  369 +
  370 +
348 #@deprecated 371 #@deprecated
349 def send_request(self, request:str)->str: 372 def send_request(self, request:str)->str:
350 return self.send_native_cmd(request) 373 return self.send_native_cmd(request)
351 374
352 - 375 +
353 def print_available_commands(self): 376 def print_available_commands(self):
354 print("\nAvailable commands are:") 377 print("\nAvailable commands are:")
355 print("- GET commands:") 378 print("- GET commands:")
@@ -358,14 +381,17 @@ class DeviceControllerAbstract(): @@ -358,14 +381,17 @@ class DeviceControllerAbstract():
358 print (list(cmd.replace('_',' ') for cmd in self._cmd.keys() if cmd.startswith('set_'))) 381 print (list(cmd.replace('_',' ') for cmd in self._cmd.keys() if cmd.startswith('set_')))
359 print("- DO commands:") 382 print("- DO commands:")
360 print (list(cmd.replace('_',' ') for cmd in self._cmd.keys() if cmd.startswith('do_'))) 383 print (list(cmd.replace('_',' ') for cmd in self._cmd.keys() if cmd.startswith('do_')))
361 - 384 +
  385 +
362 def available_commands(self): 386 def available_commands(self):
363 return list(self._cmd.keys()) 387 return list(self._cmd.keys())
364 - 388 +
  389 +
365 # @abstract 390 # @abstract
366 def formated_cmd(self, cmd:str, value:str=None)->str: 391 def formated_cmd(self, cmd:str, value:str=None)->str:
367 return cmd 392 return cmd
368 - 393 +
  394 +
369 #def run_func(self, func, arg=None): 395 #def run_func(self, func, arg=None):
370 def run_func(self, func, *args): 396 def run_func(self, func, *args):
371 #print("args", args) 397 #print("args", args)
@@ -380,7 +406,7 @@ class DeviceControllerAbstract(): @@ -380,7 +406,7 @@ class DeviceControllerAbstract():
380 406
381 def execute_generic_cmd(self, generic_cmd:str, values_to_set:str=None)->str: 407 def execute_generic_cmd(self, generic_cmd:str, values_to_set:str=None)->str:
382 ''' Execute a generic command 408 ''' Execute a generic command
383 - 409 +
384 :param generic_cmd: str like "get_ra" or "set_ra" or "do_park"... 410 :param generic_cmd: str like "get_ra" or "set_ra" or "do_park"...
385 :param value: only for a "set_" cmd 411 :param value: only for a "set_" cmd
386 ''' 412 '''