From 76e1d14424003a0c196f135a5d9cf9f14d98e96b Mon Sep 17 00:00:00 2001 From: Ziheng Sun Date: Sun, 16 Apr 2023 19:33:47 -0400 Subject: [PATCH] windows is not supported, add resetpassword, revise readme --- README.md | 35 +++++++++++++++-------- pygeoweaver/__main__.py | 21 +++++++++----- pygeoweaver/sc_interface.py | 2 ++ pygeoweaver/sc_resetpassword.py | 13 +++++++++ pygeoweaver/sc_run.py | 49 +++++++++++++++++++++------------ pygeoweaver/server.py | 23 ++++++++-------- pygeoweaver/start.sh | 2 -- pygeoweaver/utils.py | 11 +++++++- pyproject.toml | 2 +- 9 files changed, 105 insertions(+), 53 deletions(-) create mode 100644 pygeoweaver/sc_resetpassword.py diff --git a/README.md b/README.md index 964fcb2..06b2ed5 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,26 @@ geoweaver.stop() 3. To list the existing objects, please run: ``` -geoweaver.list("host") -geoweaver.list("process") -geoweaver.list("workflow") +geoweaver.list_hosts() +geoweaver.list_processes() +geoweaver.list_workflows() ``` 4. To run a workflow, please run: ``` -geoweaver.run_workflow() +geoweaver.run_workflow("workflow_id", "host_id_list", "password_list", "environment_list") +``` + +or + +``` +geoweaver.run_workflow("workflow_zip_file_path", "host_id_list", "password_list", "environment_list") +``` + +or + +``` +geoweaver.run_workflow("workflow_local_folder_path", "host_id_list", "password_list", "environment_list") ``` 5. To export a workflow: @@ -47,42 +59,41 @@ geoweaver.export_workflow("workflow_id", "workflow_zip_save_path") 6. To import a workflow: ``` -geoweaver.import_workflow("workflow_zip_file_path") +geoweaver.import_workflow("") ``` or ``` -geoweaver.import_workflow("workflow_folder_path") +geoweaver.import_workflow("") ``` 7. To get history of a workflow run: ``` -geoweaver.history_workflow() +geoweaver.history("") ``` 8. To get history of a process run: ``` -geoweaver.history_process() +geoweaver.history("") ``` 9. To check the source code of a process ``` -geoweaver.detail_processs(process_id) +geoweaver.detail_processs("") ``` 10. To check the configuration of a workflow ``` -geoweaver.detail_workflow(workflow_id) +geoweaver.detail_workflow("") ``` 11. To check the details of a host: ``` -geoweaver.detail_host(host_id) +geoweaver.detail_host("") ``` - diff --git a/pygeoweaver/__main__.py b/pygeoweaver/__main__.py index 7ef4408..f9dc7db 100644 --- a/pygeoweaver/__main__.py +++ b/pygeoweaver/__main__.py @@ -2,12 +2,9 @@ The main function of pygeoweaver To run in CLI mode. """ -from pygeoweaver import detail_host, detail_process, detail_workflow -from pygeoweaver import export_workflow -from pygeoweaver import show_history -from pygeoweaver import import_workflow -from pygeoweaver import list_hosts, list_processes, list_workflows -from pygeoweaver import start, stop +from pygeoweaver import detail_host, detail_process, detail_workflow, export_workflow, \ + show_history, import_workflow, list_hosts, list_processes, list_workflows, \ + start, stop, reset_password, run_process, run_worklfow def main(): # start geoweaver @@ -29,7 +26,17 @@ def main(): #import_workflow("/Users/joe/Downloads/gr3ykr8dynu12vrwq11oy.zip") # export workflow # export_workflow("gr3ykr8dynu12vrwq11oy", "4", "/Users/joe/Downloads/test_pygeoweaver_export.zip") - # run workflow + # run process + # run_process(process_id="7zwnvx", host_id="100001", password="xxx", environment="",) + # run workflow by id + # run_worklfow(workflow_id="9sszomwhiiusakodb1ft", host_list="100001", password_list="xxx", + # environment_list="",) + # run workflow by zip path + + # run workflow by folder path + + # reset localhost password for Geoweaver + # reset_password() if __name__ == "__main__": diff --git a/pygeoweaver/sc_interface.py b/pygeoweaver/sc_interface.py index e0f933d..b9032c5 100644 --- a/pygeoweaver/sc_interface.py +++ b/pygeoweaver/sc_interface.py @@ -8,3 +8,5 @@ from pygeoweaver.sc_import import * from pygeoweaver.sc_list import * from pygeoweaver.sc_run import * +from pygeoweaver.server import * +from pygeoweaver.sc_resetpassword import * diff --git a/pygeoweaver/sc_resetpassword.py b/pygeoweaver/sc_resetpassword.py new file mode 100644 index 0000000..e837b94 --- /dev/null +++ b/pygeoweaver/sc_resetpassword.py @@ -0,0 +1,13 @@ + +import subprocess +from pygeoweaver.utils import download_geoweaver_jar, get_geoweaver_jar_path, get_root_dir + + +def reset_password(): + """ + Usage:
resetpassword + Reset password for localhost + """ + download_geoweaver_jar() + subprocess.run(["java", "-jar", get_geoweaver_jar_path(), "resetpassword",]) + diff --git a/pygeoweaver/sc_run.py b/pygeoweaver/sc_run.py index f00f352..1a041b9 100644 --- a/pygeoweaver/sc_run.py +++ b/pygeoweaver/sc_run.py @@ -2,17 +2,23 @@ from pygeoweaver.utils import download_geoweaver_jar, get_geoweaver_jar_path, get_root_dir -def run_process(*, process_id, host_id, password, environment): - if not host_id: - raise RuntimeError("Host id is missing") +def run_process(*, process_id: str, host_id: str, password: str, environment: str=None): + """ + Run a process + + Args: process_id - required + host_id - required + password - required + environment - optional + """ download_geoweaver_jar() subprocess.run(["java", "-jar", get_geoweaver_jar_path(), "run", "process", f"--host={host_id}", f"--password={password}", f"--environment={environment}", process_id], cwd=f"{get_root_dir()}/") -def run_worklfow(*, workflow_id, workflow_folder_path, workflow_zip_file_path, environments, host, password): +def run_worklfow(*, workflow_id: str, workflow_folder_path: str=None, workflow_zip_file_path: str=None, + environment_list: str=None, host_list: str, password_list: str): """ - Missing required parameter: '' Usage:
run workflow [-d=] [-f=] [-e=]... [-h=]... [-p=]... @@ -20,32 +26,39 @@ def run_worklfow(*, workflow_id, workflow_folder_path, workflow_zip_file_path, e workflow id to run -d, --workflow-folder-path= geoweaver workflow folder path - -e, --environments= environments to run on + -e, --environments= environments to run on. List of environment ids with comma as separator -f, --workflow-zip-file-path= workflow package or path to workflow zip to run - -h, --hosts= hosts to run on - -p, --passwords= passwords to the target hosts + -h, --hosts= hosts to run on. list of host ids with comma as separator. + -p, --passwords= passwords to the target hosts. list of passwords with comma as separator. """ download_geoweaver_jar() - if workflow_folder_path and workflow_zip_file_path: - raise RuntimeError("Please provide either Folder path or Zip path") + if not workflow_id and not workflow_folder_path and not workflow_zip_file_path: + raise RuntimeError("Please provide at least one of the three options: workflow id, " \ + "folder path or zip path") + + if workflow_id and not workflow_folder_path and not workflow_zip_file_path: + subprocess.run(["java", "-jar", get_geoweaver_jar_path(), "run", "workflow", workflow_id, + "-e", environment_list, + "-h", host_list, + "-p", password_list], + cwd=f"{get_root_dir()}/") if workflow_folder_path and not workflow_zip_file_path: # command to run workflow from folder subprocess.run(["java", "-jar", get_geoweaver_jar_path(), "run", "workflow", workflow_id, "-d", workflow_folder_path, - "-e", environments, - "-h", host, - "-p", password], + "-e", environment_list, + "-h", host_list, + "-p", password_list], cwd=f"{get_root_dir()}/") if not workflow_folder_path and workflow_zip_file_path: subprocess.run(["java", "-jar", get_geoweaver_jar_path(), "run", "workflow", workflow_id, - "-e", environments, + "-e", environment_list, "-f", workflow_zip_file_path, - "-h", host, - "-p", password], + "-h", host_list, + "-p", password_list], cwd=f"{get_root_dir()}/") - - raise RuntimeError("Please provide either zip path or directory path to run workflow.") + diff --git a/pygeoweaver/server.py b/pygeoweaver/server.py index 96220ad..fe1a4d4 100644 --- a/pygeoweaver/server.py +++ b/pygeoweaver/server.py @@ -1,6 +1,6 @@ import os import subprocess -from pygeoweaver.utils import get_root_dir +from pygeoweaver.utils import checkOS, download_geoweaver_jar, get_root_dir """ This module provides function to start and stop Geoweaver server. @@ -9,22 +9,21 @@ """ -def download_geoweaver(): - """ - Download Geoweaver to user home directory - """ - pass - -def start(): - print("start Geoweaver instance..") - result = subprocess.run(['./start.sh'], cwd=f"{get_root_dir()}/") +def start(force=False): + download_geoweaver_jar(overwrite=force) + if checkOS() == 3: + raise RuntimeError("windows is not supported yet") + else: + result = subprocess.run(['./start.sh'], cwd=f"{get_root_dir()}/") def stop(): - print("stop Geoweaver instance..") - result = subprocess.run(['./stop.sh'], cwd=f"{get_root_dir()}/", shell=True) + if checkOS() == 3: + raise RuntimeError("Windows is not supported yet") + else: + result = subprocess.run(['./stop.sh'], cwd=f"{get_root_dir()}/", shell=True) diff --git a/pygeoweaver/start.sh b/pygeoweaver/start.sh index e5df1c5..330a45a 100755 --- a/pygeoweaver/start.sh +++ b/pygeoweaver/start.sh @@ -3,8 +3,6 @@ echo "Stop running Geoweaver if any.." pkill -f geoweaver - - echo "Start Geoweaver.." nohup java -jar ~/geoweaver.jar > ~/geoweaver.log & diff --git a/pygeoweaver/utils.py b/pygeoweaver/utils.py index cc1b97a..1a0d323 100644 --- a/pygeoweaver/utils.py +++ b/pygeoweaver/utils.py @@ -1,7 +1,7 @@ import os import subprocess import requests - +import platform def get_home_dir(): return os.path.expanduser('~') @@ -39,3 +39,12 @@ def download_geoweaver_jar(overwrite=False): else: raise RuntimeError("Fail to download geoweaver.jar") + + +def checkOS(): + if platform.system() == "Linux" or platform == "Linux2": + return 1 + elif platform.system() == "Darwin": + return 2 + elif platform == "Windows": + return 3 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 2e8b96b..81ebbed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "pygeoweaver" -version = "0.6.2" +version = "0.6.4" authors = [ { name="Geoweaver team", email="geoweaver.app@gmail.com" }, ]