Repository navigation
Expand file tree
/
Copy pathtest-tools-main.py
More file actions
97 lines (75 loc) · 2.96 KB
/
Copy pathtest-tools-main.py
File metadata and controls
97 lines (75 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python3
import os
import sys
import subprocess
import shlex
from pathlib import Path
# Chemin vers le dossier contenant les outils python dans tools-main
BASE_DIR = Path(__file__).resolve().parent
TOOLS_DIR = BASE_DIR / "third_party" / "tools-main" / "python"
def list_available_tools():
"""Liste tous les fichiers .py disponibles dans le dossier des outils."""
if not TOOLS_DIR.exists():
print(f"❌ Le dossier {TOOLS_DIR} n'existe pas.")
return []
tools = [f.name for f in TOOLS_DIR.glob("*.py") if not f.name.startswith("__")]
return sorted(tools)
def main():
tools = list_available_tools()
print("=" * 60)
print(" 🛠️ Runner d'outils tools-main")
print("=" * 60)
print(f"Dossier des outils : {TOOLS_DIR}")
print("Tapez 'quit' ou 'exit' à n'importe quel moment pour quitter.\n")
if tools:
print("Outils disponibles dans le dossier :")
for tool in tools:
print(f" - {tool}")
print()
while True:
try:
# 1. Demande le nom de l'outil Python
tool_name = input("\nNom de l'outil (ex: all_gcp_buckets.py) : ").strip()
if tool_name.lower() in ("quit", "exit", "q"):
print("Au revoir !")
break
if not tool_name:
continue
# Ajoute l'extension .py si omise
if not tool_name.endswith(".py"):
tool_name += ".py"
tool_path = TOOLS_DIR / tool_name
if not tool_path.exists():
print(f"❌ Erreur : L'outil '{tool_name}' est introuvable dans {TOOLS_DIR}")
continue
# 2. Demande les arguments / inputs pour cet outil
args_input = input(f"Entrez les arguments/inputs pour {tool_name} (ex: test ou --help) : ").strip()
if args_input.lower() in ("quit", "exit", "q"):
print("Au revoir !")
break
# Découpage propre des arguments
extra_args = shlex.split(args_input) if args_input else []
# 3. Exécution du script et affichage du résultat
cmd = [sys.executable, str(tool_path)] + extra_args
print(f"\n🚀 Exécution : {' '.join(cmd)}")
print("-" * 50)
result = subprocess.run(
cmd,
capture_output=True,
text=True
)
if result.stdout:
print("--- [STDOUT] ---")
print(result.stdout)
if result.stderr:
print("--- [STDERR] ---")
print(result.stderr)
print(f"Code de sortie : {result.returncode}")
print("-" * 50)
except KeyboardInterrupt:
print("\n\nInterruption par l'utilisateur. Au revoir !")
break
except Exception as e:
print(f"❌ Erreur lors de l'exécution : {e}")
if __name__ == "__main__":
main()