mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 02:48:38 -04:00
Warning once when iwgetid is not available.
This commit is contained in:
parent
a98aebfdda
commit
c3f518060e
3 changed files with 12 additions and 5 deletions
|
|
@ -12,7 +12,8 @@ logger = logger.getChild(__name__)
|
|||
|
||||
POWER_SAVE_FREQ = 'powersave' # noqa
|
||||
|
||||
warn_once = get_warn_once('Unable to use nmcli', logger)
|
||||
nmcli_warn_once = get_warn_once('Unable to use nmcli', logger)
|
||||
iwgetid_warn_once = get_warn_once('Unable to use iwgetid', logger)
|
||||
|
||||
|
||||
class HotspotStatus(enum.Enum):
|
||||
|
|
@ -37,7 +38,7 @@ def hotspot_status() -> HotspotStatus:
|
|||
try:
|
||||
output = subprocess.check_output(cmd, stderr=subprocess.PIPE).decode().strip()
|
||||
except Exception as e:
|
||||
warn_once(e)
|
||||
nmcli_warn_once(e)
|
||||
return HotspotStatus.unknown
|
||||
|
||||
for line in output.splitlines():
|
||||
|
|
@ -69,6 +70,9 @@ def get_current_ssid(interface='wlan0') -> str | None:
|
|||
else:
|
||||
logger.error(f'Failed to get current ssid: {result.stderr}')
|
||||
return None
|
||||
except FileNotFoundError as e:
|
||||
iwgetid_warn_once(e)
|
||||
return None
|
||||
except Exception as e:
|
||||
logger.error('Failed to get current ssid', exc_info=e)
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -1563,12 +1563,12 @@ def get_warn_once(message: str, logger__: logging.Logger, level=logging.ERROR):
|
|||
"""Create a function that will report an error only once.
|
||||
|
||||
This is used when a function will be called many times, but the error is not important."""
|
||||
event = multiprocessing.Event()
|
||||
|
||||
def warn_once(exception: Exception):
|
||||
if not event.is_set():
|
||||
from wrolpi.api_utils import api_app
|
||||
if not api_app.shared_ctx.warn_once.get(message):
|
||||
logger__.log(level, message, exc_info=exception)
|
||||
event.set()
|
||||
api_app.shared_ctx.warn_once.update({message: True})
|
||||
|
||||
return warn_once
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,9 @@ def attach_shared_contexts(app: Sanic):
|
|||
app.shared_ctx.single_tasks_started = multiprocessing.Event()
|
||||
app.shared_ctx.flags_initialized = multiprocessing.Event()
|
||||
|
||||
# Warnings
|
||||
app.shared_ctx.warn_once = manager.dict()
|
||||
|
||||
# Locks
|
||||
app.shared_ctx.config_save_lock = multiprocessing.Lock()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue