From 934f2a03e34774c6f9c03b79759960ca43ff7510 Mon Sep 17 00:00:00 2001 From: Gokul Prathin Date: Fri, 2 Jun 2023 17:18:11 -0400 Subject: [PATCH 1/7] added start, stop bat scripts --- pygeoweaver/server.py | 19 +++++++++---------- pygeoweaver/start.bat | 34 ++++++++++++++++++++++++++++++++++ pygeoweaver/stop.bat | 7 +++++++ 3 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 pygeoweaver/start.bat create mode 100644 pygeoweaver/stop.bat diff --git a/pygeoweaver/server.py b/pygeoweaver/server.py index 3bd3706..8564d9f 100644 --- a/pygeoweaver/server.py +++ b/pygeoweaver/server.py @@ -2,7 +2,8 @@ import subprocess import webbrowser from pygeoweaver.constants import GEOWEAVER_DEFAULT_ENDPOINT_URL -from pygeoweaver.utils import checkIPython, checkOS, download_geoweaver_jar, get_logger, get_module_absolute_path, get_root_dir +from pygeoweaver.utils import checkIPython, checkOS, download_geoweaver_jar, get_logger, get_module_absolute_path, \ + get_root_dir """ This module provides function to start and stop Geoweaver server. @@ -13,23 +14,23 @@ logger = get_logger(__name__) + def start(force=False): download_geoweaver_jar(overwrite=force) if checkOS() == 3: - raise RuntimeError("windows is not supported yet") + subprocess.run([f'{get_module_absolute_path()}/start.bat'], cwd=f"{get_root_dir()}/") else: - result = subprocess.run([f'{get_module_absolute_path()}/start.sh'], cwd=f"{get_root_dir()}/") - + subprocess.run([f'{get_module_absolute_path()}/start.sh'], cwd=f"{get_root_dir()}/") def stop(): if checkOS() == 3: - raise RuntimeError("Windows is not supported yet") + subprocess.run([f'{get_module_absolute_path()}/stop.bat'], cwd=f"{get_root_dir()}/", shell=True) else: - result = subprocess.run([f'{get_module_absolute_path()}/stop.sh'], cwd=f"{get_root_dir()}/", shell=True) - + subprocess.run([f'{get_module_absolute_path()}/stop.sh'], cwd=f"{get_root_dir()}/", shell=True) + -def show(geoweaver_url = GEOWEAVER_DEFAULT_ENDPOINT_URL): +def show(geoweaver_url=GEOWEAVER_DEFAULT_ENDPOINT_URL): download_geoweaver_jar() # check if geoweaver is initialized if checkIPython(): logger.info("enter ipython block") @@ -38,5 +39,3 @@ def show(geoweaver_url = GEOWEAVER_DEFAULT_ENDPOINT_URL): else: logger.info("enter self opening block") webbrowser.open(geoweaver_url) - - diff --git a/pygeoweaver/start.bat b/pygeoweaver/start.bat new file mode 100644 index 0000000..8e6e5d1 --- /dev/null +++ b/pygeoweaver/start.bat @@ -0,0 +1,34 @@ +@echo off + +echo Stop running Geoweaver if any.. +taskkill /f /im geoweaver.exe > nul + +echo Check Java.. + +echo Start Geoweaver.. +start /b javaw -jar "%USERPROFILE%\geoweaver.jar" + +set STATUS=0 +set counter=0 +:loop +ping -n 2 127.0.0.1 > nul +set /a counter+=1 +curl -s -o NUL -w "%%{http_code}" "http://localhost:8070/Geoweaver" > response.txt +set /p STATUS= nul + +echo Geoweaver stopped successfully. From 70e55c7605a62653a7db79ca5774d333ee883d1a Mon Sep 17 00:00:00 2001 From: Gokul Prathin Date: Fri, 2 Jun 2023 17:28:37 -0400 Subject: [PATCH 2/7] fix import --- pygeoweaver/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pygeoweaver/utils.py b/pygeoweaver/utils.py index 2ffb2d5..ab5b8ca 100644 --- a/pygeoweaver/utils.py +++ b/pygeoweaver/utils.py @@ -5,6 +5,8 @@ import platform import sys +from IPython import get_ipython + def get_home_dir(): return os.path.expanduser('~') From 51ebdd6b4889279db3ef0f33688c9eceae3c4395 Mon Sep 17 00:00:00 2001 From: Gokul Prathin Date: Fri, 2 Jun 2023 17:34:31 -0400 Subject: [PATCH 3/7] changes to install java --- pygeoweaver/utils.py | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/pygeoweaver/utils.py b/pygeoweaver/utils.py index ab5b8ca..8b0e383 100644 --- a/pygeoweaver/utils.py +++ b/pygeoweaver/utils.py @@ -72,28 +72,45 @@ def is_java_installed(): # Check if Java is installed by running "java -version" command subprocess.run(["java", "-version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) return True - except FileNotFoundError: + except subprocess.CalledProcessError: return False def install_java(): system = platform.system() if system == "Darwin": - # Install Java on MacOS using Homebrew - os.system("/bin/bash -c '/usr/bin/ruby -e \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\"'") + os.system( + "/bin/bash -c '/usr/bin/ruby -e \"$(curl -fsSL " + "https://raw.githubusercontent.com/Homebrew/install/master/install)\"'") os.system("brew install openjdk") elif system == "Linux": - # Install Java on Linux using apt package manager - os.system("sudo apt update") - os.system("sudo apt install -y default-jre default-jdk") + # need to check if the package manager type is apt or yum + # arch / debian + package_manager = None + if os.path.exists("/usr/bin/apt"): + package_manager = "apt" + elif os.path.exists("/usr/bin/yum"): + package_manager = "yum" + + if package_manager: + os.system(f"sudo {package_manager} update") + os.system(f"sudo {package_manager} install -y default-jre default-jdk") + else: + print("Package manager not found. Unable to install Java.") + sys.exit(1) elif system == "Windows": - # Install Java on Windows using Chocolatey package manager - os.system("powershell -Command \"Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))\"") + # note: this requires admin access to the pc, else it will fail saying + # Access to the path 'C:\ProgramData\chocolatey\lib-bad' is denied. + os.system( + "powershell -Command \"Set-ExecutionPolicy Bypass -Scope Process -Force; [" + "System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object " + "System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))\"") os.system("choco install -y openjdk") else: print("Unsupported operating system.") sys.exit(1) -def checkJava(): + +def check_java(): # Check if Java is installed if is_java_installed(): print("Java is already installed.") From 36106cb84fee80cef13fe1bf8df1e21228a04517 Mon Sep 17 00:00:00 2001 From: Gokul Prathin Date: Fri, 2 Jun 2023 17:38:46 -0400 Subject: [PATCH 4/7] added download_gw bash script equivalent --- pygeoweaver/__main__.py | 2 +- pygeoweaver/download_gw.bat | 10 ++++++++++ pygeoweaver/server.py | 8 ++++---- pygeoweaver/utils.py | 7 ++++--- 4 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 pygeoweaver/download_gw.bat diff --git a/pygeoweaver/__main__.py b/pygeoweaver/__main__.py index 4cb8a5c..014144b 100644 --- a/pygeoweaver/__main__.py +++ b/pygeoweaver/__main__.py @@ -4,7 +4,7 @@ """ 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, helpwith, ui + start, stop, reset_password, run_process, run_worklfow, helpwith from pygeoweaver.server import show def main(): diff --git a/pygeoweaver/download_gw.bat b/pygeoweaver/download_gw.bat new file mode 100644 index 0000000..6f12c8f --- /dev/null +++ b/pygeoweaver/download_gw.bat @@ -0,0 +1,10 @@ +@echo off + +set "FILE=%USERPROFILE%\geoweaver.jar" +if exist "%FILE%" ( + echo %FILE% exists. Removing... + del "%FILE%" +) + +echo Downloading the latest geoweaver.jar to user home directory +cd %USERPROFILE% && curl -OL https://github.com/ESIPFed/Geoweaver/releases/download/latest/geoweaver.jar diff --git a/pygeoweaver/server.py b/pygeoweaver/server.py index 8564d9f..999366a 100644 --- a/pygeoweaver/server.py +++ b/pygeoweaver/server.py @@ -2,7 +2,7 @@ import subprocess import webbrowser from pygeoweaver.constants import GEOWEAVER_DEFAULT_ENDPOINT_URL -from pygeoweaver.utils import checkIPython, checkOS, download_geoweaver_jar, get_logger, get_module_absolute_path, \ +from pygeoweaver.utils import check_ipython, check_os, download_geoweaver_jar, get_logger, get_module_absolute_path, \ get_root_dir """ @@ -17,14 +17,14 @@ def start(force=False): download_geoweaver_jar(overwrite=force) - if checkOS() == 3: + if check_os() == 3: subprocess.run([f'{get_module_absolute_path()}/start.bat'], cwd=f"{get_root_dir()}/") else: subprocess.run([f'{get_module_absolute_path()}/start.sh'], cwd=f"{get_root_dir()}/") def stop(): - if checkOS() == 3: + if check_os() == 3: subprocess.run([f'{get_module_absolute_path()}/stop.bat'], cwd=f"{get_root_dir()}/", shell=True) else: subprocess.run([f'{get_module_absolute_path()}/stop.sh'], cwd=f"{get_root_dir()}/", shell=True) @@ -32,7 +32,7 @@ def stop(): def show(geoweaver_url=GEOWEAVER_DEFAULT_ENDPOINT_URL): download_geoweaver_jar() # check if geoweaver is initialized - if checkIPython(): + if check_ipython(): logger.info("enter ipython block") from IPython.display import IFrame return IFrame(src=geoweaver_url, width='100%', height='500px') diff --git a/pygeoweaver/utils.py b/pygeoweaver/utils.py index 8b0e383..8afc16f 100644 --- a/pygeoweaver/utils.py +++ b/pygeoweaver/utils.py @@ -16,6 +16,7 @@ def get_root_dir(): head, tail = os.path.split(__file__) return head + def get_module_absolute_path(): module_path = os.path.abspath(__file__) return os.path.dirname(module_path) @@ -51,7 +52,7 @@ def download_geoweaver_jar(overwrite=False): raise RuntimeError("Fail to download geoweaver.jar") -def checkOS(): +def check_os(): if platform.system() == "Linux" or platform == "Linux2": return 1 elif platform.system() == "Darwin": @@ -60,7 +61,7 @@ def checkOS(): return 3 -def checkIPython(): +def check_ipython(): try: return get_ipython().__class__.__name__ == "ZMQInteractiveShell" except: @@ -75,6 +76,7 @@ def is_java_installed(): except subprocess.CalledProcessError: return False + def install_java(): system = platform.system() if system == "Darwin": @@ -128,4 +130,3 @@ def get_logger(class_name): console_handler.setFormatter(formatter) logger.addHandler(console_handler) return logger - From 3c810bb7b98cf0a944c1beb3bbd5473d07e3c4e8 Mon Sep 17 00:00:00 2001 From: Gokul Prathin Date: Fri, 2 Jun 2023 17:47:21 -0400 Subject: [PATCH 5/7] minor bug fixes --- pygeoweaver/__main__.py | 4 ++-- pygeoweaver/utils.py | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pygeoweaver/__main__.py b/pygeoweaver/__main__.py index 014144b..6de065e 100644 --- a/pygeoweaver/__main__.py +++ b/pygeoweaver/__main__.py @@ -9,7 +9,7 @@ def main(): # start geoweaver - # start() + start() # stop geoweaver # stop() # list resources @@ -38,7 +38,7 @@ def main(): # reset localhost password for Geoweaver # reset_password() - show() + # show() # helpwith() diff --git a/pygeoweaver/utils.py b/pygeoweaver/utils.py index 8afc16f..76646e8 100644 --- a/pygeoweaver/utils.py +++ b/pygeoweaver/utils.py @@ -35,8 +35,10 @@ def download_geoweaver_jar(overwrite=False): if overwrite: os.remove(get_geoweaver_jar_path()) else: - subprocess.run(["chmod", "+x", get_geoweaver_jar_path()], cwd=f"{get_root_dir()}/") - return + system = platform.system() + if not system == "Windows": # Windows files are exec by default + subprocess.run(["chmod", "+x", get_geoweaver_jar_path()], cwd=f"{get_root_dir()}/") + return print("Downloading latest version of Geoweaver...") geoweaver_url = "https://github.com/ESIPFed/Geoweaver/releases/download/latest/geoweaver.jar" @@ -57,7 +59,7 @@ def check_os(): return 1 elif platform.system() == "Darwin": return 2 - elif platform == "Windows": + elif platform.system() == "Windows": return 3 From 55fa7f7c08ad35f2c5de489ec54c7cafb26b08c4 Mon Sep 17 00:00:00 2001 From: Gokul Prathin Date: Fri, 2 Jun 2023 17:51:16 -0400 Subject: [PATCH 6/7] cleanup --- pygeoweaver/__main__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pygeoweaver/__main__.py b/pygeoweaver/__main__.py index 6de065e..7d56ce4 100644 --- a/pygeoweaver/__main__.py +++ b/pygeoweaver/__main__.py @@ -6,10 +6,12 @@ show_history, import_workflow, list_hosts, list_processes, list_workflows, \ start, stop, reset_password, run_process, run_worklfow, helpwith from pygeoweaver.server import show +from pygeoweaver.utils import check_java + def main(): # start geoweaver - start() + # start() # stop geoweaver # stop() # list resources @@ -38,8 +40,9 @@ def main(): # reset localhost password for Geoweaver # reset_password() - # show() + show() # helpwith() + # check_java() if __name__ == "__main__": From bf4945444e48000af74eb6eebbecdb73a236e661 Mon Sep 17 00:00:00 2001 From: Gokul Prathin Date: Fri, 2 Jun 2023 17:59:04 -0400 Subject: [PATCH 7/7] bump version --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4358ca2..074572e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "pygeoweaver" -version = "0.6.7" +version = "0.6.8" authors = [ { name="Geoweaver team", email="geoweaver.app@gmail.com" }, ] @@ -22,7 +22,7 @@ classifiers = [ [tool.poetry] name = "pygeoweaver" -version = "0.6.7" +version = "0.6.8" description = "This is a wrapper package of the Geoweaver app." authors = ["Geoweaver team "] readme = "README.md"