mirror of
https://github.com/craigerl/aprsd.git
synced 2025-09-05 14:47:53 -04:00
Added client_exists() for client factory
This patch adds a method in the factory to detect if we have created the client yet or not.
This commit is contained in:
parent
95094b874c
commit
505565d3a6
@ -42,6 +42,7 @@ class Client(Protocol):
|
|||||||
class ClientFactory:
|
class ClientFactory:
|
||||||
_instance = None
|
_instance = None
|
||||||
clients = []
|
clients = []
|
||||||
|
client = None
|
||||||
|
|
||||||
def __new__(cls, *args, **kwargs):
|
def __new__(cls, *args, **kwargs):
|
||||||
"""This magic turns this into a singleton."""
|
"""This magic turns this into a singleton."""
|
||||||
@ -62,9 +63,13 @@ class ClientFactory:
|
|||||||
def create(self, key=None):
|
def create(self, key=None):
|
||||||
for client in self.clients:
|
for client in self.clients:
|
||||||
if client.is_enabled():
|
if client.is_enabled():
|
||||||
return client()
|
self.client = client()
|
||||||
|
return self.client
|
||||||
raise Exception("No client is configured!!")
|
raise Exception("No client is configured!!")
|
||||||
|
|
||||||
|
def client_exists(self):
|
||||||
|
return bool(self.client)
|
||||||
|
|
||||||
def is_client_enabled(self):
|
def is_client_enabled(self):
|
||||||
"""Make sure at least one client is enabled."""
|
"""Make sure at least one client is enabled."""
|
||||||
enabled = False
|
enabled = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user