Commit 779e1df95c5ef4b82998c88a9807e2fd2ad268ff
1 parent
330b3374
Exists in
dev
pyros.py update => recrée le venv et reinstalle packages si venv disparu
Showing
1 changed file
with
43 additions
and
27 deletions
Show diff stats
pyros.py
... | ... | @@ -387,7 +387,7 @@ def install(packages_only, database_only): |
387 | 387 | if not packages_only and not database_only: |
388 | 388 | packages_only = database_only = True |
389 | 389 | if packages_only: |
390 | - install_venv() | |
390 | + install_venv(True) | |
391 | 391 | install_packages() |
392 | 392 | if database_only: install_database(VENV) |
393 | 393 | ''' |
... | ... | @@ -447,13 +447,18 @@ def update(): |
447 | 447 | printFullTerm(Colors.BLUE, "1) UPDATING SOURCE CODE: Running git pull") |
448 | 448 | _gitpull() or die() |
449 | 449 | |
450 | - # 2) Update python packages (pip install requirements) | |
450 | + # Re-install VENV if disappeared | |
451 | + install_venv(False) | |
452 | + | |
453 | + # 2) Update python packages (pip upgrade AND pip install requirements) | |
451 | 454 | printFullTerm(Colors.BLUE, "2) UPDATING PYTHON PACKAGES") |
452 | - _update_python_packages_from_requirements() or die() | |
453 | - | |
455 | + ##_update_python_packages_from_requirements() or die() | |
456 | + install_packages() | |
457 | + print(os.getcwd()) | |
454 | 458 | # 3) Update PlantUML diagrams |
455 | 459 | printFullTerm(Colors.BLUE, "3) UPDATING PLANTUML DIAGRAMS") |
456 | 460 | _update_plantuml_diags() or die() |
461 | + print(os.getcwd()) | |
457 | 462 | |
458 | 463 | # 4) Update database structure (make migrations + migrate) |
459 | 464 | printFullTerm(Colors.BLUE, "4) UPDATING DATABASE") |
... | ... | @@ -623,11 +628,11 @@ def stop(agent): |
623 | 628 | ******************************************************************************** |
624 | 629 | """ |
625 | 630 | |
626 | -def _update_python_packages_from_requirements(): | |
627 | - # 1) try to upgrade pip | |
631 | +def notused_update_python_packages_from_requirements(): | |
632 | + # 1) Upgrade pip (if new version available) | |
628 | 633 | res = execProcessFromVenv("-m pip install --upgrade pip") |
629 | 634 | if not res: return False |
630 | - # 2) install only "not yet installed" python packages | |
635 | + # 2) Install only "not yet installed" python packages | |
631 | 636 | res = execProcessFromVenv("-m pip install -r install/"+REQUIREMENTS) |
632 | 637 | return res |
633 | 638 | |
... | ... | @@ -799,8 +804,13 @@ def venv_pip_install(package_name:str, options:str=''): |
799 | 804 | os.system(VENV_PIP + ' install ' + options + ' ' + package_name) |
800 | 805 | |
801 | 806 | |
802 | -def install_venv(): | |
803 | - | |
807 | +def install_venv(EVEN_IF_ALREADY_EXISTS:bool=False): | |
808 | + ''' | |
809 | + Install VENV if does not exist | |
810 | + OR | |
811 | + Re-install it if EVEN_IF_ALREADY_EXISTS is true | |
812 | + (return true if no issue) | |
813 | + ''' | |
804 | 814 | # -------------------------------------------- |
805 | 815 | # --- Be aware not to create virtual environment in case of user root |
806 | 816 | # -------------------------------------------- |
... | ... | @@ -814,7 +824,7 @@ def install_venv(): |
814 | 824 | exit(1) |
815 | 825 | |
816 | 826 | # -------------------------------------------- |
817 | - # --- Create the (private) venv directory to put in files for virtual environment | |
827 | + # --- (If not exists) Create the (private) venv ROOT directory (where the virtual environment dir will be created) | |
818 | 828 | # -------------------------------------------- |
819 | 829 | if (os.path.basename(os.getcwd()) != VENV_ROOT): |
820 | 830 | ##if not(os.path.isdir("../venv")): |
... | ... | @@ -822,33 +832,36 @@ def install_venv(): |
822 | 832 | print(Colors.LOG_BLUE + f"-----------------------------Creating 'venv' root directory ({VENV_ROOT}/)-----------------------------" + Colors.END) |
823 | 833 | #os.mkdir("../venv") |
824 | 834 | os.mkdir(VENV_ROOT) |
835 | + os.chdir(VENV_ROOT) | |
825 | 836 | |
826 | 837 | |
827 | 838 | # -------------------------------------------- |
828 | - # --- Deleting if already exist then creating the venv | |
839 | + # --- (if EVEN_IF_ALREADY_EXISTS) Delete venv dir if already exist | |
829 | 840 | # -------------------------------------------- |
830 | 841 | #print(Colors.LOG_BLUE + "-----------------------------cd venv-----------------------------" + Colors.END) |
831 | - os.chdir(VENV_ROOT) | |
832 | - while True: | |
833 | - try: | |
834 | - if (os.path.isdir(VENV)): | |
835 | - print(Colors.LOG_BLUE + f"-----------------------------Deleting existing VENV dir ({VENV}/)-----------------------------" + Colors.END) | |
836 | - shutil.rmtree(VENV) | |
837 | - break | |
838 | - # Exception on Windows WinError 145 : Cannot remove folder because files in folder not yet removed... | |
839 | - except Exception as e: | |
840 | - #print(e) | |
841 | - continue | |
842 | + if EVEN_IF_ALREADY_EXISTS: | |
843 | + while True: | |
844 | + try: | |
845 | + if os.path.isdir(VENV): | |
846 | + print(Colors.LOG_BLUE + f"-----------------------------Deleting existing VENV dir ({VENV}/)-----------------------------" + Colors.END) | |
847 | + shutil.rmtree(VENV) | |
848 | + break | |
849 | + # Exception on Windows WinError 145 : Cannot remove folder because files in folder not yet removed... | |
850 | + except Exception as e: | |
851 | + #print(e) | |
852 | + continue | |
842 | 853 | |
843 | 854 | # -------------------------------------------- |
844 | - # --- Reinstall the virtual environment (from ../venv/) | |
855 | + # --- (if not exists) Reinstall the virtual environment (from ../venv/) | |
845 | 856 | # -------------------------------------------- |
846 | 857 | |
847 | - print(Colors.LOG_BLUE + f"-----------------------------Creating venv dir ({VENV}/)-----------------------------"+END_OF_LINE + Colors.END) | |
848 | - os.system(GLOBAL_PYTHON+" -m venv " + VENV) | |
858 | + if not os.path.isdir(VENV): | |
859 | + print(Colors.LOG_BLUE + f"-----------------------------Creating venv dir ({VENV}/)-----------------------------"+END_OF_LINE + Colors.END) | |
860 | + os.system(GLOBAL_PYTHON+" -m venv " + VENV) | |
849 | 861 | |
850 | - # Come back | |
862 | + # Come back to project root | |
851 | 863 | os.chdir('..') |
864 | + return True | |
852 | 865 | |
853 | 866 | |
854 | 867 | def install_packages(): |
... | ... | @@ -876,7 +889,7 @@ def install_packages(): |
876 | 889 | print(Colors.LOG_BLUE + "-----------------------------Installing python packages via pip-----------------------------" + Colors.END) |
877 | 890 | venv_pip_install('../install/'+REQUIREMENTS, '-r') |
878 | 891 | #os.system(VENV_PIP+' install -r ../install' + os.sep + REQUIREMENTS) |
879 | - | |
892 | + | |
880 | 893 | #print(Colors.LOG_BLUE + "-----------------------------cd ../install-----------------------------" + Colors.END) |
881 | 894 | |
882 | 895 | if IS_WINDOWS: |
... | ... | @@ -902,6 +915,9 @@ def install_packages(): |
902 | 915 | print(Colors.ERROR + "ERROR while Copying the voevent library in Lib/site-packages" + Colors.END) ; #, file=stderr) |
903 | 916 | return False |
904 | 917 | |
918 | + # Go back to project root dir | |
919 | + os.chdir('..') | |
920 | + | |
905 | 921 | #return 0 |
906 | 922 | return True |
907 | 923 | ... | ... |