-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstatus.py
More file actions
39 lines (34 loc) · 1.32 KB
/
status.py
File metadata and controls
39 lines (34 loc) · 1.32 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
import os
import logging
STATUS_FILE = "/tmp/update_flag.txt"
# Logger konfigurieren (ggf. an dein Logging-Setup anpassen)
logger = logging.getLogger(__name__)
if not logger.hasHandlers():
logging.basicConfig(level=logging.INFO)
def _ensure_file_exists():
if not os.path.isfile(STATUS_FILE):
try:
with open(STATUS_FILE, "w") as f:
f.write("0") # Default: kein Update nötig
logger.info(f"Status-Datei angelegt: {STATUS_FILE}")
except Exception as e:
logger.error(f"Fehler beim Anlegen der Status-Datei {STATUS_FILE}: {e}")
def set_update_needed(value: bool):
_ensure_file_exists()
try:
with open(STATUS_FILE, "w") as f:
f.write("1" if value else "0")
logger.info(f"Update-Flag gesetzt auf {'1' if value else '0'} in {STATUS_FILE}")
except Exception as e:
logger.error(f"Fehler beim Schreiben in die Status-Datei {STATUS_FILE}: {e}")
def get_update_needed() -> bool:
_ensure_file_exists()
try:
with open(STATUS_FILE, "r") as f:
val = f.read(1)
result = val == "1"
logger.debug(f"Update-Flag aus {STATUS_FILE} gelesen: {val}")
return result
except Exception as e:
logger.error(f"Fehler beim Lesen der Status-Datei {STATUS_FILE}: {e}")
return False