From 8dca6783fc4719e56db17fc8ab7b93c93307a75c Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 26 Oct 2020 11:03:37 +0200 Subject: [PATCH] Fixed spelling, added utility methods --- killswitch.py | 30 ++++++++++++++++++++++++------ plugins/eddn.py | 2 +- plugins/edsm.py | 2 +- plugins/inara.py | 2 +- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/killswitch.py b/killswitch.py index c6139527..da56abd6 100644 --- a/killswitch.py +++ b/killswitch.py @@ -1,5 +1,5 @@ """Fetch kill switches from EDMC Repo.""" -from typing import Dict, List, NamedTuple, Optional, Tuple, Union, cast +from typing import Dict, List, NamedTuple, Optional, Union, cast import requests import semantic_version @@ -25,7 +25,7 @@ class KillSwitch(NamedTuple): class DisabledResult(NamedTuple): """DisabledResult is the result returned from various is_disabled calls.""" - disbled: bool + disabled: bool reason: str @@ -35,13 +35,13 @@ class KillSwitchSet: def __init__(self, kill_switches: List[KillSwitch]) -> None: self.kill_switches = kill_switches - def is_disabled(self, id: str, *, version=_current_version) -> DisabledResult: + def get_disabled(self, id: str, *, version=_current_version) -> DisabledResult: """ Return whether or not the given feature ID is disabled by a killswitch for the given version. :param id: The feature ID to check :param version: The version to check killswitches for, defaults to the current EDMC version - :return: a bool indicating status + :return: a namedtuple indicating status and reason, if any """ for ks in self.kill_switches: if version != ks.version: @@ -51,6 +51,14 @@ class KillSwitchSet: return DisabledResult(False, "") + def is_disabled(self, id: str, *, version=_current_version) -> bool: + """Return whether or not a given feature ID is disabled for the given version.""" + return self.get_disabled(id, version=version).disabled + + def get_reason(self, id: str, version=_current_version) -> str: + """Return a reason for why the given id is disabled for the given version, if any.""" + return self.get_disabled(id, version=version).reason + def __str__(self) -> str: """Return a string representation of KillSwitchSet.""" return f'KillSwitchSet: {str(self.kill_switches)}' @@ -155,17 +163,27 @@ def setup_main_list(): active = KillSwitchSet(parse_kill_switches(data)) -def is_disabled(id: str, *, version: semantic_version.Version = _current_version) -> DisabledResult: +def get_disabled(id: str, *, version: semantic_version.Version = _current_version) -> DisabledResult: """ Query the global KillSwitchSet for whether or not a given ID is disabled. See KillSwitchSet#is_disabled for more information """ + return active.get_disabled(id, version=version) + + +def is_disabled(id: str, *, version=_current_version) -> bool: + """Query the global KillSwitchSet#is_disabled method.""" return active.is_disabled(id, version=version) +def get_reason(id: str, *, version=_current_version) -> str: + """Query the global KillSwitchSet#get_reason method.""" + return active.get_reason(id, version=version) + + if __name__ == "__main__": setup_main_list() print(f'{_current_version=}') - print(f"{is_disabled('test')=}") + print(f"{get_disabled('test')=}") print(f"{active=}") diff --git a/plugins/eddn.py b/plugins/eddn.py index d952b219..1fcde025 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -127,7 +127,7 @@ class EDDN: :param cmdr: the CMDR to use as the uploader ID :param msg: the payload to send """ - if (res := killswitch.is_disabled('plugins.eddn.send')).disbled: + if (res := killswitch.get_disabled('plugins.eddn.send')).disabled: logger.warning(f"eddn.send has been disabled via killswitch. Returning. ({res.reason})") return diff --git a/plugins/edsm.py b/plugins/edsm.py index 4260e280..306c20e4 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -511,7 +511,7 @@ def worker() -> None: retrying = 0 while retrying < 3: - if (res := killswitch.is_disabled("plugins.edsm.worker")).disbled: + if (res := killswitch.get_disabled("plugins.edsm.worker")).disabled: logger.warning( f'EDSM worker has been disabled via kill switch. Not uploading data. ({res.reason})' ) diff --git a/plugins/inara.py b/plugins/inara.py index abdfe7b9..1543be1b 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -1203,7 +1203,7 @@ def new_worker(): logger.debug('Starting...') while True: events = get_events() - if (res := killswitch.is_disabled("plugins.inara.worker")).disbled: + if (res := killswitch.get_disabled("plugins.inara.worker")).disabled: logger.warning(f"Inara worker disabled via killswitch. ({res.reason})") continue