forked from wizarrrr/wizarr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.py
More file actions
161 lines (134 loc) · 5.43 KB
/
dev.py
File metadata and controls
161 lines (134 loc) · 5.43 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
153
154
155
156
157
158
159
160
161
import argparse
import subprocess
import sys
from pathlib import Path
def check_node_installation():
print("Checking Node.js and npm installation...")
try:
node_version = subprocess.run(
["node", "--version"], capture_output=True, text=True, check=True
).stdout.strip()
print(f"✓ Node.js {node_version} is installed")
npm_version = subprocess.run(
["npm", "--version"], capture_output=True, text=True, check=True
).stdout.strip()
print(f"✓ npm {npm_version} is installed")
except subprocess.CalledProcessError:
print("❌ Node.js and/or npm is not installed!")
print("Please install Node.js and npm before running this script.")
print("You can download them from: https://nodejs.org/")
sys.exit(1)
def check_uv_installation():
print("Checking uv installation...")
try:
uv_version = subprocess.run(
["uv", "--version"], capture_output=True, text=True, check=True
).stdout.strip()
print(f"✓ uv {uv_version} is installed")
except subprocess.CalledProcessError:
print("❌ uv is not installed!")
print("Please install uv before running this script.")
print(
"You can download it from: https://docs.astral.sh/uv/getting-started/installation/"
)
sys.exit(1)
def run_command(command, cwd=None, env=None):
print(f"Running: {' '.join(command)}")
try:
process = subprocess.Popen(command, cwd=cwd, env=env)
process.wait()
if process.returncode != 0:
print(f"Error running command: {' '.join(command)}")
print(f"Error code: {process.returncode}")
sys.exit(1)
except KeyboardInterrupt:
print("\nReceived interrupt signal. Shutting down...")
process.terminate()
process.wait()
sys.exit(0)
except Exception as e:
print(f"Error running command: {' '.join(command)}")
print(f"Error: {e}")
sys.exit(1)
def main():
import os
parser = argparse.ArgumentParser(
description="Wizarr development server",
epilog="""
Examples:
python dev.py # Start development server (default)
python dev.py --scheduler # Start with background scheduler enabled
python dev.py --plus # Start with Plus features enabled
python dev.py --plus --scheduler # Start with both Plus and scheduler enabled
The scheduler runs maintenance tasks like:
- Expiry cleanup (every 1 minute in dev mode)
- User account deletion for expired users
- Server-specific expiry enforcement
Plus features include:
- Audit logging for admin actions
- Advanced analytics and reporting
- Enhanced security features
""",
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"--scheduler",
action="store_true",
help="Enable the background scheduler for testing expiry and maintenance tasks",
)
parser.add_argument(
"--plus",
action="store_true",
help="Enable Plus features including audit logging and advanced analytics",
)
args = parser.parse_args()
check_node_installation()
check_uv_installation()
project_root = Path(__file__).parent
static_dir = project_root / "app" / "static"
# Create dev environment with NODE_ENV=development to ensure devDependencies are installed
npm_env = os.environ.copy()
npm_env["NODE_ENV"] = "development"
print("Compiling translations...")
run_command(["uv", "run", "pybabel", "compile", "-d", "app/translations", "-f"])
print("Running database setup...")
print("Applying alembic migrations...")
run_command(["uv", "run", "flask", "db", "upgrade"])
print("Installing/updating npm dependencies...")
run_command(["npm", "install"], cwd=static_dir, env=npm_env)
print("Building static assets (CSS & JS)...")
run_command(["npm", "run", "build"], cwd=static_dir, env=npm_env)
# Start the Tailwind watcher in the background
print("Starting Tailwind watcher...")
tailwind_process = subprocess.Popen(
["npm", "run", "watch:css"], cwd=static_dir, env=npm_env
)
try:
flask_command = ["uv", "run", "flask", "run", "--debug"]
# Set environment variables based on flags
if args.scheduler:
print(
"🕒 Scheduler enabled - background tasks will run (expiry cleanup every 1 minute)"
)
os.environ["WIZARR_ENABLE_SCHEDULER"] = "true"
else:
print(
"ℹ️ Scheduler disabled - use --scheduler flag to enable background tasks"
)
if args.plus:
print(
"⭐ Plus features enabled - audit logging and advanced features available"
)
os.environ["WIZARR_PLUS_ENABLED"] = "true"
else:
print(
"ℹ️ Plus features disabled - use --plus flag to enable audit logging and advanced features"
)
print("Starting Flask development server...")
run_command(flask_command)
finally:
# Ensure we clean up the Tailwind process when Flask exits
tailwind_process.terminate()
tailwind_process.wait()
if __name__ == "__main__":
main()