From 779e1df95c5ef4b82998c88a9807e2fd2ad268ff Mon Sep 17 00:00:00 2001 From: Etienne Pallier Date: Fri, 20 Dec 2019 19:38:26 +0100 Subject: [PATCH] pyros.py update => recrée le venv et reinstalle packages si venv disparu --- pyros.py | 70 +++++++++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/pyros.py b/pyros.py index 467a248..ff8589d 100755 --- a/pyros.py +++ b/pyros.py @@ -387,7 +387,7 @@ def install(packages_only, database_only): if not packages_only and not database_only: packages_only = database_only = True if packages_only: - install_venv() + install_venv(True) install_packages() if database_only: install_database(VENV) ''' @@ -447,13 +447,18 @@ def update(): printFullTerm(Colors.BLUE, "1) UPDATING SOURCE CODE: Running git pull") _gitpull() or die() - # 2) Update python packages (pip install requirements) + # Re-install VENV if disappeared + install_venv(False) + + # 2) Update python packages (pip upgrade AND pip install requirements) printFullTerm(Colors.BLUE, "2) UPDATING PYTHON PACKAGES") - _update_python_packages_from_requirements() or die() - + ##_update_python_packages_from_requirements() or die() + install_packages() + print(os.getcwd()) # 3) Update PlantUML diagrams printFullTerm(Colors.BLUE, "3) UPDATING PLANTUML DIAGRAMS") _update_plantuml_diags() or die() + print(os.getcwd()) # 4) Update database structure (make migrations + migrate) printFullTerm(Colors.BLUE, "4) UPDATING DATABASE") @@ -623,11 +628,11 @@ def stop(agent): ******************************************************************************** """ -def _update_python_packages_from_requirements(): - # 1) try to upgrade pip +def notused_update_python_packages_from_requirements(): + # 1) Upgrade pip (if new version available) res = execProcessFromVenv("-m pip install --upgrade pip") if not res: return False - # 2) install only "not yet installed" python packages + # 2) Install only "not yet installed" python packages res = execProcessFromVenv("-m pip install -r install/"+REQUIREMENTS) return res @@ -799,8 +804,13 @@ def venv_pip_install(package_name:str, options:str=''): os.system(VENV_PIP + ' install ' + options + ' ' + package_name) -def install_venv(): - +def install_venv(EVEN_IF_ALREADY_EXISTS:bool=False): + ''' + Install VENV if does not exist + OR + Re-install it if EVEN_IF_ALREADY_EXISTS is true + (return true if no issue) + ''' # -------------------------------------------- # --- Be aware not to create virtual environment in case of user root # -------------------------------------------- @@ -814,7 +824,7 @@ def install_venv(): exit(1) # -------------------------------------------- - # --- Create the (private) venv directory to put in files for virtual environment + # --- (If not exists) Create the (private) venv ROOT directory (where the virtual environment dir will be created) # -------------------------------------------- if (os.path.basename(os.getcwd()) != VENV_ROOT): ##if not(os.path.isdir("../venv")): @@ -822,33 +832,36 @@ def install_venv(): print(Colors.LOG_BLUE + f"-----------------------------Creating 'venv' root directory ({VENV_ROOT}/)-----------------------------" + Colors.END) #os.mkdir("../venv") os.mkdir(VENV_ROOT) + os.chdir(VENV_ROOT) # -------------------------------------------- - # --- Deleting if already exist then creating the venv + # --- (if EVEN_IF_ALREADY_EXISTS) Delete venv dir if already exist # -------------------------------------------- #print(Colors.LOG_BLUE + "-----------------------------cd venv-----------------------------" + Colors.END) - os.chdir(VENV_ROOT) - while True: - try: - if (os.path.isdir(VENV)): - print(Colors.LOG_BLUE + f"-----------------------------Deleting existing VENV dir ({VENV}/)-----------------------------" + Colors.END) - shutil.rmtree(VENV) - break - # Exception on Windows WinError 145 : Cannot remove folder because files in folder not yet removed... - except Exception as e: - #print(e) - continue + if EVEN_IF_ALREADY_EXISTS: + while True: + try: + if os.path.isdir(VENV): + print(Colors.LOG_BLUE + f"-----------------------------Deleting existing VENV dir ({VENV}/)-----------------------------" + Colors.END) + shutil.rmtree(VENV) + break + # Exception on Windows WinError 145 : Cannot remove folder because files in folder not yet removed... + except Exception as e: + #print(e) + continue # -------------------------------------------- - # --- Reinstall the virtual environment (from ../venv/) + # --- (if not exists) Reinstall the virtual environment (from ../venv/) # -------------------------------------------- - print(Colors.LOG_BLUE + f"-----------------------------Creating venv dir ({VENV}/)-----------------------------"+END_OF_LINE + Colors.END) - os.system(GLOBAL_PYTHON+" -m venv " + VENV) + if not os.path.isdir(VENV): + print(Colors.LOG_BLUE + f"-----------------------------Creating venv dir ({VENV}/)-----------------------------"+END_OF_LINE + Colors.END) + os.system(GLOBAL_PYTHON+" -m venv " + VENV) - # Come back + # Come back to project root os.chdir('..') + return True def install_packages(): @@ -876,7 +889,7 @@ def install_packages(): print(Colors.LOG_BLUE + "-----------------------------Installing python packages via pip-----------------------------" + Colors.END) venv_pip_install('../install/'+REQUIREMENTS, '-r') #os.system(VENV_PIP+' install -r ../install' + os.sep + REQUIREMENTS) - + #print(Colors.LOG_BLUE + "-----------------------------cd ../install-----------------------------" + Colors.END) if IS_WINDOWS: @@ -902,6 +915,9 @@ def install_packages(): print(Colors.ERROR + "ERROR while Copying the voevent library in Lib/site-packages" + Colors.END) ; #, file=stderr) return False + # Go back to project root dir + os.chdir('..') + #return 0 return True -- libgit2 0.21.2