From b458b9bbef996564d03119742785cf9b2edaa402 Mon Sep 17 00:00:00 2001 From: ske087 Date: Wed, 24 Sep 2025 17:33:34 +0300 Subject: [PATCH] updated to browser view --- __pycache__/dependency_utils.cpython-311.pyc | Bin 0 -> 3552 bytes app.py | 153 ++++--------------- data/log.txt | 32 ++++ dependency_utils.py | 58 +++++++ 4 files changed, 117 insertions(+), 126 deletions(-) create mode 100644 __pycache__/dependency_utils.cpython-311.pyc create mode 100644 dependency_utils.py diff --git a/__pycache__/dependency_utils.cpython-311.pyc b/__pycache__/dependency_utils.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..313fe9746e825fab8e0a110a46fb0f0edd1a004d GIT binary patch literal 3552 zcmb_eO>Eo96&{L|OwqI@TmDUqgl?QVa#l8wcz0vRKZ@;L)J|X&$O4NPNeo3C$FwC; z9a6AO$U$1{!3BH>+5k4X309}nMfTw19(vjAttZkT5P^U$TkK(PD$)W$PJKg)vgM>G z3Uv7RW;lHF&Ad0m_wmmyEdqiPVC>be!U+AHKKLb2YrMGvjXfkInaQ9f#;pTO0k>wC zShwbuI63eYS_;Z6=#b3ZMseHw*WhC5B>#kq)(AWTwb`jpRTPfo7iv zU%Bw4HtE1{6zYn1`&Tq?{9F#*vBsa;t9F_&S`Jo_-aJ78f`U0$8)-AUK z#lTvyJ}$EEB9qRBl||i^wLND~uSphfH~P@-TE+mgzOJv)bMC!y9kA~b-A zw9Pim+F8S5KZI}x$z9v*BUT0^ueHH!piTA;+F;_{#;71cna^o@DwB~?(yzDlRW&E& zQ|a~8LoBTjH4D8Ps~Bgb6(xgRbECO7K*>FnjF4w#u*1W{Mj(-O*u0W=niLPy5E6-; znox2w-Za8)TgG|K=uRXa5S&_1Xj__&vx(Y_n$hdpY@|pop{0qE*Ap2vozfLGXS5{} zD=JCj1i>}*FMghY(8O7%HJ!@q1%j8=f}Stv4yWTy-D%R5EQTIJH>*JR^2cX?l#Fhv zHXO^6R!FC@rmYk*nXN*XYq2MNo&r~8Nmq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66<{W>E6^Irb6!+yqDecNG^0rhBL1>u98Oqb(iW4Z zD-|wm3UP}YvbiDC7wrNZm2dlRj0L`L9in<{bapuSY9vhcwU1`w!5`v5XvdqJ*7~|SLQe(YXVF2=yWPhAb2XD(OK`-&t0```TVhdTfO literal 0 HcmV?d00001 diff --git a/app.py b/app.py index 03d51f1..f4e2092 100644 --- a/app.py +++ b/app.py @@ -2,50 +2,24 @@ import os import sys import subprocess -import importlib -import importlib.util import stat import pwd 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 CONFIGURATION_MODE = False -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(): - """ - 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 = { +# Run dependency check before importing anything else +try: + check_and_install_dependencies({ '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', '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', 'certifi': 'certifi-2025.1.31-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', 'aiohappyeyeballs': 'aiohappyeyeballs-2.6.1-py3-none-any.whl', 'propcache': 'propcache-0.3.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl' - } - - 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() + }, "./Files/reposytory") except Exception as e: print(f"Warning: Dependency check failed: {e}") print("Continuing with existing packages...") @@ -246,31 +149,29 @@ def early_launch_configuration_mode(): print(f"📄 Loading Screen.html from: {screen_html_path}") - # Launch chromium in kiosk mode with the local HTML file - chromium_command = [ - 'chromium-browser', - '--kiosk', - '--no-sandbox', - '--disable-dev-shm-usage', - '--disable-gpu', - '--disable-software-rasterizer', - '--disable-background-timer-throttling', - '--disable-backgrounding-occluded-windows', - '--disable-renderer-backgrounding', - f'file://{screen_html_path}' - ] - - print("🚀 Starting Chromium in configuration mode...") - process = subprocess.Popen(chromium_command, - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL) - + + # Terminate any existing Chromium processes + chromium_process_name = "chromium" + log_info_with_server("Refreshing Chromium process.") + try: + subprocess.run(["pkill", "-f", chromium_process_name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + time.sleep(5) # Wait for processes to terminate + # Launch Chromium with Screen.html + url = f"file://{screen_html_path}" + subprocess.Popen( + ["chromium", "--test-type", "--noerrors", "--kiosk", "--start-fullscreen", + url], + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL, start_new_session=True + ) + log_info_with_server("Chromium process restarted successfully.") + except Exception as e: + log_info_with_server(f"Failed to refresh Chromium process: {e}") + return False print("✅ Configuration mode launched successfully") print("ℹ️ Network connectivity checks disabled") print("ℹ️ Server status messages disabled") print("🔧 Device running in configuration mode") print("🔧 To exit configuration mode, change idmasa.txt content to device name") - return True except FileNotFoundError: diff --git a/data/log.txt b/data/log.txt index 743e7d9..f566186 100644 --- a/data/log.txt +++ b/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 - Variabila Id Masa A fost initializata 2025-09-24 16:26:44,799 - INFO - idmasa +2025-09-24 17:16:50,868 - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * 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 - Press CTRL+C to quit +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 - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * 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 - Press CTRL+C to quit +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] "POST /logs HTTP/1.1" 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] "POST /logs HTTP/1.1" 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] "POST /logs HTTP/1.1" 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] "POST /logs HTTP/1.1" 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 diff --git a/dependency_utils.py b/dependency_utils.py new file mode 100644 index 0000000..d9acad6 --- /dev/null +++ b/dependency_utils.py @@ -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")