-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.py
More file actions
152 lines (130 loc) · 5.2 KB
/
launch.py
File metadata and controls
152 lines (130 loc) · 5.2 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import argparse
import os
import sys
import subprocess
import platform
import urllib.request
import tarfile
import zipfile
import shutil
def install_python_dependencies():
"""Install Python dependencies from requirements.txt."""
print("Installing Python dependencies from requirements.txt...")
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
print("Python dependencies installed successfully.")
except subprocess.CalledProcessError as e:
print(f"Error installing Python dependencies: {e}", file=sys.stderr)
sys.exit(1)
def get_ffuf_url():
"""Determine the correct ffuf download URL based on OS and architecture."""
system = platform.system().lower()
machine = platform.machine().lower()
if system == "linux":
if "aarch64" in machine or "arm64" in machine:
arch = "arm64"
else:
arch = "amd64"
ext = "tar.gz"
elif system == "darwin":
arch = "amd64"
ext = "tar.gz"
elif system == "windows":
arch = "amd64"
ext = "zip"
else:
print(f"Unsupported OS: {system}", file=sys.stderr)
return None
url = f"https://github.com/ffuf/ffuf/releases/download/v2.1.0/ffuf_2.1.0_{system}_{arch}.{ext}"
return url
def install_ffuf():
"""Download and extract the ffuf binary."""
print("Installing ffuf...")
ffuf_url = get_ffuf_url()
if not ffuf_url:
sys.exit(1)
bin_dir = "bin"
os.makedirs(bin_dir, exist_ok=True)
ffuf_path = os.path.join(bin_dir, "ffuf.exe" if platform.system().lower() == "windows" else "ffuf")
if os.path.exists(ffuf_path):
print("ffuf is already installed.")
return
try:
filename = os.path.basename(ffuf_url)
download_path = os.path.join(bin_dir, filename)
print(f"Downloading ffuf from {ffuf_url}...")
urllib.request.urlretrieve(ffuf_url, download_path)
print("Download complete.")
print("Extracting ffuf...")
if download_path.endswith(".tar.gz"):
with tarfile.open(download_path, "r:gz") as tar:
tar.extract("ffuf", path=bin_dir)
elif download_path.endswith(".zip"):
with zipfile.ZipFile(download_path, "r") as zip_ref:
zip_ref.extract("ffuf.exe", path=bin_dir)
os.remove(download_path)
if os.path.exists(ffuf_path):
os.chmod(ffuf_path, 0o755)
print("ffuf installed successfully.")
else:
print("Error: ffuf executable not found after extraction.", file=sys.stderr)
except Exception as e:
print(f"Error installing ffuf: {e}", file=sys.stderr)
sys.exit(1)
def check_exiftool():
"""Check if exiftool is installed and provide instructions if not."""
print("Checking for exiftool...")
if shutil.which("exiftool"):
print("exiftool is installed.")
else:
print("\n---")
print("Warning: exiftool not found in your system's PATH.", file=sys.stderr)
print("The metadata extraction feature will be limited without it.", file=sys.stderr)
print("Please install it using your system's package manager:", file=sys.stderr)
print(" - Debian/Ubuntu: sudo apt-get install libimage-exiftool-perl", file=sys.stderr)
print(" - Fedora/RHEL: sudo dnf install perl-Image-ExifTool", file=sys.stderr)
print(" - Arch Linux: sudo pacman -S perl-image-exiftool", file=sys.stderr)
print(" - macOS (Homebrew): brew install exiftool", file=sys.stderr)
print(" - Windows: Download from https://exiftool.org/", file=sys.stderr)
print("---\n")
def handle_install():
"""Run the complete installation process."""
print("Starting MetaSpidey setup...")
install_python_dependencies()
install_ffuf()
check_exiftool()
print("\nInstallation complete. You can now run the application with 'python launch.py run'.")
def handle_run():
"""Run the main MetaSpidey application."""
print("Launching MetaSpidey...")
main_script_path = os.path.join("MetaSpidey", "main.py")
if not os.path.exists(main_script_path):
print(f"Error: Main script not found at {main_script_path}", file=sys.stderr)
sys.exit(1)
try:
subprocess.run([sys.executable, main_script_path])
except Exception as e:
print(f"Error launching MetaSpidey: {e}", file=sys.stderr)
sys.exit(1)
def handle_build():
"""Placeholder for the build/packaging logic."""
print("Build logic not yet implemented.")
def main():
"""Main function to parse arguments and call the appropriate handler."""
parser = argparse.ArgumentParser(
description="MetaSpidey Launcher: A tool to install, run, and build the MetaSpidey application."
)
parser.add_argument(
"command",
choices=["install", "run", "build"],
help="The command to execute: 'install' to set up dependencies, 'run' to start the application, 'build' to package it."
)
args = parser.parse_args()
if args.command == "install":
handle_install()
elif args.command == "run":
handle_run()
elif args.command == "build":
handle_build()
if __name__ == "__main__":
main()