Skip to content

Commit

Permalink
add more commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ZihengSun committed Feb 3, 2024
1 parent 24f9ed8 commit 63585b0
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 3 deletions.
171 changes: 171 additions & 0 deletions pygeoweaver/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
helpwith,
)
from pygeoweaver.constants import GEOWEAVER_DEFAULT_ENDPOINT_URL
from pygeoweaver.sc_create import create_process, create_process_from_file, create_workflow
from pygeoweaver.sc_detail import get_process_code
from pygeoweaver.sc_find import get_process_by_id, get_process_by_language, get_process_by_name
from pygeoweaver.server import show


Expand Down Expand Up @@ -60,6 +63,14 @@ def show_command(geoweaver_url):
show(geoweaver_url)


@geoweaver.command("reset_password")
def reset_password_command():
"""
Reset the password for localhost.
"""
reset_password()


@geoweaver.group("create")
def create_command():
"""
Expand All @@ -68,8 +79,168 @@ def create_command():
pass


@create_command.command("process")
@click.option('--lang', prompt='Programming Language', help='The programming language of the process')
@click.option('--description', prompt='Description', help='The description of the process')
@click.option('--name', prompt='Name', help='The name of the process')
@click.option('--code', prompt='Code', help='The code of the process')
@click.option('--file-path', prompt='File Path', type=click.Path(exists=True), help='The path to the file containing the code')
@click.option('--owner', default='111111', help='The owner of the process (default: "111111")')
@click.option('--confidential', is_flag=True, help='Set if the process is confidential')
def create_process_command(lang, description, name, code, file_path, owner, confidential):
"""
Create a process with given code or given file_path, which ever is valid first.
"""
if code is not None:
create_process(lang, description, name, code, owner, confidential)
elif file_path is not None:
create_process_from_file(lang, description, name, file_path, owner, confidential)


@create_command.command("workflow")
@click.option('--description', prompt='Description', help='The description of the workflow')
@click.option('--edges', prompt='Edges', help='The edges of the workflow')
@click.option('--name', prompt='Name', help='The name of the workflow')
@click.option('--nodes', prompt='Nodes', help='The nodes of the workflow')
@click.option('--owner', default='111111', help='The owner of the workflow (default: "111111")')
@click.option('--confidential', is_flag=True, help='Set if the workflow is confidential')
def create_workflow_command(description, edges, name, nodes, owner, confidential):
"""
Create a workflow with given data if valid.
"""
create_workflow(description, edges, name, nodes, owner, confidential)


@geoweaver.group("detail")
def detail_command():
"""
Detail commands for Geoweaver.
"""
pass


@detail_command.command("workflow")
@click.argument('workflow_id', type=str)
def detail_workflow_command(workflow_id):
"""
Display detailed information about a workflow.
:param workflow_id: The ID of the workflow.
:type workflow_id: str
"""
detail_workflow(workflow_id)


@detail_command.command("process")
@click.argument('process_id', type=str)
def detail_process_command(process_id):
"""
Display detailed information about a process.
:param process_id: The ID of the process.
:type process_id: str
"""
detail_process(process_id)


@detail_command.command("host")
@click.argument('host_id', type=str)
def detail_host_command(host_id):
"""
Display detailed information about a host.
:param host_id: The ID of the host.
:type host_id: str
"""
detail_host(host_id)


@detail_command.command("code")
@click.argument('process_id', type=str)
def get_process_code_command(process_id):
"""
Get the code of a process.
:param process_id: The ID of the process.
:type process_id: str
"""
get_process_code(process_id)


@geoweaver.group("export")
def export_command():
"""
Export commands for Geoweaver.
"""
pass


@export_command.command()
@click.argument('workflow_id', type=str)
@click.option('--mode', default=4, type=int, help='Exportation mode options: 1 - workflow only, 2 - workflow with process code, 3 - workflow with process code and only good history, 4 - workflow with process code and all the history. Default option is 4.')
@click.argument('target_file_path', type=click.Path())
@click.option('--unzip', is_flag=True, help='Unzip the exported file.')
@click.option('--unzip-directory-name', help='Specify the directory name when unzipping.')
def export_workflow_command(workflow_id, mode, target_file_path, unzip, unzip_directory_name):
"""
Export a Geoweaver workflow.
:param workflow_id: Geoweaver workflow ID.
:type workflow_id: str
:param mode: Exportation mode options: 1 - workflow only, 2 - workflow with process code, 3 - workflow with process code and only good history, 4 - workflow with process code and all the history. Default option is 4.
:type mode: int
:param target_file_path: Target file path to save the workflow zip.
:type target_file_path: str
:param unzip: Unzip the exported file.
:type unzip: bool
:param unzip_directory_name: Specify the directory name when unzipping.
:type unzip_directory_name: str
"""
export_workflow(workflow_id, mode, target_file_path, unzip, unzip_directory_name)


@geoweaver.group("find")
def find_command():
"""
Find commands for Geoweaver.
"""
pass


@find_command.command("name")
@click.argument('process_name', type=str)
def get_process_by_name_command(process_name):
"""
Get processes by their name.
:param process_name: The name of the process.
:type process_name: str
"""
get_process_by_name(process_name)


@find_command.command("id")
@click.argument('process_id', type=str)
def get_process_by_id_command(process_id):
"""
Get a process by its ID.
:param process_id: The ID of the process.
:type process_id: str
"""
get_process_by_id(process_id)


@find_command.command("language")
@click.argument('language', type=str)
def get_process_by_language_command(language):
"""
Get processes by their programming language.
:param language: The programming language of the processes.
:type language: str
"""
get_process_by_language(language)


def main():
Expand Down
5 changes: 5 additions & 0 deletions pygeoweaver/sc_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,8 @@ def create_workflow(
return pd.DataFrame(json.loads(data_json).items(), columns=["Key", "Value"])
else:
return r.json()


def create_workflow_from_file():
raise Exception("Creating workflow from file is not implemented yet.")

29 changes: 26 additions & 3 deletions pygeoweaver/sc_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@


def detail_workflow(workflow_id):
"""
Display detailed information about a workflow.
:param workflow_id: The ID of the workflow.
:type workflow_id: str
"""
if not workflow_id:
raise RuntimeError("Workflow id is missing")
download_geoweaver_jar()
Expand All @@ -30,8 +36,13 @@ def detail_workflow(workflow_id):
cwd=f"{get_root_dir()}/",
)


def detail_process(process_id):
"""
Display detailed information about a process.
:param process_id: The ID of the process.
:type process_id: str
"""
if not process_id:
raise RuntimeError("Process id is missing")
download_geoweaver_jar()
Expand All @@ -46,8 +57,13 @@ def detail_process(process_id):
cwd=f"{get_root_dir()}/",
)


def detail_host(host_id):
"""
Display detailed information about a host.
:param host_id: The ID of the host.
:type host_id: str
"""
if not host_id:
raise RuntimeError("Host id is missing")
download_geoweaver_jar()
Expand All @@ -62,8 +78,15 @@ def detail_host(host_id):
cwd=f"{get_root_dir()}/",
)


def get_process_code(process_id):
"""
Get the code of a process.
:param process_id: The ID of the process.
:type process_id: str
:return: The code of the process.
:rtype: str
"""
r = requests.post(
f"{GEOWEAVER_DEFAULT_ENDPOINT_URL}/web/detail",
data={"type": "process", "id": process_id},
Expand Down
18 changes: 18 additions & 0 deletions pygeoweaver/sc_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@


def get_process_by_name(process_name):
"""
Get processes by their name.
:param process_name: The name of the process.
:type process_name: str
"""
response = requests.post(
f"{GEOWEAVER_DEFAULT_ENDPOINT_URL}/web/list", data={"type": "process"}
)
Expand All @@ -21,6 +27,12 @@ def get_process_by_name(process_name):


def get_process_by_id(process_id):
"""
Get a process by its ID.
:param process_id: The ID of the process.
:type process_id: str
"""
response = requests.post(
f"{GEOWEAVER_DEFAULT_ENDPOINT_URL}/web/list", data={"type": "process"}
)
Expand All @@ -38,6 +50,12 @@ def get_process_by_id(process_id):


def get_process_by_language(language):
"""
Get processes by their programming language.
:param language: The programming language of the processes.
:type language: str
"""
response = requests.post(
f"{GEOWEAVER_DEFAULT_ENDPOINT_URL}/web/list", data={"type": "process"}
)
Expand Down

0 comments on commit 63585b0

Please sign in to comment.