Skip to content

Commit 56590cd

Browse files
authored
chore(network): drop per-poll debug logs and add missing docstrings (#308)
# Description - [x] Documentation Stacked on #1, review after it merges. Removes per-poll debug logging that was spamming the log directory, compresses comments to one-liners, adds missing docstrings across the network layer (buys docstr-coverage margin for the rest of the stack, baseline 80.1% against an 80% gate). - Drop noisy per-poll debug logs - Compress multi-line comments to one-liners - Add docstrings for pre-existing gaps # Tests All 5 gates pass standing alone. No behaviour change (docs/logging only).
1 parent a634e14 commit 56590cd

4 files changed

Lines changed: 23 additions & 24 deletions

File tree

‎BlocksScreen/lib/network/manager.py‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Qt-facing NetworkManager facade: owns the worker thread and its signals."""
2+
13
# pylint: disable=protected-access
24

35
import asyncio
@@ -17,7 +19,7 @@
1719

1820
logger = logging.getLogger(__name__)
1921

20-
_KEEPALIVE_POLL_MS: int = 300_000 # 5 minutes — safety net for missed signals
22+
_KEEPALIVE_POLL_MS: int = 300_000 # 5 minutes: safety net for missed signals
2123

2224

2325
class NetworkManager(QObject):
@@ -27,9 +29,9 @@ class NetworkManager(QObject):
2729
a ``NetworkManagerWorker`` that runs all D-Bus coroutines on its
2830
dedicated asyncio thread.
2931
30-
Coroutines are submitted to ``worker._asyncio_loop`` — the same loop
31-
on which the D-Bus file-descriptor was registered — so signal delivery
32-
and async I/O always occur on the correct selector.
32+
Coroutines are submitted to ``worker._asyncio_loop`` (the same loop the
33+
D-Bus file-descriptor was registered on), so signal delivery and async
34+
I/O always occur on the correct selector.
3335
3436
"""
3537

@@ -72,7 +74,7 @@ def __init__(self, parent: QObject | None = None) -> None:
7274
self._worker.reconnect_complete.connect(self.reconnect_complete)
7375
self._worker.initialized.connect(self._on_worker_initialized)
7476

75-
# Keepalive timer — safety net for any missed D-Bus signals.
77+
# Keepalive timer: safety net for any missed D-Bus signals.
7678
self._keepalive_timer = QTimer(self)
7779
self._keepalive_timer.setInterval(_KEEPALIVE_POLL_MS)
7880
self._keepalive_timer.timeout.connect(self._on_keepalive_tick)
@@ -96,7 +98,7 @@ def _schedule(self, coro: "asyncio.Coroutine") -> None:
9698
future.add_done_callback(self._pending_futures.discard)
9799
else:
98100
logger.debug(
99-
"Dropping early coroutine — loop not yet running: %s",
101+
"Dropping early coroutine, loop not yet running: %s",
100102
coro.__qualname__,
101103
)
102104
coro.close()
@@ -114,7 +116,7 @@ def _on_worker_initialized(self) -> None:
114116
return
115117
self._worker_ready = True
116118
logger.info(
117-
"Worker initialised — starting keepalive (every %d ms)",
119+
"Worker initialised: starting keepalive (every %d ms)",
118120
_KEEPALIVE_POLL_MS,
119121
)
120122
self._keepalive_timer.start()
@@ -185,7 +187,7 @@ def _on_hotspot_info_ready(self, ssid: str, password: str, security: str) -> Non
185187

186188
@pyqtSlot()
187189
def _on_keepalive_tick(self) -> None:
188-
"""Safety-net refresh — runs every 5 min to catch any missed signals."""
190+
"""Safety-net refresh: runs every 5 min to catch any missed signals."""
189191
if self._shutting_down:
190192
return
191193
self._schedule(self._worker._async_get_current_state())
@@ -273,7 +275,7 @@ def update_hotspot_config(
273275
new_password: str,
274276
security: str = "wpa-psk",
275277
) -> None:
276-
"""Change hotspot name/password/security — cleans up old profiles."""
278+
"""Change hotspot name/password/security: cleans up old profiles."""
277279
self._schedule(
278280
self._worker._async_update_hotspot_config(
279281
old_ssid, new_ssid, new_password, security
@@ -346,17 +348,17 @@ def saved_networks(self) -> list[SavedNetwork]:
346348

347349
@property
348350
def hotspot_ssid(self) -> str:
349-
"""Hotspot SSID — read from main-thread cache (thread-safe)."""
351+
"""Hotspot SSID: read from main-thread cache (thread-safe)."""
350352
return self._cached_hotspot_ssid
351353

352354
@property
353355
def hotspot_password(self) -> str:
354-
"""Hotspot password — read from main-thread cache (thread-safe)."""
356+
"""Hotspot password: read from main-thread cache (thread-safe)."""
355357
return self._cached_hotspot_password
356358

357359
@property
358360
def hotspot_security(self) -> str:
359-
"""Hotspot security type — always 'wpa-psk' (WPA2-PSK, thread-safe)."""
361+
"""Hotspot security type: always 'wpa-psk' (WPA2-PSK, thread-safe)."""
360362
return self._cached_hotspot_security
361363

362364
def get_network_info(self, ssid: str) -> NetworkInfo | None:

‎BlocksScreen/lib/network/models.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ class NetworkStatus(IntEnum):
8282
``NetworkInfo.is_open`` (derived from ``security_type``) instead.
8383
"""
8484

85-
DISCOVERED = 0 # Seen in scan, not saved — protected security
86-
OPEN = 1 # Seen in scan, not saved — open (no passphrase)
85+
DISCOVERED = 0 # Seen in scan, not saved: protected security
86+
OPEN = 1 # Seen in scan, not saved: open (no passphrase)
8787
SAVED = 2 # Profile saved on this device
8888
ACTIVE = 3 # Currently connected
8989
HIDDEN = 4 # Hidden-network placeholder
@@ -287,7 +287,7 @@ class HotspotSecurity(str, Enum):
287287
"""
288288

289289
WPA1 = "wpa1"
290-
WPA2_PSK = "wpa-psk" # WPA2-PSK (CCMP) — default
290+
WPA2_PSK = "wpa-psk" # WPA2-PSK (CCMP): default
291291

292292
@classmethod
293293
def is_valid(cls, value: str) -> bool:

‎BlocksScreen/lib/network/worker.py‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Async D-Bus NetworkManager worker: signal watching, link control, state snapshots."""
2+
13
import asyncio
24
import fcntl
35
import ipaddress
@@ -476,21 +478,19 @@ async def _listen_ap_added(self) -> None:
476478
if not self._signal_wifi:
477479
return
478480
logger.debug("AP Added listener started on %s", self._primary_wifi_path)
479-
async for ap_path in self._signal_wifi.access_point_added:
481+
async for _ in self._signal_wifi.access_point_added:
480482
if not self._running:
481483
return
482-
logger.debug("AP added: %s", ap_path)
483484
self._schedule_debounced_scan()
484485

485486
async def _listen_ap_removed(self) -> None:
486487
"""React to access points disappearing from scan results."""
487488
if not self._signal_wifi:
488489
return
489490
logger.debug("AP Removed listener started on %s", self._primary_wifi_path)
490-
async for ap_path in self._signal_wifi.access_point_removed:
491+
async for _ in self._signal_wifi.access_point_removed:
491492
if not self._running:
492493
return
493-
logger.debug("AP removed: %s", ap_path)
494494
self._schedule_debounced_scan()
495495

496496
async def _listen_wired_state_changed(self) -> None:
@@ -836,7 +836,6 @@ async def _build_current_state(self) -> NetworkState:
836836
current_ip = _fallback
837837
if _iface != "wlan0":
838838
eth_connected = True
839-
logger.debug("OS fallback IP for '%s': %s", _iface, _fallback)
840839
break
841840

842841
signal = 0
@@ -852,10 +851,6 @@ async def _build_current_state(self) -> NetworkState:
852851
if not hotspot_enabled and self._is_hotspot_active and not current_ssid:
853852
hotspot_enabled = True
854853
current_ssid = self._hotspot_config.ssid
855-
logger.debug(
856-
"Hotspot SSID not found via D-Bus, using config: '%s'",
857-
current_ssid,
858-
)
859854

860855
if hotspot_enabled:
861856
sec_type = self._hotspot_config.security

‎BlocksScreen/lib/panels/networkWindow.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Network settings UI: Wi-Fi, ethernet and hotspot panels backed by the NM manager."""
2+
13
import fcntl
24
import ipaddress as _ipaddress
35
import logging

0 commit comments

Comments
 (0)