diff --git a/pyros.py b/pyros.py index bc5fedd..b26f811 100755 --- a/pyros.py +++ b/pyros.py @@ -115,10 +115,7 @@ try: except KeyError: WITH_DOCKER = False -if type(WITH_DOCKER) is str and re.match("^y$|^Y$|^yes$|^Yes$", WITH_DOCKER.rstrip()) != None: - WITH_DOCKER = True -else: - WITH_DOCKER = False +WITH_DOCKER = type(WITH_DOCKER) is str and re.match("^y$|^Y$|^yes$|^Yes$", WITH_DOCKER.rstrip()) != None my_abs_path = os.path.dirname(os.path.realpath(__file__)) # VENV_ROOT = "private" @@ -568,8 +565,7 @@ 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, - with_database=with_database) + _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) @@ -667,9 +663,9 @@ def _install_or_update(UPDATE: bool = False, with_packages: bool = True, with_da # Upgrade pip if new version available os.system(VENV_PYTHON + ' -m pip install --upgrade pip') # TODO: faire les apt-get intall aussi (indi, ...) - venv_pip_install2(GUITASTRO_PATH + '/install/requirements.txt', '-r') + _venv_pip_install2(GUITASTRO_PATH + '/install/requirements.txt', '-r') #venv_pip_install2(GUITASTRO_PATH + '/install/requirements_linux.txt', '-r') - venv_pip_install2(GUITASTRO_PATH + '/install/requirements_dev.txt', '-r') + _venv_pip_install2(GUITASTRO_PATH + '/install/requirements_dev.txt', '-r') ''' print("Guitastro : Generating (updating) API documentation (using Sphinx)") # Make html doc from RST @@ -682,13 +678,13 @@ def _install_or_update(UPDATE: bool = False, with_packages: bool = True, with_da change_dir("PREVIOUS") ''' - # 5) Update PlantUML diagrams + # 5) Update PlantUML diagrams (in UPDATE or INSTALL mode) num += 1 printFullTerm(Colors.BLUE, f"{num}) UPDATING UML DIAGRAMS") _update_plantuml_diags() or die() print(os.getcwd()) - # 6) Update Sphinx API doc (Non Windows only) + # 6) Update Sphinx API doc (Non Windows only) (in UPDATE or INSTALL mode) num += 1 printFullTerm(Colors.BLUE, f"{num}) UPDATING API DOC (with Sphinx)") if not IS_WINDOWS: @@ -1124,8 +1120,7 @@ def new_start(configfile: str, observatory: str, unit: str, computer_hostname: s # pip = "pip" if platform.system() == "Windows" else "pip3" # TODO: "python -m pip" au lieu de "pip" pip = "pip" if IS_WINDOWS else "pip3" - process = subprocess.Popen( - pip + " install --user --upgrade pykwalify", shell=True) + process = subprocess.Popen(pip + " install --user --upgrade pykwalify", shell=True) process.wait() if process.returncode == 0: # self.addExecuted(self.current_command, command) @@ -1306,12 +1301,9 @@ def _update_api_doc(): print(os.getcwd()) DOC_RST_PATH = "doc/doc_rst/" # 0) Upgrade pip if new version available - if WITH_DOCKER: - os.system(VENV_PYTHON + ' -m pip install --user --upgrade pip') - else: - os.system(VENV_PYTHON + ' -m pip install --upgrade pip') + _venv_pip_install2('pip', '--upgrade') # 1) install/update Sphinx requirements (only if not yet installed) - venv_pip_install2(DOC_RST_PATH+'requirements.txt', '-r') + _venv_pip_install2(DOC_RST_PATH+'requirements.txt', '-r') # 2) make html doc from RST doc # cd doc/sourcedoc/ change_dir(DOC_RST_PATH) @@ -1483,20 +1475,24 @@ def notused_install_required(): exit(1) -def venv_pip_install(package_name: str, options: str = ''): - if WITH_DOCKER: - os.system(VENV_PIP + ' install --user ' + options + ' ' + package_name) - else: - os.system(VENV_PIP + ' install ' + options + ' ' + package_name) +def _venv_pip_install_from_venv(PIP_MODULE: bool, package_name: str, options: str = ''): + ''' + pip install package_name with options + If PIP_MODULE install with 'python -m pip' else install with 'pip' + If WITH_DOCKER => install in user mode (with --user option) + ''' + #_pip_install(options + ' ' + package_name) + pip_cmd = VENV_PYTHON+' -m pip' if PIP_MODULE else VENV_PIP + usermode = '--user' if WITH_DOCKER else '' + os.system(f'{pip_cmd} install {usermode} {options} {package_name}') -def venv_pip_install2(package_name: str, options: str = ''): - if WITH_DOCKER: - os.system(VENV_PYTHON + ' -m pip install --user ' - + options + ' ' + package_name) - else: - os.system(VENV_PYTHON + ' -m pip install ' - + options + ' ' + package_name) +def _venv_pip_install(package_name: str, options: str = ''): + _venv_pip_install_from_venv(False, package_name, options) + + +def _venv_pip_install2(package_name: str, options: str = ''): + _venv_pip_install_from_venv(True, package_name, options) def install_venv(EVEN_IF_ALREADY_EXISTS: bool = False): @@ -1568,10 +1564,7 @@ def install_packages(): print(Colors.LOG_BLUE + "-----------------------------Upgrade pip, wheel, and setuptools" + "-----------------------------"+END_OF_LINE + Colors.END) # Upgrade pip - if WITH_DOCKER: - os.system(VENV_PYTHON + ' -m pip install --user --upgrade pip') - else: - os.system(VENV_PYTHON + ' -m pip install --upgrade pip') + _venv_pip_install2('pip', '--upgrade') ''' if (platform.system() == "Windows"): os.system(venv + '\Scripts\python -m pip install --upgrade pip') @@ -1580,27 +1573,24 @@ def install_packages(): ''' # Pip upgrade wheel and setuptools - venv_pip_install('wheel', '--upgrade') + _venv_pip_install('wheel', '--upgrade') # os.system(VENV_PIP+' install --upgrade wheel') # Not working with python 3.8 (on 17/02/2022) # venv_pip_install('setuptools', '--upgrade') - if WITH_DOCKER: - os.system(VENV_PIP+' install --user setuptools==58') - else: - os.system(VENV_PIP+' install setuptools==58') + _venv_pip_install('setuptools==58') # Pip install required packages from REQUIREMENTS file print() # General normal packages print(Colors.LOG_BLUE + "-----------------------------Installing python packages via pip-----------------------------" + Colors.END) - venv_pip_install('../install/'+REQUIREMENTS, '-r') + _venv_pip_install('../install/'+REQUIREMENTS, '-r') # os.system(VENV_PIP+' install -r ../install' + os.sep + REQUIREMENTS) # DEV only packages if DEV: print(Colors.LOG_BLUE + "-----------------------------Installing DEV python packages via pip-----------------------------" + Colors.END) - venv_pip_install('../install/'+REQUIREMENTS_DEV, '-r') + _venv_pip_install('../install/'+REQUIREMENTS_DEV, '-r') print("FIN INSTALL PACKAGES") return None @@ -1657,12 +1647,9 @@ def install_observatory(observatory): from git import Repo, GitError 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 process.returncode == 0: # self.addExecuted(self.current_command, command) diff --git a/src/core/pyros_django/majordome/agent/A_Basic.py b/src/core/pyros_django/majordome/agent/A_Basic.py index cba3779..7ab0f82 100755 --- a/src/core/pyros_django/majordome/agent/A_Basic.py +++ b/src/core/pyros_django/majordome/agent/A_Basic.py @@ -1,8 +1,9 @@ #!/usr/bin/env python3 -import time -import sys, argparse +#import time +import sys +import argparse import os ##import utils.Logger as L @@ -23,7 +24,6 @@ for short_path in short_paths: if path not in sys.path: sys.path.insert(0, path) - #from src.core.pyros_django.common.models import AgentCmd #from src.core.pyros_django.majordome.agent.Agent import Agent, build_agent from majordome.agent.Agent import Agent, build_agent -- libgit2 0.21.2