|
3 | 3 | import sys
|
4 | 4 | import subprocess
|
5 | 5 |
|
| 6 | +def install_python_3_10(): |
| 7 | + """ |
| 8 | + Verifica se Python 3.10 è installato e, se non lo è, lo installa tramite winget. |
| 9 | + """ |
| 10 | + try: |
| 11 | + # Verifica se Python 3.10 è già installato |
| 12 | + result = subprocess.run(["python3.10", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 13 | + if result.returncode != 0: |
| 14 | + print("Python 3.10 non trovato. Installazione in corso...") |
| 15 | + subprocess.run(["winget", "install", "Python.Python.3.10"], check=True) |
| 16 | + print("Python 3.10 installato con successo.") |
| 17 | + else: |
| 18 | + print("Python 3.10 già installato.") |
| 19 | + except FileNotFoundError: |
| 20 | + print("Python 3.10 non trovato. Installazione in corso...") |
| 21 | + subprocess.run(["winget", "install", "Python.Python.3.10"], check=True) |
| 22 | + print("Python 3.10 installato con successo.") |
| 23 | + except subprocess.CalledProcessError as e: |
| 24 | + print(f"Errore durante l'installazione di Python 3.10: {e}") |
| 25 | + |
| 26 | +def install_requirements(): |
| 27 | + """ |
| 28 | + Installa le dipendenze presenti nel file requirements.txt. |
| 29 | + Se il file non esiste, stampa un messaggio di avviso. |
| 30 | + """ |
| 31 | + requirements_file = 'requirements.txt' |
| 32 | + |
| 33 | + if os.path.isfile(requirements_file): |
| 34 | + print("Trovato requirements.txt. Installazione delle dipendenze...") |
| 35 | + try: |
| 36 | + subprocess.run([sys.executable, "-m", "pip", "install", "-r", requirements_file], check=True) |
| 37 | + print("Dipendenze installate con successo.") |
| 38 | + except subprocess.CalledProcessError as e: |
| 39 | + print(f"Errore durante l'installazione delle dipendenze: {e}") |
| 40 | + else: |
| 41 | + print("requirements.txt non trovato. Nessuna dipendenza da installare.") |
| 42 | + |
6 | 43 | def get_scripts(directory):
|
7 | 44 | """
|
8 | 45 | Restituisce una lista di file .py presenti in 'directory',
|
@@ -51,6 +88,12 @@ def get_description(filepath):
|
51 | 88 | return "Nessuna descrizione disponibile."
|
52 | 89 |
|
53 | 90 | def main():
|
| 91 | + # Installa Python 3.10 se non è già installato |
| 92 | + install_python_3_10() |
| 93 | + |
| 94 | + # Installa le dipendenze da requirements.txt (se presente) |
| 95 | + install_requirements() |
| 96 | + |
54 | 97 | # Se esiste una cartella "scripts", usiamola, altrimenti la directory corrente
|
55 | 98 | base_dir = os.getcwd()
|
56 | 99 | scripts_dir = os.path.join(base_dir, "scripts")
|
|
0 commit comments