RTC Toolkit 6.1.0-pre1
Loading...
Searching...
No Matches
cli.operations.Operations Class Reference

This class provides methods that implement the various sub-command operations of the command line interface. More...

Public Member Functions

 __init__ (self, ConfigurationManager config_manager)
 Initialise an Operations object with the configTool's configuration manager.
 
 reload_config (self)
 Refreshes the configuration managed by the configuration manager and updates the internal cached configuration.
 
 get_repository (self, str repo)
 Return the appropriate repository adapter based on the value of the repo option string.
 
 run_shell (self, str repo_name)
 Setup the repository object and enter a Python shell for interactive mode.
 
 list_datapoints (self, str repo_name, path, bool recursive)
 List all available datapoints and sub-paths found under a given path.
 
 get_datapoint (self, str repo_name, DataPointPath path, bool get_type, bool get_size, bool use_repr, object meta)
 Get and print the datapoint value or metadata to console.
 
 link_datapoint (self, str repo_name, DataPointPath target_path, DataPointPath link_path)
 Create or update a datapoint symlink.
 
 set_datapoint (self, str repo_name, DataPointPath path, str value, Optional[Any] requested_type=None, Optional[str] meta=None)
 Set a datapoint's value or metadata attribute.
 
 read_hierarchy (self, DataPointPath path, str output_path, Optional[str] repo_name=None, Optional[RepositoryIf] repo=None)
 Reads a datapoint or hierarchy from the repository and stores the data in local files.
 
 write_hierarchy (self, DataPointPath path, str input_path, Optional[str] repo_name=None, Optional[RepositoryIf] repo=None)
 Loads data from local files and writes them into the repository.
 
 delete_datapoints (self, str repo_name, DataPointPath path, bool recursive)
 Deletes a single datapoint or a whole hierarchy if recursive is set to True.
 
 populate_runtime_repository (self)
 Populate the Runtime Configuration Repository.
 
 validate_persistent_repository (self)
 Validate the structure and contents of the Persistent Configuration Repository.
 

Static Public Member Functions

 parse_value (str value, Optional[Any] requested_type=None)
 Parses a string value as a Python literal expression.
 

Public Attributes

 config_manager = config_manager
 

Protected Member Functions

 _log_repository_name (self, str repo)
 log the repository endpoint.
 
 _yaml_read_iterator (self, str input_file)
 A generator that iterates recursively over a YAML input file, returning (path, type, data) for each datapoint found in the file.
 
 _repo_iterator (self, RepositoryIf repo, DataPointPath path)
 A generator function to iterate recursively over an input repository datapoint path.
 
 _set_datapoint_force (self, RepositoryIf repo, DataPointPath path, data_type, data)
 Helper function used to set a datapoint in the repository.
 

Protected Attributes

 _config = self.config_manager.get_active_config_as_dataclass()
 
 _logger = CiiLogManager.get_logger()
 

Detailed Description

This class provides methods that implement the various sub-command operations of the command line interface.

Constructor & Destructor Documentation

◆ __init__()

cli.operations.Operations.__init__ ( self,
ConfigurationManager config_manager )

Initialise an Operations object with the configTool's configuration manager.

Parameters
config_managerShould be an instance of the tool's configuration manager.

Member Function Documentation

◆ _log_repository_name()

cli.operations.Operations._log_repository_name ( self,
str repo )
protected

log the repository endpoint.

◆ _repo_iterator()

cli.operations.Operations._repo_iterator ( self,
RepositoryIf repo,
DataPointPath path )
protected

A generator function to iterate recursively over an input repository datapoint path.

Yields (path, type, data) for each datapoint, where the path is the full path for the datapoint within the repository, type is the type of the datapoint as known by RepositoryIf, and data is the value of the datapoint.

◆ _set_datapoint_force()

cli.operations.Operations._set_datapoint_force ( self,
RepositoryIf repo,
DataPointPath path,
data_type,
data )
protected

Helper function used to set a datapoint in the repository.

The datapoint is created if it does not exist. If it exists with the wrong data type, it is deleted and recreated with the correct one. Otherwise, its value is simply updated.

◆ _yaml_read_iterator()

cli.operations.Operations._yaml_read_iterator ( self,
str input_file )
protected

A generator that iterates recursively over a YAML input file, returning (path, type, data) for each datapoint found in the file.

◆ delete_datapoints()

cli.operations.Operations.delete_datapoints ( self,
str repo_name,
DataPointPath path,
bool recursive )

Deletes a single datapoint or a whole hierarchy if recursive is set to True.

Parameters
repo_nameMust be "runtime" or "persistent", indicating the type of the repository.
pathThe path of the datapoint or hierarchy to delete.
recursiveIf True then all datapoints found under path are deleted recursively.

◆ get_datapoint()

cli.operations.Operations.get_datapoint ( self,
str repo_name,
DataPointPath path,
bool get_type,
bool get_size,
bool use_repr,
object meta )

Get and print the datapoint value or metadata to console.

If the get_type flag is used then the datapoint type is printed in the same format as is accepted by the –type argument. If the get_size flag is used then the datapoint size is printed. If the use_repr flag is True then the value of the datapoint is printed using Python 'repr', which produces a string representation compatible with Python literal syntax. If meta is specified, the datapoint metadata is returned instead of the value:

  • If meta is an empty string, all metadata fields are printed. The "type" field is printed in the human-readable type format, and the "timestamp" field is converted to an ISO 8601 datetime string.
  • If meta is a non-empty string, only the metadata field with that key is printed.
Parameters
repo_nameMust be "runtime" or "persistent", indicating the type of the repository.
pathThe path of the datapoint to read.
get_typeIf True then the datapoint type is printed instead.
get_sizeIf True then the size of the datapoint is printed instead.
use_reprIndicates if output should be compatible with Python literal syntax.
metaIf None, the datapoint value is printed. If an empty string, all metadata fields are printed. If a non-empty string, only the metadata field with that key is printed.

◆ get_repository()

cli.operations.Operations.get_repository ( self,
str repo )

Return the appropriate repository adapter based on the value of the repo option string.

Parameters
repoMust be "runtime" or "persistent", indicating the repository type to return.
Returns
An instance of RuntimeRepoIf or PersistentRepoIf depending on the value of repo.

◆ link_datapoint()

cli.operations.Operations.link_datapoint ( self,
str repo_name,
DataPointPath target_path,
DataPointPath link_path )

Create or update a datapoint symlink.

Creates a new symlink datapoint pointing to the target, or updates an existing symlink to point to a new target.

Parameters
repo_nameMust be "runtime" or "persistent", indicating type of the repository.
target_pathThe path of the datapoint target (the datapoint being linked to).
link_pathThe path of the datapoint link (the symlink to create or update).

◆ list_datapoints()

cli.operations.Operations.list_datapoints ( self,
str repo_name,
path,
bool recursive )

List all available datapoints and sub-paths found under a given path.

Parameters
repo_nameMust be "runtime" or "persistent", indicating the type of the repository.
pathThe path to the datapoint hierarchy to list.
recursiveIf True then we print all datapoints found under path recursively.

◆ parse_value()

cli.operations.Operations.parse_value ( str value,
Optional[Any] requested_type = None )
static

Parses a string value as a Python literal expression.

This will parse and return the given value and optionally try to convert to the requested RTC Toolkit type if given. requested_type should be one of the type classes from rtctk.framework or None. If None is used then the type is deduced from the value. In case it is not possible to deduce the type a BadParameter exception is thrown.

Parameters
valueThe input string with a Python literal to parse.
requested_typeOptional type that the return value should be converted to.
Returns
The parsed data object.

◆ populate_runtime_repository()

cli.operations.Operations.populate_runtime_repository ( self)

Populate the Runtime Configuration Repository.

This will copy the data from the Persistent Configuration Repository into the Runtime Configuration Repository using the same logic as RTC Supervisor.

◆ read_hierarchy()

cli.operations.Operations.read_hierarchy ( self,
DataPointPath path,
str output_path,
Optional[str] repo_name = None,
Optional[RepositoryIf] repo = None )

Reads a datapoint or hierarchy from the repository and stores the data in local files.

The datapoint or hierarchy of datapoints indicated by path are copied from the repository and written to the file or directory indicated by output_path. The output format used depends on the file extension used or if a directory has been given instead. The following output formats are supported:

  • FITS - if output_path ends in '.fits'.
  • YAML - if output_path ends in '.yaml'.
  • Directory layout compatible with PersistentRepoAdapter - if a directory is given.

The repository to access must be identified by either providing 'repo_name' or the adapter object directly with 'repo'.

Parameters
pathThe path of the datapoint or hierarchy to read from.
output_pathThe path of the output file or directory.
repo_nameName of the repository 'runtime' or 'persistent'.
repoThe repository adapter.

◆ reload_config()

cli.operations.Operations.reload_config ( self)

Refreshes the configuration managed by the configuration manager and updates the internal cached configuration.

◆ run_shell()

cli.operations.Operations.run_shell ( self,
str repo_name )

Setup the repository object and enter a Python shell for interactive mode.

Parameters
repo_nameMust be "runtime" or "persistent", indicating the type of the repository.

◆ set_datapoint()

cli.operations.Operations.set_datapoint ( self,
str repo_name,
DataPointPath path,
str value,
Optional[Any] requested_type = None,
Optional[str] meta = None )

Set a datapoint's value or metadata attribute.

If the datapoint does not exist, it is created with the type indicated by requested_type. If the datapoint already exists and requested_type is not None then it is first cross checked with the datapoint's actual type.

If the meta argument is provided, the value is parsed and written as a metadata attribute with the given key to the datapoint, rather than setting the datapoint's value directly.

Parameters
repo_nameMust be "runtime" or "persistent", indicating the type of the repository.
pathThe path of the datapoint to set or create.
valueThe value to set for the datapoint as a Python literal string, or the value to assign to the metadata attribute if meta is provided.
requested_typeThe data type of the new datapoint or metadata attribute.
metaIf None, the datapoint value is set. If a non-empty string, it is used as the key for a metadata attribute to write to the datapoint, with the parsed value as its value.

◆ validate_persistent_repository()

cli.operations.Operations.validate_persistent_repository ( self)

Validate the structure and contents of the Persistent Configuration Repository.

◆ write_hierarchy()

cli.operations.Operations.write_hierarchy ( self,
DataPointPath path,
str input_path,
Optional[str] repo_name = None,
Optional[RepositoryIf] repo = None )

Loads data from local files and writes them into the repository.

Data is read from the file or directory indicated by input_path and written to the corresponding datapoints into the repository under the given datapoint path hierarchy. The expected format of the input files depends on the file extension of input_path, or if it points to a directory. The following input formats are supported:

  • FITS - if input_path ends in '.fits'.
  • YAML - if input_path ends in '.yaml'.
  • Directory layout compatible with PersistentRepoAdapter - if a directory is given.

The repository to access must be identified by either providing 'repo_name' or the adapter object directly with 'repo'.

Parameters
pathThe path of the datapoint or hierarchy to write to.
input_pathThe path of the input file or directory.
repo_nameName of the repository 'runtime' or 'persistent'.
repoThe repository adapter.

Member Data Documentation

◆ _config

cli.operations.Operations._config = self.config_manager.get_active_config_as_dataclass()
protected

◆ _logger

cli.operations.Operations._logger = CiiLogManager.get_logger()
protected

◆ config_manager

cli.operations.Operations.config_manager = config_manager

The documentation for this class was generated from the following file: