diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ef4d66..6577cd7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: - name: Install ZanzoCam run: | sudo apt-get install language-pack-it wireless-tools - pip install Pillow requests piexif pytest pytest-coverage pytest-subprocess freezegun coveralls + pip install Pillow requests piexif pytest pytest-coverage pytest-subprocess freezegun coveralls flask pip install --no-deps -e . - name: Unit tests diff --git a/.gitignore b/.gitignore index 430367c..79a7754 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ zanzocam/web_ui/static/previews/* zanzocam/data/* !zanzocam/data/send-logs.flag -!zanzocam/data/upload_interval.txt +!zanzocam/data/upload-interval.txt **/build/*.* diff --git a/tests/unit_tests/test_webcam_system.py b/tests/unit_tests/test_webcam_system.py index 331c68c..2da82ed 100644 --- a/tests/unit_tests/test_webcam_system.py +++ b/tests/unit_tests/test_webcam_system.py @@ -72,7 +72,6 @@ def test_get_uptime_exception(fake_process, logs): assert in_logs(logs, "Could not get uptime information") assert in_logs(logs, "Could not get last reboot time information") - def test_run_hotspot_on_wifi_1(fake_process, logs): """ Check if the hotspot runs, normal behavior on wifi. @@ -348,7 +347,7 @@ def test_report_general_status(monkeypatch): class Empty(): def __getattr__(self, attr): - return lambda *a, **k: None + return lambda *a, **k: None monkeypatch.setattr(webcam, "system", Empty()) status = original_system.report_general_status() diff --git a/zanzocam/constants.py b/zanzocam/constants.py index be02f78..e893fc5 100644 --- a/zanzocam/constants.py +++ b/zanzocam/constants.py @@ -1,12 +1,7 @@ -import logging from pathlib import Path -#from zanzocam.web_ui.utils import read_flag_file, write_text_file - - #: ZanzoCam version -VERSION = "1.3.4" - +VERSION = "1.3.5" # Executables constants # ##################### @@ -97,9 +92,6 @@ #: Path to the autohotspot script AUTOHOTSPOT_BINARY_PATH = "/usr/bin/autohotspot" -#: Interval to wait before retrying the autohotspot script -AUTOHOTSPOT_RETRY_TIME = 5 * 60 # 5 minutes - #: Ecoding of the FTP server files FTP_CONFIG_FILE_ENCODING = 'utf-8' diff --git a/zanzocam/data/upload_interval.txt b/zanzocam/data/upload-interval.txt similarity index 100% rename from zanzocam/data/upload_interval.txt rename to zanzocam/data/upload-interval.txt diff --git a/zanzocam/web_ui/api.py b/zanzocam/web_ui/api.py index 9120ba4..23656e0 100644 --- a/zanzocam/web_ui/api.py +++ b/zanzocam/web_ui/api.py @@ -106,7 +106,7 @@ def set_upload_interval(value: int) -> str: """ try: int(value) - return "", write_text_file(Path(__file__).parent.parent / "data" / "upload_interval.txt", value) + return "", write_text_file(Path(__file__).parent.parent / "data" / "upload-interval.txt", value) except ValueError as e: abort(500, f"invalid value for the random interval field: {value}") diff --git a/zanzocam/web_ui/pages.py b/zanzocam/web_ui/pages.py index 3b06ea7..2bd69b0 100644 --- a/zanzocam/web_ui/pages.py +++ b/zanzocam/web_ui/pages.py @@ -1,5 +1,6 @@ import os import shutil +import logging from datetime import datetime from typing import OrderedDict @@ -18,7 +19,7 @@ def home_page(): server_data = read_setup_data_file(CONFIGURATION_FILE).get('server', {}) return render_template("home.html", title="Setup", - version=VERSION, + version=VERSION, network_data=network_data, server_data=server_data) @@ -34,9 +35,9 @@ def server_page(): """ The page with the server data forms """ server_data = read_setup_data_file(CONFIGURATION_FILE).get('server', {}) try: - server_data["random_upload_interval"] = int(read_flag_file(DATA_PATH / "upload_interval.txt", default="5")) + server_data["random_upload_interval"] = int(read_flag_file(DATA_PATH / "upload-interval.txt", default="5")) except Exception as e: - logging.exception("data/upload_interval.txt does not contain an integer value. Overwriting its value with 5 seconds.") + logging.exception("data/upload-interval.txt does not contain an integer value. Overwriting its value with 5 seconds.") server_data["random_upload_interval"] = 5 return render_template("server.html", title="Setup Server", diff --git a/zanzocam/web_ui/templates/network.html b/zanzocam/web_ui/templates/network.html index 514fbec..1eda05b 100644 --- a/zanzocam/web_ui/templates/network.html +++ b/zanzocam/web_ui/templates/network.html @@ -2,22 +2,53 @@ {% block content %}
+
- - + + + + + +
+ + +
+ +
Indietro
+
+
+ {% endblock %} diff --git a/zanzocam/webcam/server/server.py b/zanzocam/webcam/server/server.py index 0fcda43..1447305 100644 --- a/zanzocam/webcam/server/server.py +++ b/zanzocam/webcam/server/server.py @@ -155,7 +155,7 @@ def upload_picture(self, image_path: Path, image_name: str, """ # Wait a random time, if enabled try: - random_upload_interval = int(read_flag_file(DATA_PATH / "upload_interval.txt", default="5")) + random_upload_interval = int(read_flag_file(DATA_PATH / "upload-interval.txt", default="5")) except Exception as e: log_error("Can't read the upload interval value. Defaulting to 5 seconds.", e) random_upload_interval = 5 diff --git a/zanzocam/webcam/system.py b/zanzocam/webcam/system.py index b96f904..9625bea 100644 --- a/zanzocam/webcam/system.py +++ b/zanzocam/webcam/system.py @@ -9,7 +9,6 @@ import requests import datetime import subprocess -from time import sleep from pathlib import Path from textwrap import dedent @@ -18,18 +17,13 @@ from zanzocam.web_ui.utils import read_flag_file -class RaceConditionError(Exception): - pass - - def log_general_status() -> bool: """ Returns True if the execution was successful, False in case of errors """ - status = None return_value = True - report = "Status report:\n" try: + report = "Status report:\n" status = report_general_status() col_width = 16 @@ -41,26 +35,19 @@ def log_general_status() -> bool: continue report += f"- {key}: {' ' * (col_width - len(key))}{value}\n" - except RaceConditionError as e: - log_error("Another Zanzocam is running.", e) - raise e - except Exception as e: - log_error( - "Something unexpected happened during the system status check. " - "This might be a symptom of deeper issues, don't ignore this!", e - ) + log_error("Something unexpected happened during the system " + "status check. This might be " + "a symptom of deeper issues, don't ignore this!", e) return_value = False finally: log(report) - if status and not status.get('internet access', False): - log_error("No Internet access detected on this WiFi network. Skipping this photo.") - raise RuntimeError("No Internet access detected on this WiFi network.") return return_value + def report_general_status() -> Dict: """ Collect general system data like version, uptime, internet connectivity. @@ -74,27 +61,16 @@ def report_general_status() -> Dict: status["last reboot"] = get_last_reboot_time() status["uptime"] = get_uptime() - race_condition = check_race_condition() - if race_condition: - log_error("Another Zanzocam process is running (probably waiting for WiFi). Skipping this photo.") - raise RaceConditionError() - - status['wifi data'] = get_wifi_data() - if status['wifi data'] and "ssid" in status['wifi data'] and status['wifi data']["ssid"] == "n/a": - - autohotspot_status = run_autohotspot() - if autohotspot_status is None: - status["hotspot status"] = "FAILED (see stacktrace)" - else: - while not autohotspot_status: - log(f"Hotspot is active. Waiting for {AUTOHOTSPOT_RETRY_TIME} minutes and retrying to connect to WiFi.") - sleep(AUTOHOTSPOT_RETRY_TIME) - autohotspot_status = run_autohotspot() - - # Once we connect, let's collect the WiFi data again. + autohotspot_status = run_autohotspot() + if autohotspot_status is None: + status["hotspot status"] = "FAILED (see stacktrace)" + else: + if autohotspot_status: status["hotspot status"] = "OFF (connected to WiFi)" - status['wifi data'] = get_wifi_data() + else: + status["hotspot status"] = "ON (no known WiFi in range)" + status['wifi data'] = get_wifi_data() status['internet access'] = check_internet_connectivity() status['max upload wait'] = get_max_random_upload_interval() @@ -105,21 +81,9 @@ def report_general_status() -> Dict: return status -def check_race_condition(): - """ - Check whether there's any other Zanzocam process already running. - """ - try: - ps_proc = subprocess.Popen(['/bin/ps', 'aux'], stdout=subprocess.PIPE) - ps_output, _ = ps_proc.communicate() - return ps_output.decode('utf-8').count("z-webcam") > 2 - except Exception as e: - log_error("Could not check for other processes. Something is wrong, aborting the script.", e) - - def get_max_random_upload_interval(): try: - random_upload_interval = int(read_flag_file(DATA_PATH / "upload_interval.txt", default="5")) + random_upload_interval = int(read_flag_file(DATA_PATH / "upload-interval.txt", default="5")) except Exception as e: log_error("Can't read the upload interval value. Defaulting to 5 seconds.", e) random_upload_interval = 5 @@ -559,3 +523,5 @@ def prepare_crontab_string(time: Dict, length: Optional[int] = None) -> List[str start_total_minutes += frequency return cron_strings + +