From 33b9e98654f15285ba935f132a7104dcb88e9021 Mon Sep 17 00:00:00 2001 From: Ziheng Sun Date: Sun, 30 Jun 2024 00:29:35 -0400 Subject: [PATCH] add detail --- pygeoweaver/commands/pgw_detail.py | 91 +++++++++++++++++++----------- pygeoweaver/utils.py | 2 +- 2 files changed, 59 insertions(+), 34 deletions(-) diff --git a/pygeoweaver/commands/pgw_detail.py b/pygeoweaver/commands/pgw_detail.py index 15a92ce..45e3238 100644 --- a/pygeoweaver/commands/pgw_detail.py +++ b/pygeoweaver/commands/pgw_detail.py @@ -2,6 +2,7 @@ Detail subcommand """ +import logging import subprocess import requests @@ -12,8 +13,11 @@ get_geoweaver_jar_path, get_java_bin_path, get_root_dir, + get_spinner, ) +logger = logging.getLogger(__name__) + def detail_workflow(workflow_id): """ @@ -24,17 +28,25 @@ def detail_workflow(workflow_id): """ if not workflow_id: raise RuntimeError("Workflow id is missing") - download_geoweaver_jar() - subprocess.run( - [ - get_java_bin_path(), - "-jar", - get_geoweaver_jar_path(), - "detail", - f"--workflow-id={workflow_id}", - ], - cwd=f"{get_root_dir()}/", - ) + with get_spinner(text="Getting host details..", spinner="dots"): + download_geoweaver_jar() + process = subprocess.run( + [ + get_java_bin_path(), + "-jar", + get_geoweaver_jar_path(), + "detail", + f"--workflow-id={workflow_id}", + ], + cwd=f"{get_root_dir()}/", + ) + + print(process.stdout) + if process.stderr: + print("=== Error ===") + print(process.stderr) + logger.error(process.stderr) + def detail_process(process_id): """ @@ -45,17 +57,23 @@ def detail_process(process_id): """ if not process_id: raise RuntimeError("Process id is missing") - download_geoweaver_jar() - subprocess.run( - [ - get_java_bin_path(), - "-jar", - get_geoweaver_jar_path(), - "detail", - f"--process-id={process_id}", - ], - cwd=f"{get_root_dir()}/", - ) + with get_spinner(text="Getting host details..", spinner="dots"): + download_geoweaver_jar() + process = subprocess.run( + [ + get_java_bin_path(), + "-jar", + get_geoweaver_jar_path(), + "detail", + f"--process-id={process_id}", + ], + cwd=f"{get_root_dir()}/", + ) + print(process.stdout) + if process.stderr: + print("=== Error ===") + print(process.stderr) + logger.error(process.stderr) def detail_host(host_id): """ @@ -66,17 +84,24 @@ def detail_host(host_id): """ if not host_id: raise RuntimeError("Host id is missing") - download_geoweaver_jar() - subprocess.run( - [ - get_java_bin_path(), - "-jar", - get_geoweaver_jar_path(), - "detail", - f"--host-id={host_id}", - ], - cwd=f"{get_root_dir()}/", - ) + with get_spinner(text="Getting host details..", spinner="dots"): + download_geoweaver_jar() + process = subprocess.run( + [ + get_java_bin_path(), + "-jar", + get_geoweaver_jar_path(), + "detail", + f"--host-id={host_id}", + ], + cwd=f"{get_root_dir()}/", + ) + + print(process.stdout) + if process.stderr: + print("=== Error ===") + print(process.stderr) + logger.error(process.stderr) def get_process_code(process_id): """ diff --git a/pygeoweaver/utils.py b/pygeoweaver/utils.py index e875940..f0d43e1 100644 --- a/pygeoweaver/utils.py +++ b/pygeoweaver/utils.py @@ -28,7 +28,7 @@ def is_interactive(): return False # Probably standard Python interpreter -def get_spinner(text: str, spinner: str): +def get_spinner(text: str, spinner: str = "dots"): if is_interactive(): return Spinner(text=text, style=spinner) else: