CscCommander¶
-
class
lsst.ts.salobj.CscCommander(name, index=0, exclude=None, fields_to_ignore=('ignored', 'value', 'priority'))¶ Bases:
objectCommand a CSC from the command line.
Parameters: - name :
str SAL component name of CSC.
- index :
int(optional) SAL index of CSC.
- exclude :
List[str] orNone(optional) Names of telemetry or event topics to not print. If
Noneor empty then no topics are excluded.- fields_to_ignore :
List[str] (optional) SAL topic fields to ignore when specifying command parameters, and when printing events and telemetry.
Notes
Warning: use with caution. Running a commander may interfere with telescope operations! If you provide a command-line script in
bin/that runs a commander, consider picking a name that is obscure and not easily confused with the script that runs the CSC.Subclasses may provide overrides as follows:
- do_<command_name> overrides sending the specified command. It receives one argument: a list of string arguments. This can be useful for complicated commands, such as commands with array parameters.
- evt_<event_name>_callback overrides handling data for the specified event (usually this just mean printing the data). It receives one argument: the DDS sample.
- tel_<event_name>_callback overrides handling data for the specified telemetry topic (usually this just involves printing the data). It receives one argument: the DDS sample. This can be useful if the default is too chatty.
I have not found a way to write a unit test for this class. I tried running a commander in a subprocess but could not figure out how to send multiple commands (the
suprocess.communicatemethod only allows sending one item of data). Instead I suggest manually running it to control the Test CSC.Methods Summary
add_arguments(parser)Add arguments to the parser created by make_from_cmd_line.add_kwargs_from_args(args, kwargs)Add constructor keyword arguments based on parsed arguments. amain(**kwargs)Construct the commander and run it. check_arguments(args, *names)Check that the required arguments are provided, and return them as a keyword argument dict with cast values. close()Close the commander, prior to quitting. do_start(args)Allow the start command to have no arguments. event_callback(data, name)Generic callback for events. evt_summaryState_callback(data)field_is_public(name)Return True if the specified field name is public, False otherwise. format_data(data)Format an event or telemetry sample for printing. format_item(key, value)Format one event or telemetry field for printing. get_commands_help()Get help for each command, as a list of strings. get_public_data(data)Return a dict of field_name: value for public fields. get_rounded_public_fields(data)Get the public fields for a sample, with float values rounded. make_from_cmd_line(index, **kwargs)Construct a SAL-related class from command line arguments. print_help()Print help. run_command(command_name, args)Run a command that takes only scalar arguments. telemetry_callback(data, name)Generic callback for telemetry. Methods Documentation
-
classmethod
add_arguments(parser)¶ Add arguments to the parser created by
make_from_cmd_line.Parameters: - parser :
argparse.ArgumentParser The argument parser.
Notes
If you override this method then you should almost certainly override
add_kwargs_from_argsas well.- parser :
-
classmethod
add_kwargs_from_args(args, kwargs)¶ Add constructor keyword arguments based on parsed arguments.
Parameters: - args :
argparse.namespace Parsed command.
- kwargs :
dict Keyword argument dict for the constructor. Update this based on
args. The index argument will already be present if relevant.
Notes
If you override this method then you should almost certainly override
add_argumentsas well.- args :
-
classmethod
amain(**kwargs)¶ Construct the commander and run it.
Parse the command line to construct the commander, then parse and execute commands until the
exitis seen.
-
check_arguments(args, *names)¶ Check that the required arguments are provided, and return them as a keyword argument dict with cast values.
Parameters: - args :
List[str] Command arguments, as strings.
- *names :
List[strortuple] Argument name and optional cast function. Each element is either:
- An argument name, in which case the argument is cast to a float
- A tuple of (name, cast function), in which case the argument
- is cast using the cast function.
- args :
-
close()¶ Close the commander, prior to quitting.
-
do_start(args)¶ Allow the start command to have no arguments.
-
event_callback(data, name)¶ Generic callback for events.
You may provide evt_<event_name> methods to override printing of specific events.
-
evt_summaryState_callback(data)¶
-
field_is_public(name)¶ Return True if the specified field name is public, False otherwise.
-
format_data(data)¶ Format an event or telemetry sample for printing.
-
format_item(key, value)¶ Format one event or telemetry field for printing.
-
get_commands_help()¶ Get help for each command, as a list of strings.
-
get_public_data(data)¶ Return a dict of field_name: value for public fields.
Parameters: - data :
dds_sample DDS sample.
- data :
-
get_rounded_public_fields(data)¶ Get the public fields for a sample, with float values rounded.
-
classmethod
make_from_cmd_line(index, **kwargs)¶ Construct a SAL-related class from command line arguments.
Parameters: - index :
int,True,FalseorNone If the SAL component is indexed: specify
Trueto make index a required command line argument, or specify a non-zerointto use that index. If the SAL component is not indexed: specifyNoneor 0.- **kwargs :
dict(optional) Additional keyword arguments for your class’s constructor. If any arguments match those from the command line the command line values will be used.
Returns: - instance :
cls The constructed instance.
Notes
To add additional command-line arguments, override
add_argumentsandadd_kwargs_from_args.- index :
-
print_help()¶ Print help.
-
run_command(command_name, args)¶ Run a command that takes only scalar arguments.
Parameters:
-
telemetry_callback(data, name)¶ Generic callback for telemetry.
You may provide tel_<telemetry_name> methods to override printing of specific telemetry topics.
- name :