-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e89c0d9
commit c2956d9
Showing
6 changed files
with
166 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import typer | ||
import os | ||
from typing import Optional | ||
|
||
from aerie_cli.commands.command_context import CommandContext | ||
|
||
app = typer.Typer() | ||
|
||
def _get_name_and_ext(path: str): | ||
path = path.strip() | ||
filename = os.path.basename(path) | ||
return os.path.splitext(filename) | ||
|
||
@app.command() | ||
def new( | ||
path: str = typer.Argument(default=...), | ||
description: Optional[str] = typer.Option( | ||
None, '--description', '-d', help="Description metadata" | ||
), | ||
public: bool = typer.Option(False, '-pub', help="Indicates a public goal visible to all users (default false)"), | ||
name: Optional[str] = typer.Option( | ||
None, '--name', '-n', help="Name of the new goal (default is the file name without extension)" | ||
), | ||
model_id: Optional[int] = typer.Option( | ||
None, '--model', '-m', help="Mission model ID of specification to add this to" | ||
), | ||
plan_id: Optional[int] = typer.Option( | ||
None, '--plan', '-p', help="Plan ID of the specification to add this to" | ||
) | ||
): | ||
client = CommandContext.get_client() | ||
filename, extension = _get_name_and_ext(path) | ||
if name is None: | ||
name = filename | ||
upload_obj = {} | ||
if extension == '.ts': | ||
with open(path, "r") as f: | ||
upload_obj["definition"] = f.read() | ||
upload_obj["type"] = "EDSL" | ||
elif extension == '.jar': | ||
jar_id = client.upload_file(path) | ||
upload_obj["uploaded_jar_id"] = jar_id | ||
upload_obj["parameter_schema"] = {} | ||
upload_obj["type"] = "JAR" | ||
else: | ||
raise RuntimeError(f"Unsupported goal file extension: {extension}") | ||
metadata = {"name": name} | ||
if description is not None: | ||
metadata["description"] = description | ||
metadata["public"] = public | ||
if model_id is not None: | ||
metadata["models_using"] = {"data": {"model_id": model_id}} | ||
if plan_id is not None: | ||
spec_id = client.get_scheduling_specification_for_plan(plan_id) | ||
metadata["plans_using"] = {"data": {"specification_id": spec_id}} | ||
upload_obj["metadata"] = {"data": metadata} | ||
resp = client.upload_scheduling_goals([upload_obj]) | ||
id = resp[0]["goal_id"] | ||
typer.echo(f"Uploaded scheduling goal to venue. ID: {id}") | ||
|
||
|
||
@app.command() | ||
def update( | ||
path: str = typer.Argument(default=...), | ||
goal_id: Optional[int] = typer.Option(None, '--goal', '-g', help="Goal ID of goal to be updated (will search by name if omitted)"), | ||
name: Optional[str] = typer.Option(None, '--name', '-n', help="Name of the goal to be updated (ignored if goal is provided, default is the file name without extension)"), | ||
): | ||
client = CommandContext.get_client() | ||
filename, extension = _get_name_and_ext(path) | ||
if goal_id is None: | ||
if name is None: | ||
name = filename | ||
goal_id = client.get_goal_id_for_name(name) | ||
upload_obj = {"goal_id": goal_id} | ||
if extension == '.ts': | ||
with open(path, "r") as f: | ||
upload_obj["definition"] = f.read() | ||
upload_obj["type"] = "EDSL" | ||
elif extension == '.jar': | ||
jar_id = client.upload_file(path) | ||
upload_obj["uploaded_jar_id"] = jar_id | ||
upload_obj["parameter_schema"] = {} | ||
upload_obj["type"] = "JAR" | ||
else: | ||
raise RuntimeError(f"Unsupported goal file extension: {extension}") | ||
|
||
resp = client.upload_scheduling_goals([upload_obj]) | ||
id = resp[0]["goal_id"] | ||
typer.echo(f"Uploaded new version of scheduling goal to venue. ID: {id}") | ||
|
||
|
||
@app.command() | ||
def delete( | ||
goal_id: int = typer.Option( | ||
..., help="Goal ID of goal to be deleted", prompt=True | ||
) | ||
): | ||
"""Delete scheduling goal""" | ||
client = CommandContext.get_client() | ||
|
||
resp = client.delete_scheduling_goal(goal_id) | ||
typer.echo("Successfully deleted Goal ID: " + str(resp)) | ||
|
||
@app.command() | ||
def delete_all_goals_for_plan( | ||
plan_id: int = typer.Option( | ||
..., help="Plan ID", prompt=True | ||
), | ||
): | ||
client = CommandContext.get_client() | ||
|
||
specification = client.get_scheduling_specification_for_plan(plan_id) | ||
clear_goals = client.get_scheduling_goals_by_specification(specification) # response is in asc order | ||
|
||
if len(clear_goals) == 0: # no goals to clear | ||
typer.echo("No goals to delete.") | ||
return | ||
|
||
typer.echo("Deleting goals for Plan ID {plan}: ".format(plan=plan_id), nl=False) | ||
goal_ids = [] | ||
for goal in clear_goals: | ||
goal_ids.append(goal["goal_metadata"]["id"]) | ||
typer.echo(str(goal["goal_metadata"]["id"]) + " ", nl=False) | ||
typer.echo() | ||
|
||
client.delete_scheduling_goals(goal_ids) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters