From a56e6e0e2b1fb62fe0cf62015df78e941b15c6a2 Mon Sep 17 00:00:00 2001 From: Etienne Pallier Date: Sat, 7 Oct 2023 01:07:12 +0200 Subject: [PATCH] comments and shortcuts in pyros.py and docker scripts --- docker/PYROS_DOCKER_INSTALL_DB | 2 ++ docker/PYROS_DOCKER_UPDATE | 12 ++++++++---- pyros.py | 43 +++++++++++++++++++++---------------------- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/docker/PYROS_DOCKER_INSTALL_DB b/docker/PYROS_DOCKER_INSTALL_DB index 72c7d28..3fd57bd 100755 --- a/docker/PYROS_DOCKER_INSTALL_DB +++ b/docker/PYROS_DOCKER_INSTALL_DB @@ -1,5 +1,7 @@ #!/usr/bin/env bash +# PRE-CONDITION : pyros container must be running + # if no container is running if ! [ $(docker ps | grep 'pyros' | wc -l) -eq 4 ] ; then echo "pyros-db or pyros weren't running, starting them..." diff --git a/docker/PYROS_DOCKER_UPDATE b/docker/PYROS_DOCKER_UPDATE index f5cc478..ee87376 100755 --- a/docker/PYROS_DOCKER_UPDATE +++ b/docker/PYROS_DOCKER_UPDATE @@ -1,5 +1,7 @@ #!/usr/bin/env bash +# PRE-CONDITION : pyros container must be running + # If no container is running Start it if ! [ $(docker ps | grep 'pyros' | wc -l) -eq 4 ] then @@ -16,10 +18,12 @@ echo "Updating Guitastro source code" echo "Updating PyROS source code" git pull -echo "Updating observatory source code" -for dir in ../../PYROS_OBSERVATORY/* -do - git pull +# 3) Update all observatories with git repo +for dir in ../../PYROS_OBSERVATORY/* ; do + if [ -d .git ] ; then + echo "Updating observatory $dir source code" + git pull + fi done # 3) pyros.py update => update BD + doc + Guitastro requirements diff --git a/pyros.py b/pyros.py index d08204c..6f79aa8 100755 --- a/pyros.py +++ b/pyros.py @@ -534,7 +534,7 @@ def dbshell(): @pyros_launcher.command(help="Update (only if necessary) the python packages AND the source code AND the DB structure") def update(): - install_or_update(UPDATE=True) + _install_or_update(UPDATE=True) ''' print("Running update command") # 1) Update source code (git pull) @@ -568,13 +568,14 @@ def update(): def install(packages_only, database_only): with_packages = not database_only with_database = not packages_only - install_or_update(UPDATE=False, with_packages=with_packages, + _install_or_update(UPDATE=False, with_packages=with_packages, with_database=with_database) # install_or_update(UPDATE=False, with_packages=packages_only, with_database=database_only) # install_or_update(UPDATE=False, packages_only=packages_only, database_only=database_only) + # def install_or_update(UPDATE: bool = False, with_packages: bool = False, with_database: bool = False): -def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_database: bool = True): +def _install_or_update(UPDATE: bool = False, with_packages: bool = True, with_database: bool = True): SQL_USER = os.environ.get("MYSQL_PYROS_LOGIN").strip() SQL_PSWD = os.environ.get("MYSQL_PYROS_PWD").strip() os.environ["PATH_TO_OBSCONF_FOLDER"] = os.path.join(os.path.abspath( @@ -583,7 +584,7 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat PYROS_DJANGO_BASE_DIR), os.environ["PATH_TO_OBSCONF_FOLDER"] + "observatory.yml") ACTION = "UPDATING" if UPDATE else "INSTALLING" - # if WITH_DOCKER: with_database = True + # if WITH_DOCKER: only install the DB (with_database = True) if WITH_DOCKER: with_packages = False @@ -597,21 +598,22 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat # if (os.path.basename(os.getcwd()) != "private"): num = 0 - # 1) Update source code (git pull) + if UPDATE: + # Update source code (git pull) num += 1 - printFullTerm( - Colors.BLUE, f"{num}) UPDATING SOURCE CODE: Running git pull") + printFullTerm(Colors.BLUE, f"{num}) UPDATING SOURCE CODE: Running git pull") if not WITH_DOCKER: _gitpull() or die() - # 2) Update python packages (pip upgrade AND pip install requirements) if with_packages: + # Update python packages (pip upgrade AND pip install requirements) num += 1 printFullTerm(Colors.BLUE, f"{num}) {ACTION} PYTHON PACKAGES") # (UPDATE) Re-install VENV if disappeared install_venv(EVEN_IF_ALREADY_EXISTS=not UPDATE) install_packages() + if UPDATE: print("Running UPDATE command") else: @@ -621,13 +623,10 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat from git import Repo except: pip = "pip" if IS_WINDOWS else "pip3" - if WITH_DOCKER: - process = subprocess.Popen( - pip + " install --user --upgrade GitPython", shell=True) - else: - process = subprocess.Popen( - pip + " install --upgrade GitPython", shell=True) + usermode = '--user' if WITH_DOCKER else '' + process = subprocess.Popen(pip + f" install {usermode} --upgrade GitPython", shell=True) process.wait() + # if run ok if process.returncode == 0: # self.addExecuted(self.current_command, command) from git import Repo @@ -645,14 +644,16 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat change_dir("PREVIOUS") ''' + # # Guitastro + # GUITASTRO_PATH = os.path.join(os.getcwd(), "./vendor/guitastro") - if with_packages and not WITH_DOCKER : + if with_packages: # and not WITH_DOCKER: #GUITASTRO_PATH = os.path.join(os.getcwd(), "../vendor/guitastro") change_dir("..") print(os.getcwd()) # 1) clone repo if not yet done - if not os.path.exists(GUITASTRO_PATH) and not WITH_DOCKER : + if not WITH_DOCKER and not os.path.exists(GUITASTRO_PATH): print("Guitastro : Cloning repository") cloned_repo = Repo.clone_from( "https://gitlab.irap.omp.eu/guitastrolib/guitastro.git", GUITASTRO_PATH) @@ -661,7 +662,7 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat gitpull_guitastro() change_dir("PREVIOUS") # 2) install/update requirements & generate API doc - if os.path.exists(GUITASTRO_PATH) and not WITH_DOCKER: + if not WITH_DOCKER and os.path.exists(GUITASTRO_PATH): # TODO: update guitastro (git pull from vendor/guitastro/) print("\nGuitastro : Installing/Updating python package dependencies\n") # Upgrade pip if new version available @@ -703,9 +704,8 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat _updatedb() or die() else: res = install_database(VENV) - if(res == 0): - print( - f"You can connect to PyROS as '{SQL_USER}' user with the password '{SQL_PSWD}' ") + if (res == 0): + print(f"You can connect to PyROS as '{SQL_USER}' user with the password '{SQL_PSWD}' ") return True @@ -789,8 +789,7 @@ def gitpull_guitastro(): change_dir("./vendor/guitastro/") GIT = "git.exe" if IS_WINDOWS else "git" if not test_mode(): - return execProcess(f"{GIT} pull",foreground=True) - + return execProcess(f"{GIT} pull", foreground=True) return True -- libgit2 0.21.2