chore(dev): lint monitor.py and update flake dependencies

- Refactor `hosts/desktop/monitor.py` to resolve PEP8 violations (line lengths, trailing whitespace, blank line structure).
- Update `flake.lock` to incorporate the latest upstream changes for `antigravity`, `DankMaterialShell`, and `home-manager`.
This commit is contained in:
kiskaadee committed 2026-06-25 17:09:18 -05:00
1 parent 81c05c8122
commit ea9dfffcec
2 files changed
+33 -34

No files matched your search

Generated
+9 -9
View File
@@ -8,11 +8,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1782288772, "lastModified": 1782375110,
"narHash": "sha256-cLZ/6ZCuX5kyU/g/ppmGYGC5SYDQnwEcBCg934bU0Mo=", "narHash": "sha256-VgQr+Y1b3C9bCn68DVyrzJiLvF14Cxpcf66HV6MNkVM=",
"owner": "jacopone", "owner": "jacopone",
"repo": "antigravity-nix", "repo": "antigravity-nix",
"rev": "9339da3b94d8691a92e101e7be45f83ea5012f69", "rev": "738d61a4b7d88473adedda7b5dbc7b6bc5704020",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -49,11 +49,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1782274482, "lastModified": 1782412048,
"narHash": "sha256-QzEtKa5ROX8cNYDymcjB6oTfRBpEApGQ7PFsF85Gl5s=", "narHash": "sha256-iLCNbmbH1ltOrqBUf8ccN0DaPkFr8JrnwnEtoy1grog=",
"owner": "AvengeMedia", "owner": "AvengeMedia",
"repo": "DankMaterialShell", "repo": "DankMaterialShell",
"rev": "1a39b7f66ca2b8df23a546fe312619e05c61a13c", "rev": "016527fda910f21b36c079051def38b12c6d0aab",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -103,11 +103,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1782233665, "lastModified": 1782423922,
"narHash": "sha256-h/xOtrByoA/Ak1lWHn0O1lVZz4qWYbwOSLQ8YSwQO0I=", "narHash": "sha256-qPNd6lUohHP5gcJhqQ7rLV87RwIx0xYR2A4Frb9Zjc4=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "062581938b4a378a82dfbb294b494808157153a1", "rev": "5d320ab301cfaaca7d32514f13815d19d109f5f4",
"type": "github" "type": "github"
}, },
"original": { "original": {
+24 -25
View File
@@ -1,13 +1,13 @@
""" """
Dynu DDNS Smart IP Change Monitor and Updater. Dynu DDNS Smart IP Change Monitor and Updater.
This script determines the current public IPv4 address by querying multiple external This script determines the current public IPv4 address by querying multiple
resolvers sequentially. It compares the discovered IP against the last recorded external resolvers sequentially. It compares the discovered IP against the last
successful IP in a local history log. If a change is detected, it triggers the recorded successful IP in a local history log. If a change is detected, it
`ddclient.service` on-demand to perform the DNS record update. triggers the `ddclient.service` on-demand to perform the DNS record update.
This local-first state verification prevents making redundant API requests to the This local-first state verification prevents making redundant API requests to
DNS provider, avoiding potential rate-limiting, IP bans, or API abuse flags. the DNS provider, avoiding rate-limiting, IP bans, or API abuse flags.
""" """
import urllib.request import urllib.request
@@ -22,7 +22,7 @@ from datetime import datetime
# Defaults to a state directory managed securely by the systemd service unit. # Defaults to a state directory managed securely by the systemd service unit.
HISTORY_FILE = os.environ.get("HISTORY_FILE", "/var/lib/dynu/ip_history.jsonl") HISTORY_FILE = os.environ.get("HISTORY_FILE", "/var/lib/dynu/ip_history.jsonl")
# Fallback sequence of external reflection services to discover the public WAN IP. # Fallback sequence of external services to discover the public WAN IP.
PROVIDERS = [ PROVIDERS = [
"https://api.ipify.org", "https://api.ipify.org",
"https://ifconfig.me/ip", "https://ifconfig.me/ip",
@@ -34,9 +34,9 @@ PROVIDERS = [
def is_valid_public_ipv4(ip): def is_valid_public_ipv4(ip):
""" """
Validates that a string is a properly formatted public IPv4 address. Validates that a string is a properly formatted public IPv4 address.
This function excludes standard private, loopback, link-local, and CGNAT blocks This function excludes standard private, loopback, link-local, and CGNAT
to avoid recording temporary, local, or invalid network states. blocks to avoid recording temporary, local, or invalid network states.
""" """
match = re.match(r"^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$", ip) match = re.match(r"^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$", ip)
if not match: if not match:
@@ -45,7 +45,7 @@ def is_valid_public_ipv4(ip):
if any(x > 255 for x in octets): if any(x > 255 for x in octets):
return False return False
a, b, c, d = octets a, b, c, d = octets
# RFC 1918 Private ranges: 10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12 # RFC 1918 Private ranges: 10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12
if a == 10: if a == 10:
return False return False
@@ -53,26 +53,26 @@ def is_valid_public_ipv4(ip):
return False return False
if a == 172 and 16 <= b <= 31: if a == 172 and 16 <= b <= 31:
return False return False
# Carrier-Grade NAT (CGNAT) RFC 6598: 100.64.0.0/10 # Carrier-Grade NAT (CGNAT) RFC 6598: 100.64.0.0/10
if a == 100 and 64 <= b <= 127: if a == 100 and 64 <= b <= 127:
return False return False
# Loopback address range: 127.0.0.0/8 # Loopback address range: 127.0.0.0/8
if a == 127: if a == 127:
return False return False
# Link-local addresses: 169.254.0.0/16 # Link-local addresses: 169.254.0.0/16
if a == 169 and b == 254: if a == 169 and b == 254:
return False return False
return True return True
def get_public_ip(): def get_public_ip():
""" """
Queries public IP providers sequentially until a valid public IPv4 is returned. Queries public IP providers until a valid public IPv4 is returned.
Returns: Returns:
str: The validated public IP string, or None if all providers fail. str: The validated public IP string, or None if all providers fail.
""" """
@@ -85,7 +85,7 @@ def get_public_ip():
'User-Agent': 'Mozilla/5.0 (NixOS WAN Monitor)' 'User-Agent': 'Mozilla/5.0 (NixOS WAN Monitor)'
} }
) )
# Fetch content with a strict 5 second timeout to prevent hanging the systemd task # Fetch with 5s timeout to avoid hanging the systemd service
with urllib.request.urlopen(req, timeout=5) as response: with urllib.request.urlopen(req, timeout=5) as response:
ip = response.read().decode('utf-8').strip() ip = response.read().decode('utf-8').strip()
if is_valid_public_ipv4(ip): if is_valid_public_ipv4(ip):
@@ -94,7 +94,7 @@ def get_public_ip():
errors.append(f"{provider}: invalid public IPv4 '{ip}'") errors.append(f"{provider}: invalid public IPv4 '{ip}'")
except Exception as e: except Exception as e:
errors.append(f"{provider}: {str(e)}") errors.append(f"{provider}: {str(e)}")
print( print(
f"Error: All IP discovery providers failed. Details: {errors}", f"Error: All IP discovery providers failed. Details: {errors}",
file=sys.stderr file=sys.stderr
@@ -104,8 +104,8 @@ def get_public_ip():
def get_last_recorded_ip(): def get_last_recorded_ip():
""" """
Reads the history log from the bottom up to locate the last successful IP address. Reads the history log to locate the last successful IP address.
Returns: Returns:
str: The last successfully updated IP, or None if no log exists yet. str: The last successfully updated IP, or None if no log exists yet.
""" """
@@ -151,12 +151,12 @@ def record_ip(ip, status, details=None):
def trigger_ddclient(): def trigger_ddclient():
""" """
Invokes the systemd service unit for `ddclient` on-demand. Invokes the systemd service unit for `ddclient` on-demand.
Returns: Returns:
tuple: (bool, str) representing (success_boolean, error_details_string) tuple: (bool, str) representing (success_boolean, error_details_string)
""" """
try: try:
# Run ddclient as a one-shot activation via systemd to perform the API call # Run ddclient as a one-shot activation via systemd to perform API call
res = subprocess.run( res = subprocess.run(
["systemctl", "start", "ddclient.service"], ["systemctl", "start", "ddclient.service"],
capture_output=True, capture_output=True,
@@ -184,7 +184,7 @@ def main():
last_ip = get_last_recorded_ip() last_ip = get_last_recorded_ip()
if current_ip == last_ip: if current_ip == last_ip:
# IP matches the last recorded working IP; do nothing to conserve API quota # IP matches last recorded working IP; do nothing to conserve quota
sys.exit(0) sys.exit(0)
print(f"IP rotation detected! Old: {last_ip}, New: {current_ip}") print(f"IP rotation detected! Old: {last_ip}, New: {current_ip}")
@@ -203,4 +203,3 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() main()