rail_pz_service.client.cli.wrappers module
Wrappers to create functions for the various parts of the CLI
These wrappers create functions that invoke interface functions that are defined in the db.row.RowMixin, db.node.NodeMixin, and db.element.ElementMixin classes.
These make it easier to define router functions that apply to all RowMixin, NodeMixin and ElementMixin classes.
- class rail_pz_service.client.cli.wrappers.CustomJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]
Bases:
JSONEncoderA custom JSON decoder that can serialize Enums.
- default(o)[source]
Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return super().default(o)
- Parameters:
o (Any)
- Return type:
Any
- rail_pz_service.client.cli.wrappers.download_command(group_command, sub_client_name)[source]
Return a function downloads a file
- Parameters:
group_command (Callable) – CLI decorator from the CLI group to attach to
sub_client_name (str) – Name of python API sub-client to use
- Returns:
Function that downloads a file
- Return type:
Callable
- rail_pz_service.client.cli.wrappers.get_create_command(group_command, sub_client_name, model_class, create_options)[source]
Return a function that creates a new row in the table and attaches that function to the cli.
- Parameters:
group_command (Callable) – CLI decorator from the CLI group to attach to
sub_client_name (str) – Name of python API sub-client to use
model_class (TypeAlias) – Pydantic model class
create_options (list[Callable]) – Command line options for the create function
- Returns:
the_function – Function that creates a row in the table
- Return type:
Callable
- rail_pz_service.client.cli.wrappers.get_delete_command(group_command, sub_client_name)[source]
Return a function that delets a row in the table and attaches that function to the cli.
- Parameters:
group_command (Callable) – CLI decorator from the CLI group to attach to
sub_client_name (str) – Name of python API sub-client to use
- Returns:
Function that deletes a row in the table
- Return type:
Callable
- rail_pz_service.client.cli.wrappers.get_list_command(group_command, sub_client_name, model_class)[source]
Return a function that gets all the rows from a table and attaches that function to the cli.
This version will provide a function that always returns all the rows
- Parameters:
group_command (Callable) – CLI decorator from the CLI group to attach to
sub_client_name (str) – Name of python API sub-client to use
model_class (TypeAlias) – Underlying database class
- Returns:
the_function – Function that return all the rows for the table in question
- Return type:
Callable
- rail_pz_service.client.cli.wrappers.get_row_attribute_list_command(group_command, sub_client_name, model_class, query)[source]
Return a function that gets the data_dict from a row in the table and attaches that function to the cli.
- Parameters:
group_command (Callable) – CLI decorator from the CLI group to attach to
sub_client_name (str) – Name of python API sub-client to use
model_class (TypeAlias)
query (str)
- Returns:
Function that returns the data_dict from a row
- Return type:
Callable
- rail_pz_service.client.cli.wrappers.get_row_by_name_command(group_command, sub_client_name, model_class)[source]
Return a function that gets a row from a table and attaches that function to the cli.
- Parameters:
group_command (Callable) – CLI decorator from the CLI group to attach to
sub_client_name (str) – Name of python API sub-client to use
model_class (TypeAlias) – Underlying database class
- Returns:
Function that returns the row for the table in question
- Return type:
Callable
- rail_pz_service.client.cli.wrappers.get_row_command(group_command, sub_client_name, model_class)[source]
Return a function that gets a row from a table and attaches that function to the cli.
- Parameters:
group_command (Callable) – CLI decorator from the CLI group to attach to
sub_client_name (str) – Name of python API sub-client to use
model_class (TypeAlias) – Underlying database class
- Returns:
Function that returns the row for the table in question
- Return type:
Callable
- rail_pz_service.client.cli.wrappers.output_pydantic_list(models, output, col_names)[source]
Render a sequences of objects as requested
- Parameters:
models (Sequence[BaseModel]) – Objects in question
output (OutputEnum | None) – Output format
col_names (list[str]) – Names for columns in tabular representation
- Return type:
None
- rail_pz_service.client.cli.wrappers.output_pydantic_object(model, output, col_names)[source]
Render a single object as requested
- Parameters:
model (BaseModel) – Object in question
output (OutputEnum | None) – Output format
col_names (list[str]) – Names for columns in tabular representation
- Return type:
None