-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilefinder.py
More file actions
54 lines (40 loc) · 1.49 KB
/
Filefinder.py
File metadata and controls
54 lines (40 loc) · 1.49 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
import subprocess
import sys
from pathlib import Path
VENV_DIR = Path("./sbom_backend_venv")
REQUIREMENTS_FILE = Path("requirements.txt")
MAIN_SCRIPT = Path("Main.py")
def run(cmd, check=True):
print(f"[cmd] {' '.join(map(str, cmd))}")
subprocess.run(cmd, check=check)
def main():
if not sys.executable:
print("[!] Python interpreter not found.")
sys.exit(1)
print(f"[i] Using Python interpreter: {sys.executable}")
if not VENV_DIR.exists():
print("[i] Creating virtual environment...")
run([sys.executable, "-m", "venv", str(VENV_DIR)])
pip_path = VENV_DIR / "bin" / "pip"
python_path = VENV_DIR / "bin" / "python"
if not pip_path.exists():
pip_path = VENV_DIR / "Scripts" / "pip.exe"
python_path = VENV_DIR / "Scripts" / "python.exe"
if not pip_path.exists() or not python_path.exists():
print("[!] Virtual environment tools not found.")
sys.exit(1)
run([str(pip_path), "install", "--upgrade", "pip"])
if REQUIREMENTS_FILE.exists():
print(f"[i] Installing dependencies from {REQUIREMENTS_FILE}...")
run([str(pip_path), "install", "-r", str(REQUIREMENTS_FILE)])
else:
print(f"[!] {REQUIREMENTS_FILE} not found.")
sys.exit(1)
if MAIN_SCRIPT.exists():
print(f"[i] Running {MAIN_SCRIPT}...")
run([str(python_path), str(MAIN_SCRIPT)])
else:
print(f"[!] {MAIN_SCRIPT} not found.")
sys.exit(1)
if __name__ == "__main__":
main()