Skip to content

Commit

Permalink
Added more argument validation to csc_state_transition.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbovill committed Jan 17, 2024
1 parent 3f222e3 commit 4c27c6e
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions python/lsst/ts/IntegrationTests/csc_state_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,38 +56,41 @@ def __init__(
self.csc = csc
self.state = state
self.added_config = additional_configuration
self.temp_config["csc"] = self.csc
self.temp_config["state"] = self.state
temp_config = {}
temp_config["data"] = [self.csc, self.state]
if self.added_config:
self.temp_config["added_config"] = self.added_config
self.configs = (yaml.safe_dump(self.temp_config),)
temp_config["data"].append(self.added_config)
self.configs = (yaml.safe_dump(temp_config),)


def csc_state_transition() -> None:
# Define the lists of CSC and State options.
csc_list = list(BaseScript.cscs)
csc_list.sort()
state_list = list(BaseScript.csc_states)
state_list.sort()
# Define the script arguments.
parser = argparse.ArgumentParser()
parser.add_argument(
"csc",
metavar="csc",
nargs="?",
type=str.lower,
help="Specify which CSC to command (case insensitive).",
type=str,
choices=csc_list,
help="Specify which CSC to command (case sensitive).",
)
parser.add_argument(
"state",
metavar="state",
nargs="?",
type=str.lower,
choices=[
"standby",
"disabled",
"enabled",
"offline",
],
type=str.upper,
choices=state_list,
help="Specify to which state to transition.",
)
parser.add_argument(
"additional_configuration",
nargs="?",
type=str.lower,
type=str,
help="Specify any additional configurations.",
)
parser.add_argument(
Expand All @@ -102,6 +105,20 @@ def csc_state_transition() -> None:
if not (args.info or args.csc or args.state):
parser.print_help()
exit()
if args.info:
print(
f"\nThe allowed options are:\n"
f" csc:\t{csc_list}\n\n"
f" state:\t{state_list}\n"
)
exit()
if args.csc not in BaseScript.cscs:
print(
f"Invalid CSC: {args.csc}. "
f"Perhaps it is misspelled or not properly capitalized."
)
parser.print_help()
exit()
main(args)


Expand All @@ -121,6 +138,6 @@ def main(opts: argparse.Namespace) -> None:
print(
f"\nTransitioning the {opts.csc.upper()} "
f"to the {opts.state} state."
f"\nAdditional configuration: {opts.additional_configuration}."
f"\nConfiguration: {script_class.configs}."
)
asyncio.run(script_class.run())

0 comments on commit 4c27c6e

Please sign in to comment.