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 249 def uncap_received_data(self, data_received:str):
250 250 return self.my_channel.uncap_received_data(data_received)
251 251 '''
252   -
  252 +
  253 +
253 254 def get_utc_date(self):
254 255 return celme.Date("now").iso(0)
255 256 #return celme.Date("now").ymdhms()
... ... @@ -257,13 +258,19 @@ class DeviceControllerAbstract():
257 258  
258 259 def close(self):
259 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 274 #return cmd.startswith('get_') or cmd.startswith('set_') or cmd.startswith('do_')
268 275 #cmds = ['get ', 'get_', 'set ', 'set_', 'do ', 'do_']
269 276 '''
... ... @@ -295,8 +302,8 @@ class DeviceControllerAbstract():
295 302 if len(cmd_splitted) > 2: values_to_set = cmd_splitted[2:]
296 303 # ex: return "set_radec", ["20:00:00", "90:00:00"]
297 304 return generic_cmd, values_to_set
298   -
299   -
  305 +
  306 +
300 307 def execute_cmd(self, raw_input_cmd:str)->GenericResult:
301 308 # GENERIC command
302 309 generic_cmd, values = self.is_generic_cmd(raw_input_cmd)
... ... @@ -319,9 +326,19 @@ class DeviceControllerAbstract():
319 326 #print("NATIVE COMMAND")
320 327 res_native = self.execute_native_cmd(raw_input_cmd)
321 328 return GenericResult(res_native)
322   -
  329 +
  330 +
323 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 342 print("NATIVE Command to send is "+ repr(native_cmd))
326 343 #self.send_request(native_cmd)
327 344 self.send_native_cmd(native_cmd)
... ... @@ -331,25 +348,31 @@ class DeviceControllerAbstract():
331 348 ok = True if not awaited_res_if_ok else (native_res == awaited_res_if_ok)
332 349 return GenericResult(native_res, ok)
333 350 '''
334   -
  351 +
  352 +
335 353 '''
336 354 def execute_native_cmd_OLD(self, request:str)->str:
337 355 self.send_request(request)
338 356 native_res = self.receive_data()
339 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 362 request = self.formated_cmd(request)
343 363 #return self.execute_native_cmd_OLD(request)
344 364 return self.execute_native_cmd(request)
345 365  
  366 +
346 367 def send_native_cmd(self, native_cmd:str)->str:
347 368 return self.send_data(native_cmd)
  369 +
  370 +
348 371 #@deprecated
349 372 def send_request(self, request:str)->str:
350 373 return self.send_native_cmd(request)
351 374  
352   -
  375 +
353 376 def print_available_commands(self):
354 377 print("\nAvailable commands are:")
355 378 print("- GET commands:")
... ... @@ -358,14 +381,17 @@ class DeviceControllerAbstract():
358 381 print (list(cmd.replace('_',' ') for cmd in self._cmd.keys() if cmd.startswith('set_')))
359 382 print("- DO commands:")
360 383 print (list(cmd.replace('_',' ') for cmd in self._cmd.keys() if cmd.startswith('do_')))
361   -
  384 +
  385 +
362 386 def available_commands(self):
363 387 return list(self._cmd.keys())
364   -
  388 +
  389 +
365 390 # @abstract
366 391 def formated_cmd(self, cmd:str, value:str=None)->str:
367 392 return cmd
368   -
  393 +
  394 +
369 395 #def run_func(self, func, arg=None):
370 396 def run_func(self, func, *args):
371 397 #print("args", args)
... ... @@ -380,7 +406,7 @@ class DeviceControllerAbstract():
380 406  
381 407 def execute_generic_cmd(self, generic_cmd:str, values_to_set:str=None)->str:
382 408 ''' Execute a generic command
383   -
  409 +
384 410 :param generic_cmd: str like "get_ra" or "set_ra" or "do_park"...
385 411 :param value: only for a "set_" cmd
386 412 '''
... ...