-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsyncz
More file actions
executable file
·75 lines (61 loc) · 2.21 KB
/
syncz
File metadata and controls
executable file
·75 lines (61 loc) · 2.21 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
#!/usr/bin/env python3
"""SyncZ CLI wrapper for launching the main client from a src layout."""
import os
import sys
import subprocess
from pathlib import Path
SCRIPT_DIR = Path(__file__).resolve().parent
SRC_DIR = SCRIPT_DIR / "src"
CLIENT_PATH = SRC_DIR / "syncz" / "client.py"
VENV_PYTHON = SCRIPT_DIR / ".venv" / "bin" / "python"
MODULE_ENTRYPOINT = "syncz.client"
def get_python_command():
"""Get the appropriate Python command to use."""
if VENV_PYTHON.exists():
return str(VENV_PYTHON)
for candidate in ("python3", "python"):
try:
subprocess.run(
[candidate, "--version"], check=True, capture_output=True
)
return candidate
except (subprocess.CalledProcessError, FileNotFoundError):
continue
termux_python = Path("/data/data/com.termux/files/usr/bin/python")
if termux_python.exists():
return str(termux_python)
print("❌ Error: Python not found. Please install Python 3.")
print(f" Tried virtual env: {VENV_PYTHON}")
print(" Tried: python3, python")
sys.exit(1)
def build_env():
"""Return environment with src on PYTHONPATH so imports work."""
env = os.environ.copy()
src_path = str(SRC_DIR)
existing = env.get("PYTHONPATH", "")
env["PYTHONPATH"] = (
src_path if not existing else f"{src_path}{os.pathsep}{existing}"
)
return env
def main():
"""Main entry point for syncz command."""
if not CLIENT_PATH.exists():
print(f"❌ Error: client.py not found at {CLIENT_PATH}")
print("📁 Contents of src directory:")
try:
for item in sorted(SRC_DIR.iterdir()):
print(f" - {item.name}")
except Exception as e: # pragma: no cover - defensive logging
print(f" Error listing src directory: {e}")
sys.exit(1)
python_cmd = get_python_command()
args = [python_cmd, "-m", MODULE_ENTRYPOINT] + sys.argv[1:]
env = build_env()
try:
os.chdir(SCRIPT_DIR)
os.execvpe(python_cmd, args, env)
except Exception as e: # pragma: no cover - exec failure path
print(f"❌ Error executing syncz: {e}")
sys.exit(1)
if __name__ == "__main__":
main()