updated to browser view
This commit is contained in:
BIN
__pycache__/dependency_utils.cpython-311.pyc
Normal file
BIN
__pycache__/dependency_utils.cpython-311.pyc
Normal file
Binary file not shown.
153
app.py
153
app.py
@@ -2,50 +2,24 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import importlib
|
|
||||||
import importlib.util
|
|
||||||
import stat
|
import stat
|
||||||
import pwd
|
import pwd
|
||||||
import grp
|
import grp
|
||||||
|
# Import dependency check/install functions from dependency_utils
|
||||||
|
from dependency_utils import install_package_from_wheel, check_and_install_dependencies
|
||||||
|
|
||||||
|
|
||||||
# Global configuration mode flag
|
# Global configuration mode flag
|
||||||
CONFIGURATION_MODE = False
|
CONFIGURATION_MODE = False
|
||||||
|
|
||||||
def install_package_from_wheel(wheel_path, package_name):
|
# Run dependency check before importing anything else
|
||||||
"""
|
try:
|
||||||
Install a Python package from a wheel file
|
check_and_install_dependencies({
|
||||||
"""
|
|
||||||
try:
|
|
||||||
print(f"Installing {package_name} from {wheel_path}...")
|
|
||||||
result = subprocess.run([
|
|
||||||
sys.executable, "-m", "pip", "install", wheel_path,
|
|
||||||
"--no-index", "--no-deps", "--break-system-packages",
|
|
||||||
"--no-warn-script-location", "--force-reinstall"
|
|
||||||
], capture_output=True, text=True, timeout=60)
|
|
||||||
|
|
||||||
if result.returncode == 0:
|
|
||||||
print(f"✓ {package_name} installed successfully")
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
print(f"✗ Failed to install {package_name}: {result.stderr}")
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
|
||||||
print(f"✗ Error installing {package_name}: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def check_and_install_dependencies():
|
|
||||||
"""
|
|
||||||
Check if required packages are installed and install them from local repository if needed
|
|
||||||
"""
|
|
||||||
print("Checking and installing dependencies...")
|
|
||||||
|
|
||||||
# Define required packages and their corresponding wheel files
|
|
||||||
required_packages = {
|
|
||||||
'rdm6300': 'rdm6300-0.1.1-py3-none-any.whl',
|
'rdm6300': 'rdm6300-0.1.1-py3-none-any.whl',
|
||||||
'gpiozero': None, # System package, should be pre-installed
|
'gpiozero': None,
|
||||||
'requests': 'requests-2.32.3-py3-none-any.whl',
|
'requests': 'requests-2.32.3-py3-none-any.whl',
|
||||||
'aiohttp': 'aiohttp-3.11.18-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl',
|
'aiohttp': 'aiohttp-3.11.18-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl',
|
||||||
'flask': None, # Will try to install if needed
|
'flask': None,
|
||||||
'urllib3': 'urllib3-2.3.0-py3-none-any.whl',
|
'urllib3': 'urllib3-2.3.0-py3-none-any.whl',
|
||||||
'certifi': 'certifi-2025.1.31-py3-none-any.whl',
|
'certifi': 'certifi-2025.1.31-py3-none-any.whl',
|
||||||
'charset_normalizer': 'charset_normalizer-3.4.1-py3-none-any.whl',
|
'charset_normalizer': 'charset_normalizer-3.4.1-py3-none-any.whl',
|
||||||
@@ -57,78 +31,7 @@ def check_and_install_dependencies():
|
|||||||
'yarl': 'yarl-1.20.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl',
|
'yarl': 'yarl-1.20.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl',
|
||||||
'aiohappyeyeballs': 'aiohappyeyeballs-2.6.1-py3-none-any.whl',
|
'aiohappyeyeballs': 'aiohappyeyeballs-2.6.1-py3-none-any.whl',
|
||||||
'propcache': 'propcache-0.3.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl'
|
'propcache': 'propcache-0.3.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl'
|
||||||
}
|
}, "./Files/reposytory")
|
||||||
|
|
||||||
repository_path = "./Files/reposytory"
|
|
||||||
missing_packages = []
|
|
||||||
|
|
||||||
# Check each required package
|
|
||||||
for package_name, wheel_file in required_packages.items():
|
|
||||||
try:
|
|
||||||
# Use importlib to check if package exists
|
|
||||||
spec = importlib.util.find_spec(package_name)
|
|
||||||
if spec is not None:
|
|
||||||
print(f"✓ {package_name} is already installed")
|
|
||||||
else:
|
|
||||||
raise ImportError(f"Package {package_name} not found")
|
|
||||||
|
|
||||||
except ImportError:
|
|
||||||
print(f"✗ {package_name} is not installed")
|
|
||||||
missing_packages.append((package_name, wheel_file))
|
|
||||||
except Exception as e:
|
|
||||||
print(f"✗ Error checking {package_name}: {e}")
|
|
||||||
missing_packages.append((package_name, wheel_file))
|
|
||||||
|
|
||||||
# Install missing packages
|
|
||||||
if missing_packages:
|
|
||||||
print(f"\nInstalling {len(missing_packages)} missing packages...")
|
|
||||||
|
|
||||||
for package_name, wheel_file in missing_packages:
|
|
||||||
if wheel_file is None:
|
|
||||||
# Try to install via pip from internet or system packages
|
|
||||||
try:
|
|
||||||
print(f"Attempting to install {package_name} via pip...")
|
|
||||||
result = subprocess.run([
|
|
||||||
sys.executable, "-m", "pip", "install", package_name,
|
|
||||||
"--break-system-packages", "--no-warn-script-location"
|
|
||||||
], capture_output=True, text=True, timeout=120)
|
|
||||||
|
|
||||||
if result.returncode == 0:
|
|
||||||
print(f"✓ {package_name} installed via pip")
|
|
||||||
else:
|
|
||||||
print(f"✗ Could not install {package_name} via pip: {result.stderr}")
|
|
||||||
# Try system package manager for common packages
|
|
||||||
if package_name in ['flask', 'gpiozero']:
|
|
||||||
try:
|
|
||||||
print(f"Trying to install {package_name} via apt...")
|
|
||||||
apt_name = f"python3-{package_name.replace('_', '-')}"
|
|
||||||
apt_result = subprocess.run([
|
|
||||||
"sudo", "apt", "install", "-y", apt_name
|
|
||||||
], capture_output=True, text=True, timeout=300)
|
|
||||||
if apt_result.returncode == 0:
|
|
||||||
print(f"✓ {package_name} installed via apt")
|
|
||||||
else:
|
|
||||||
print(f"✗ Could not install {package_name} via apt")
|
|
||||||
except Exception as apt_e:
|
|
||||||
print(f"✗ Error installing {package_name} via apt: {apt_e}")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"✗ Error installing {package_name} via pip: {e}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
wheel_path = os.path.join(repository_path, wheel_file)
|
|
||||||
|
|
||||||
if not os.path.exists(wheel_path):
|
|
||||||
print(f"✗ Wheel file not found: {wheel_path}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Install the package
|
|
||||||
install_package_from_wheel(wheel_path, package_name)
|
|
||||||
|
|
||||||
print("Dependency check completed.\n")
|
|
||||||
|
|
||||||
# Run dependency check before importing anything else
|
|
||||||
try:
|
|
||||||
check_and_install_dependencies()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Warning: Dependency check failed: {e}")
|
print(f"Warning: Dependency check failed: {e}")
|
||||||
print("Continuing with existing packages...")
|
print("Continuing with existing packages...")
|
||||||
@@ -246,31 +149,29 @@ def early_launch_configuration_mode():
|
|||||||
|
|
||||||
print(f"📄 Loading Screen.html from: {screen_html_path}")
|
print(f"📄 Loading Screen.html from: {screen_html_path}")
|
||||||
|
|
||||||
# Launch chromium in kiosk mode with the local HTML file
|
|
||||||
chromium_command = [
|
# Terminate any existing Chromium processes
|
||||||
'chromium-browser',
|
chromium_process_name = "chromium"
|
||||||
'--kiosk',
|
log_info_with_server("Refreshing Chromium process.")
|
||||||
'--no-sandbox',
|
try:
|
||||||
'--disable-dev-shm-usage',
|
subprocess.run(["pkill", "-f", chromium_process_name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
'--disable-gpu',
|
time.sleep(5) # Wait for processes to terminate
|
||||||
'--disable-software-rasterizer',
|
# Launch Chromium with Screen.html
|
||||||
'--disable-background-timer-throttling',
|
url = f"file://{screen_html_path}"
|
||||||
'--disable-backgrounding-occluded-windows',
|
subprocess.Popen(
|
||||||
'--disable-renderer-backgrounding',
|
["chromium", "--test-type", "--noerrors", "--kiosk", "--start-fullscreen",
|
||||||
f'file://{screen_html_path}'
|
url],
|
||||||
]
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL, start_new_session=True
|
||||||
|
)
|
||||||
print("🚀 Starting Chromium in configuration mode...")
|
log_info_with_server("Chromium process restarted successfully.")
|
||||||
process = subprocess.Popen(chromium_command,
|
except Exception as e:
|
||||||
stdout=subprocess.DEVNULL,
|
log_info_with_server(f"Failed to refresh Chromium process: {e}")
|
||||||
stderr=subprocess.DEVNULL)
|
return False
|
||||||
|
|
||||||
print("✅ Configuration mode launched successfully")
|
print("✅ Configuration mode launched successfully")
|
||||||
print("ℹ️ Network connectivity checks disabled")
|
print("ℹ️ Network connectivity checks disabled")
|
||||||
print("ℹ️ Server status messages disabled")
|
print("ℹ️ Server status messages disabled")
|
||||||
print("🔧 Device running in configuration mode")
|
print("🔧 Device running in configuration mode")
|
||||||
print("🔧 To exit configuration mode, change idmasa.txt content to device name")
|
print("🔧 To exit configuration mode, change idmasa.txt content to device name")
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
|||||||
32
data/log.txt
32
data/log.txt
@@ -28,3 +28,35 @@
|
|||||||
2025-09-24 16:26:44,794 - INFO - LED controls initialized
|
2025-09-24 16:26:44,794 - INFO - LED controls initialized
|
||||||
2025-09-24 16:26:44,794 - INFO - Variabila Id Masa A fost initializata
|
2025-09-24 16:26:44,794 - INFO - Variabila Id Masa A fost initializata
|
||||||
2025-09-24 16:26:44,799 - INFO - idmasa
|
2025-09-24 16:26:44,799 - INFO - idmasa
|
||||||
|
2025-09-24 17:16:50,868 - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m
|
||||||
|
* Running on all addresses (0.0.0.0)
|
||||||
|
* Running on http://127.0.0.1:80
|
||||||
|
* Running on http://10.76.157.86:80
|
||||||
|
2025-09-24 17:16:50,869 - INFO - [33mPress CTRL+C to quit[0m
|
||||||
|
2025-09-24 17:16:52,857 - INFO - Log file is not older than 10 days: log.txt (n_masa: notconfig)
|
||||||
|
2025-09-24 17:16:52,857 - INFO - Configuration mode: Server logging disabled
|
||||||
|
2025-09-24 17:16:52,866 - INFO - LED controls initialized (n_masa: notconfig)
|
||||||
|
2025-09-24 17:16:52,867 - INFO - Configuration mode: Server logging disabled
|
||||||
|
2025-09-24 17:16:52,867 - INFO - LED controls initialized
|
||||||
|
2025-09-24 17:16:52,867 - INFO - Variabila Id Masa A fost initializata
|
||||||
|
2025-09-24 17:16:52,867 - INFO - idmasa
|
||||||
|
2025-09-24 17:33:06,772 - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m
|
||||||
|
* Running on all addresses (0.0.0.0)
|
||||||
|
* Running on http://127.0.0.1:80
|
||||||
|
* Running on http://10.89.219.105:80
|
||||||
|
2025-09-24 17:33:06,773 - INFO - [33mPress CTRL+C to quit[0m
|
||||||
|
2025-09-24 17:33:08,754 - INFO - Log file is not older than 10 days: log.txt (n_masa: notconfig)
|
||||||
|
2025-09-24 17:33:08,762 - INFO - 127.0.0.1 - - [24/Sep/2025 17:33:08] "[33mPOST /logs HTTP/1.1[0m" 404 -
|
||||||
|
2025-09-24 17:33:08,764 - ERROR - Failed to send log to server: 404 Client Error: NOT FOUND for url: http://rpi-ansible:80/logs
|
||||||
|
2025-09-24 17:33:08,767 - INFO - Internet connection check loaded (n_masa: notconfig)
|
||||||
|
2025-09-24 17:33:08,775 - INFO - 127.0.0.1 - - [24/Sep/2025 17:33:08] "[33mPOST /logs HTTP/1.1[0m" 404 -
|
||||||
|
2025-09-24 17:33:08,777 - ERROR - Failed to send log to server: 404 Client Error: NOT FOUND for url: http://rpi-ansible:80/logs
|
||||||
|
2025-09-24 17:33:08,777 - INFO - Log file is not older than 10 days: log.txt (n_masa: notconfig)
|
||||||
|
2025-09-24 17:33:08,782 - INFO - 127.0.0.1 - - [24/Sep/2025 17:33:08] "[33mPOST /logs HTTP/1.1[0m" 404 -
|
||||||
|
2025-09-24 17:33:08,784 - ERROR - Failed to send log to server: 404 Client Error: NOT FOUND for url: http://rpi-ansible:80/logs
|
||||||
|
2025-09-24 17:33:08,785 - INFO - LED controls initialized (n_masa: notconfig)
|
||||||
|
2025-09-24 17:33:08,799 - INFO - 127.0.0.1 - - [24/Sep/2025 17:33:08] "[33mPOST /logs HTTP/1.1[0m" 404 -
|
||||||
|
2025-09-24 17:33:08,802 - ERROR - Failed to send log to server: 404 Client Error: NOT FOUND for url: http://rpi-ansible:80/logs
|
||||||
|
2025-09-24 17:33:08,802 - INFO - LED controls initialized
|
||||||
|
2025-09-24 17:33:08,802 - INFO - Variabila Id Masa A fost initializata
|
||||||
|
2025-09-24 17:33:08,803 - INFO - idmasa
|
||||||
|
|||||||
58
dependency_utils.py
Normal file
58
dependency_utils.py
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import importlib.util
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
def install_package_from_wheel(wheel_path, package_name):
|
||||||
|
"""
|
||||||
|
Install a Python package from a wheel file
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
print(f"Installing {package_name} from {wheel_path}...")
|
||||||
|
result = subprocess.run([
|
||||||
|
sys.executable, "-m", "pip", "install", wheel_path,
|
||||||
|
"--no-index", "--no-deps", "--break-system-packages",
|
||||||
|
"--no-warn-script-location", "--force-reinstall"
|
||||||
|
], capture_output=True, text=True, timeout=60)
|
||||||
|
if result.returncode == 0:
|
||||||
|
print(f"✓ {package_name} installed successfully")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print(f"✗ Failed to install {package_name}: {result.stderr}")
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
print(f"✗ Error installing {package_name}: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def check_and_install_dependencies(required_packages, repository_path):
|
||||||
|
"""
|
||||||
|
Check if required packages are installed and install them from local repository if needed
|
||||||
|
"""
|
||||||
|
print("Checking and installing dependencies...")
|
||||||
|
missing_packages = []
|
||||||
|
for package_name, wheel_file in required_packages.items():
|
||||||
|
try:
|
||||||
|
spec = importlib.util.find_spec(package_name)
|
||||||
|
if spec is not None:
|
||||||
|
continue # Already installed
|
||||||
|
else:
|
||||||
|
print(f"✗ {package_name} is not installed")
|
||||||
|
missing_packages.append((package_name, wheel_file))
|
||||||
|
except ImportError:
|
||||||
|
print(f"✗ {package_name} is not installed")
|
||||||
|
missing_packages.append((package_name, wheel_file))
|
||||||
|
except Exception as e:
|
||||||
|
print(f"✗ Error checking {package_name}: {e}")
|
||||||
|
missing_packages.append((package_name, wheel_file))
|
||||||
|
if missing_packages:
|
||||||
|
print(f"\nInstalling {len(missing_packages)} missing packages...")
|
||||||
|
for package_name, wheel_file in missing_packages:
|
||||||
|
if wheel_file is None:
|
||||||
|
print(f"No wheel file for {package_name}, please install manually if needed.")
|
||||||
|
continue
|
||||||
|
wheel_path = os.path.join(repository_path, wheel_file)
|
||||||
|
if not os.path.exists(wheel_path):
|
||||||
|
print(f"✗ Wheel file not found: {wheel_path}")
|
||||||
|
continue
|
||||||
|
install_package_from_wheel(wheel_path, package_name)
|
||||||
|
print("Dependency check completed.\n")
|
||||||
Reference in New Issue
Block a user