-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_updates.py
More file actions
93 lines (78 loc) · 2.59 KB
/
check_updates.py
File metadata and controls
93 lines (78 loc) · 2.59 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
"""
Prüft ob Updates verfügbar sind (optional beim Start)
"""
import subprocess
import sys
import os
from pathlib import Path
def check_for_updates(silent=False):
"""
Prüft ob Updates von GitHub verfügbar sind
Args:
silent: Wenn True, keine Ausgabe
Returns:
tuple: (updates_available: bool, count: int, error: str or None)
"""
try:
# Prüfe ob Git verfügbar ist
result = subprocess.run(
["git", "--version"],
capture_output=True,
text=True,
timeout=5
)
if result.returncode != 0:
return (False, 0, "Git nicht installiert")
# Aktuellen Branch ermitteln
result = subprocess.run(
["git", "branch", "--show-current"],
capture_output=True,
text=True,
timeout=5,
cwd=Path(__file__).parent
)
if result.returncode != 0:
return (False, 0, "Kein Git Repository")
current_branch = result.stdout.strip()
# Fetch updates (leise)
result = subprocess.run(
["git", "fetch", "origin", current_branch],
capture_output=True,
text=True,
timeout=30,
cwd=Path(__file__).parent
)
if result.returncode != 0:
return (False, 0, "Keine Verbindung zu GitHub")
# Zähle verfügbare Updates
result = subprocess.run(
["git", "rev-list", "HEAD...origin/" + current_branch, "--count"],
capture_output=True,
text=True,
timeout=5,
cwd=Path(__file__).parent
)
if result.returncode != 0:
return (False, 0, "Fehler beim Zählen der Updates")
count = int(result.stdout.strip())
if not silent and count > 0:
print(f"\n✨ {count} Update(s) verfügbar!")
print(" Führe 'update.bat' aus um zu aktualisieren.\n")
return (count > 0, count, None)
except subprocess.TimeoutExpired:
return (False, 0, "Timeout bei Git-Abfrage")
except Exception as e:
return (False, 0, f"Fehler: {str(e)}")
if __name__ == "__main__":
# Standalone-Aufruf
updates_available, count, error = check_for_updates(silent=False)
if error:
print(f"⚠️ Konnte nicht auf Updates prüfen: {error}")
sys.exit(1)
if updates_available:
print(f"✅ {count} Update(s) verfügbar!")
print("\nFühre 'update.bat' aus um zu aktualisieren.")
sys.exit(0)
else:
print("✅ Du hast die neueste Version!")
sys.exit(0)