Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-41947: Add cli interface for all the various table operations in cm-service #15

Merged
merged 11 commits into from
Dec 21, 2023
258 changes: 256 additions & 2 deletions src/lsst/cmservice/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,138 @@ def scripts(
_output_pydantic_list(result, output, db.Script.col_names_for_table)


@get.command()
@options.cmclient()
@options.output()
def specifications(
client: CMClient,
output: options.OutputEnum | None,
) -> None:
"""List the existing specifications"""
result = client.get_specifications()
_output_pydantic_list(result, output, db.Specification.col_names_for_table)


@get.command()
@options.cmclient()
@options.output()
def spec_blocks(
client: CMClient,
output: options.OutputEnum | None,
) -> None:
"""List the existing spec blocks"""
result = client.get_spec_blocks()
_output_pydantic_list(result, output, db.SpecBlock.col_names_for_table)


@get.command()
@options.cmclient()
@options.output()
def script_templates(
client: CMClient,
output: options.OutputEnum | None,
) -> None:
"""List the existing script_templates"""
result = client.get_script_templates()
_output_pydantic_list(result, output, db.ScriptTemplate.col_names_for_table)


@get.command()
@options.cmclient()
@options.output()
def pipetask_error_types(
client: CMClient,
output: options.OutputEnum | None,
) -> None:
"""List the existing pipetask_error_types"""
result = client.get_pipetask_error_types()
_output_pydantic_list(result, output, db.PipetaskErrorType.col_names_for_table)


@get.command()
@options.cmclient()
@options.output()
def pipetask_errors(
client: CMClient,
output: options.OutputEnum | None,
) -> None:
"""List the existing pipetask_errors"""
result = client.get_pipetask_errors()
_output_pydantic_list(result, output, db.PipetaskError.col_names_for_table)


@get.command()
@options.cmclient()
@options.output()
def script_errors(
client: CMClient,
output: options.OutputEnum | None,
) -> None:
"""List the existing script_errors"""
result = client.get_script_errors()
_output_pydantic_list(result, output, db.ScriptError.col_names_for_table)


@get.command()
@options.cmclient()
@options.output()
def task_sets(
client: CMClient,
output: options.OutputEnum | None,
) -> None:
"""List the existing task_sets"""
result = client.get_task_sets()
_output_pydantic_list(result, output, db.TaskSet.col_names_for_table)


@get.command()
@options.cmclient()
@options.output()
def product_sets(
client: CMClient,
output: options.OutputEnum | None,
) -> None:
"""List the existing product_sets"""
result = client.get_product_sets()
_output_pydantic_list(result, output, db.ProductSet.col_names_for_table)


@get.command()
@options.cmclient()
@options.output()
def wms_task_reports(
client: CMClient,
output: options.OutputEnum | None,
) -> None:
"""List the existing task_reports"""
result = client.get_wms_task_reports()
_output_pydantic_list(result, output, db.WmsTaskReport.col_names_for_table)


@get.command()
@options.cmclient()
@options.output()
def script_dependencies(
client: CMClient,
output: options.OutputEnum | None,
) -> None:
"""List the existing script_dependencies"""
result = client.get_script_dependencies()
_output_pydantic_list(result, output, db.ScriptDependency.col_names_for_table)


@get.command()
@options.cmclient()
@options.output()
def step_dependencies(
client: CMClient,
output: options.OutputEnum | None,
) -> None:
"""List the existing step_dependencies"""
result = client.get_step_dependencies()
_output_pydantic_list(result, output, db.StepDependency.col_names_for_table)


@get.command()
@options.cmclient()
@options.fullname()
Expand Down Expand Up @@ -661,15 +793,26 @@ def load_specification(
_output_pydantic_object(result, output, db.Specification.col_names_for_table)


@load.command()
@load.command(name="campaign")
@options.cmclient()
@options.output()
@options.yaml_file()
@options.name()
@options.parent_name()
@options.spec_name()
@options.spec_block_name()
@options.handler()
@options.data()
@options.child_config()
@options.collections()
@options.spec_aliases()
def load_campaign(
client: CMClient,
output: options.OutputEnum | None,
**kwargs: Any,
) -> None:
"""Load a Specification from a yaml file and make a Campaign"""
result = client.load_campaign()
result = client.load_campaign(**kwargs)
_output_pydantic_object(result, output, db.Campaign.col_names_for_table)


Expand Down Expand Up @@ -807,3 +950,114 @@ def rematch(
"""Rematch the errors"""
result = client.rematch_errors(**kwargs)
_output_pydantic_list(result, output, db.PipetaskError.col_names_for_table)


@main.group()
def manage() -> None:
"""manage the DB directly"""


@manage.group()
def production() -> None:
"""Manage production table"""


@production.command(name="create")
@options.cmclient()
@options.name()
@options.output()
def production_create(
client: CMClient,
output: options.OutputEnum | None,
**kwargs: Any,
) -> None:
"""Create a production"""
result = client.production_create(**kwargs)
_output_pydantic_object(result, output, db.Production.col_names_for_table)


@production.command(name="update")
@options.cmclient()
@options.id()
@options.name()
@options.output()
def prodcution_update(
client: CMClient,
output: options.OutputEnum | None,
id: int,
**kwargs: Any,
) -> None:
"""Update a production"""
result = client.production_update(id, **kwargs)
_output_pydantic_object(result, output, db.Production.col_names_for_table)


@production.command(name="delete")
@options.cmclient()
@options.id()
def prodcution_delete(
client: CMClient,
id: int,
) -> None:
"""Update a production"""
client.production_delete(id)


@manage.group(name="campaign")
def campaign_command() -> None:
"""Manage production table"""


@campaign_command.command(name="create")
@options.cmclient()
@options.name()
@options.parent_name()
@options.spec_block_name()
@options.data()
@options.child_config()
@options.collections()
@options.spec_aliases()
@options.handler()
@options.output()
def campagin_create(
client: CMClient,
output: options.OutputEnum | None,
**kwargs: Any,
) -> None:
"""Create a campaign"""
result = client.campaign_create(**kwargs)
_output_pydantic_object(result, output, db.Campaign.col_names_for_table)


@campaign_command.command(name="update")
@options.cmclient()
@options.name()
@options.parent_name()
@options.spec_block_name()
@options.data()
@options.child_config()
@options.collections()
@options.spec_aliases()
@options.handler()
@options.output()
@options.id()
def campaign_update(
client: CMClient,
output: options.OutputEnum | None,
id: int,
**kwargs: Any,
) -> None:
"""Update a campaign"""
result = client.campaign_update(id, **kwargs)
_output_pydantic_object(result, output, db.Campaign.col_names_for_table)


@campaign_command.command(name="delete")
@options.cmclient()
@options.id()
def campaign_delete(
client: CMClient,
id: int,
) -> None:
"""Delete a campaign"""
client.campaign_delete(id)
59 changes: 57 additions & 2 deletions src/lsst/cmservice/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,25 @@
from ..common.enums import NodeTypeEnum, StatusEnum

__all__ = [
"child_configs",
"cmclient",
"output",
"OutputEnum",
"collections",
"child_config",
"child_configs",
"data",
"fullname",
"id",
"handler",
"name",
"node_type",
"parent_name",
"parent_id",
"rematch",
"script_name",
"spec_name",
"spec_block_name",
"spec_aliases",
"status",
"update_dict",
"yaml_file",
Expand Down Expand Up @@ -140,12 +148,33 @@ class OutputEnum(Enum):
json = auto()


collections = PartialOption(
"--collections",
type=DictParamType(),
help="collections values to update",
)

child_configs = PartialOption(
"--child_configs",
type=dict,
help="Configuration to use for creating new Elements.",
help="child_configurations",
)


child_config = PartialOption(
"--child_config",
type=DictParamType(),
help="child_config values to update",
)


data = PartialOption(
"--data",
type=DictParamType(),
help="data values to update",
)


output = PartialOption(
"--output",
"-o",
Expand Down Expand Up @@ -174,6 +203,17 @@ class OutputEnum(Enum):
help="ID of parent object in DB.",
)

handler = PartialOption("--handler", type=str, help="Name of object")


id = PartialOption(
"--id",
type=int,
help="ID of object.",
)

name = PartialOption("--name", type=str, help="Name of object")

node_type = PartialOption(
"--node_type",
type=EnumChoice(NodeTypeEnum),
Expand Down Expand Up @@ -205,6 +245,21 @@ class OutputEnum(Enum):
help="Name of the specification",
)


spec_block_name = PartialOption(
"--spec_block_name",
type=str,
help="Name of the SpecBlock",
)


spec_aliases = PartialOption(
"--spec_aliases",
type=DictParamType(),
help="Spec aliases to update",
)


update_dict = PartialOption(
"--update_dict",
type=DictParamType(),
Expand Down
Loading