-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·123 lines (101 loc) · 4.53 KB
/
Copy pathsetup.py
File metadata and controls
executable file
·123 lines (101 loc) · 4.53 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
#!/usr/bin/env python3
# Description: System deployment utility. Maps project binaries to
# ~/.local/bin via transparent shell wrappers and
# configures user-level systemd services.
# Usage: ./setup.py
import os
import shutil
import subprocess
import sys
from pathlib import Path
def get_venv_python(repo_root: Path) -> Path:
"""Retrieves the Python interpreter from the uv-managed virtual environment."""
venv_python = repo_root / ".venv" / "bin" / "python"
if not venv_python.exists():
print(
f"❌ Error: Virtual environment not found at {venv_python}. Run 'uv sync' first."
)
sys.exit(1)
return venv_python
def create_executable_wrapper(src_script: Path, target_link: Path, venv_python: Path):
"""Generates a shell shim that points directly to the project's venv."""
if not src_script.exists():
print(f"⚠️ Warning: Source file missing: {src_script}", file=sys.stderr)
return
# Ensure the script is executable
src_script.chmod(src_script.stat().st_mode | 0o111)
# Transparent wrapper strategy
wrapper_content = f'#!/bin/sh\nexec "{venv_python}" "{src_script}" "$@"\n'
try:
if target_link.exists() or target_link.is_symlink():
target_link.unlink()
target_link.write_text(wrapper_content)
target_link.chmod(0o755)
# Display relative path for cleanliness
print(
f"🔹 Command mapped: {target_link.name} -> {src_script.relative_to(src_script.parent.parent.parent)}"
)
except Exception as e:
print(f"❌ Failed to map command {target_link.name}: {e}", file=sys.stderr)
def setup_systemd_services(repo_root: Path, is_headless: bool):
"""Deploys systemd user services."""
if is_headless:
return
service_src = repo_root / "src" / "services" / "battery-monitor.service"
if not service_src.exists():
return
systemd_user_dir = Path.home() / ".config" / "systemd" / "user"
systemd_user_dir.mkdir(parents=True, exist_ok=True)
target_service = systemd_user_dir / service_src.name
try:
if target_service.exists() or target_service.is_symlink():
target_service.unlink()
shutil.copy(str(service_src), str(target_service))
subprocess.run(["systemctl", "--user", "daemon-reload"], check=True)
subprocess.run(["systemctl", "--user", "enable", service_src.name], check=True)
print(f"✅ Service '{service_src.name}' installed and enabled.")
except Exception as e:
print(f"❌ Systemd configuration failed: {e}", file=sys.stderr)
def main():
repo_root = Path(__file__).resolve().parent
bin_dir = Path.home() / ".local" / "bin"
bin_dir.mkdir(parents=True, exist_ok=True)
is_headless = not (os.environ.get("DISPLAY") or os.environ.get("WAYLAND_DISPLAY"))
print("🚀 Starting deployment of system shims...")
# Get the Python interpreter managed by uv
venv_python = get_venv_python(repo_root)
# Centralized configuration mapping pointing to the new src layout
commands_to_install = {
bin_dir / "toggle-touchpad": repo_root
/ "src"
/ "desktop"
/ "toggle-touchpad.py",
bin_dir / "toggle-touchpad-click": repo_root
/ "src"
/ "desktop"
/ "toggle-touchpad-wrapper.py",
bin_dir / "bv360": repo_root / "src" / "multimedia" / "yt-download-360p.py",
bin_dir / "yta": repo_root / "src" / "multimedia" / "yt-extract-audio.py",
bin_dir / "ytfa": repo_root
/ "src"
/ "multimedia"
/ "yt-extract-fusion-audio.py",
bin_dir / "battery_monitor": repo_root
/ "src"
/ "services"
/ "battery-monitor.py",
bin_dir / "dumpcode": repo_root / "src" / "dev" / "dumpcode.py",
bin_dir / "rfwmtime": repo_root / "src" / "utils" / "rfwmtime.py",
bin_dir / "hx-jump": repo_root / "src" / "dev" / "hx-jump.py",
bin_dir / "hx-find": repo_root / "src" / "dev" / "hx-find.py",
bin_dir / "git-sync-check": repo_root / "src" / "dev" / "git-sync-check.py",
bin_dir / "check-pass": repo_root / "src" / "utils" / "check-pass.py",
bin_dir / "new-project": repo_root / "src" / "dev" / "new-project.py",
bin_dir / "git-scan": repo_root / "src" / "dev" / "git-scan.py",
}
for target, src in commands_to_install.items():
create_executable_wrapper(src, target, venv_python)
setup_systemd_services(repo_root, is_headless)
print("\n🎉 Deployment complete.")
if __name__ == "__main__":
main()