New Installation file created for unix system

This commit is contained in:
adator
2024-08-22 01:01:21 +02:00
parent d7fab2d701
commit 88b9b056ca
8 changed files with 401 additions and 45 deletions

View File

@@ -1,12 +1,16 @@
from importlib.util import find_spec
from subprocess import check_call, run
from subprocess import check_call, run, CalledProcessError
from platform import python_version
from sys import exit
import os
class Install:
def __init__(self) -> None:
self.PYTHON_MIN_VERSION = '3.10'
self.venv_folder_name = '.pyenv'
self.cmd_venv_command = ['python3', '-m', 'venv', self.venv_folder_name]
self.module_to_install = ['sqlalchemy','psutil','requests']
if not self.checkPythonVersion():
@@ -38,6 +42,17 @@ class Install:
return True
def run_subprocess(self, command:list) -> None:
print(command)
try:
check_call(command)
print("La commande s'est terminée avec succès.")
except CalledProcessError as e:
print(f"La commande a échoué avec le code de retour :{e.returncode}")
print(f"Try to install dependencies ...")
exit(5)
def checkDependencies(self) -> None:
"""### Verifie les dépendances si elles sont installées
- Test si les modules sont installés
@@ -46,6 +61,11 @@ class Install:
"""
do_install = False
# Check if virtual env exist
if not os.path.exists(f'{self.venv_folder_name}'):
self.run_subprocess(self.cmd_venv_command)
do_install = True
for module in self.module_to_install:
if find_spec(module) is None:
do_install = True
@@ -70,3 +90,10 @@ class Install:
print(f"====> Module {module} installé")
else:
print(f"==> {module} already installed")
print(f"#"*12)
print("Installation complete ...")
print("You must change environment using the command below")
print(f"source {self.venv_folder_name}{os.sep}bin{os.sep}activate")
print(f"#"*12)
exit(1)