forked from ChuckBuilds/LEDMatrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_web_v2.py
More file actions
executable file
·113 lines (96 loc) · 3.39 KB
/
start_web_v2.py
File metadata and controls
executable file
·113 lines (96 loc) · 3.39 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
#!/usr/bin/env python3
"""
LED Matrix Web Interface V2 Startup Script
Modern, lightweight web interface with real-time display preview and editor mode.
"""
import os
import sys
import subprocess
import logging
from pathlib import Path
# Setup logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('/tmp/web_interface_v2.log'),
logging.StreamHandler()
]
)
logger = logging.getLogger(__name__)
def check_dependencies():
"""Check if required dependencies are installed."""
required_packages = [
'flask',
'flask_socketio',
'PIL',
'socketio',
'eventlet',
'freetype'
]
missing_packages = []
for package in required_packages:
try:
__import__(package)
except ImportError:
missing_packages.append(package)
if missing_packages:
logger.warning(f"Missing packages: {missing_packages}")
logger.info("Installing missing packages...")
try:
subprocess.check_call([
sys.executable, '-m', 'pip', 'install', '--break-system-packages', '-r', 'requirements_web_v2.txt'
])
logger.info("Dependencies installed successfully")
except subprocess.CalledProcessError as e:
logger.error(f"Failed to install dependencies: {e}")
return False
# Install rgbmatrix module from local source
logger.info("Installing rgbmatrix module...")
try:
rgbmatrix_path = Path(__file__).parent / 'rpi-rgb-led-matrix-master' / 'bindings' / 'python'
subprocess.check_call([
sys.executable, '-m', 'pip', 'install', '--break-system-packages', '-e', str(rgbmatrix_path)
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
logger.info("rgbmatrix module installed successfully")
except subprocess.CalledProcessError as e:
logger.error(f"Failed to install rgbmatrix module: {e}")
return False
return True
def check_permissions():
"""Check if we have necessary permissions for system operations."""
try:
# Test sudo access
result = subprocess.run(['sudo', '-n', 'true'], capture_output=True)
if result.returncode != 0:
logger.warning("Sudo access not available. Some system features may not work.")
return False
return True
except Exception as e:
logger.error(f"Error checking permissions: {e}")
return False
def main():
"""Main startup function."""
logger.info("Starting LED Matrix Web Interface V2...")
# Change to script directory
script_dir = Path(__file__).parent
os.chdir(script_dir)
# Check dependencies
if not check_dependencies():
logger.error("Dependency check failed. Exiting.")
sys.exit(1)
# Check permissions
check_permissions()
# Import and start the web interface using system Python
try:
logger.info("Web interface loaded successfully")
# Start the server using system Python
logger.info("Starting web server on http://0.0.0.0:5001")
subprocess.run([
sys.executable, 'web_interface_v2.py'
])
except Exception as e:
logger.error(f"Failed to start web interface: {e}")
sys.exit(1)
if __name__ == '__main__':
main()