-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_and_run.py
More file actions
74 lines (59 loc) · 2.51 KB
/
check_and_run.py
File metadata and controls
74 lines (59 loc) · 2.51 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
# -------------------------------------------------------------------
# Programmer : Ebrahim Shafiei (EbraSha)
# Email : Prof.Shafiei@Gmail.com
# -------------------------------------------------------------------
import subprocess
import sys
import os
try:
from importlib.metadata import version, PackageNotFoundError
except ImportError:
from importlib_metadata import version, PackageNotFoundError # For Python <3.8 with backport
# Path to flag file indicating base tools have already been ensured
FLAG_FILE = ".base_tools_installed.flag"
# Step 1: Ensure pip and setuptools are installed and upgraded (only once)
def ensure_base_tools():
if os.path.exists(FLAG_FILE):
# print("[*] Base tools already ensured, skipping...")
return
try:
print("[+] Ensuring pip and setuptools are installed and up-to-date...")
subprocess.check_call([sys.executable, "-m", "ensurepip", "--upgrade"])
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "pip", "setuptools"])
# Create a flag file to remember the setup was done
with open(FLAG_FILE, "w") as f:
f.write("base tools installed")
print("[+] pip and setuptools setup completed.")
except subprocess.CalledProcessError as e:
print(f"[!] Error while upgrading pip/setuptools: {e}")
sys.exit(1)
# Step 2: Define required packages and versions
required_packages = {
"beautifulsoup4": "4.13.3",
"undetected-chromedriver": "3.5.5",
"httpx": "0.28.1",
"colorama": "0.4.6"
}
# Step 3: Check if correct version of package is installed
def is_correct_version_installed(pkg_name, required_version):
try:
installed_version = version(pkg_name)
return installed_version == required_version
except PackageNotFoundError:
return False
# Step 4: Install specific package version
def install_package(pkg_name, ver):
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", f"{pkg_name}=={ver}"])
except subprocess.CalledProcessError as e:
print(f"[!] Failed to install {pkg_name}=={ver}: {e}")
sys.exit(1)
# Execute all steps
if __name__ == "__main__":
ensure_base_tools()
for pkg, ver in required_packages.items():
if not is_correct_version_installed(pkg, ver):
print(f"[+] Installing or upgrading: {pkg}=={ver}")
install_package(pkg, ver)
# Step 5: Run the main script
subprocess.call([sys.executable, "abdal-web-intelligence-analyzer.py"])