2021-06-09 18:44:10 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""Global utility methods and classes."""
|
|
|
|
|
|
|
|
from distutils.util import strtobool
|
2023-06-28 06:19:11 +00:00
|
|
|
from typing import ClassVar
|
2021-06-09 18:44:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
def to_bool(string):
|
|
|
|
return bool(strtobool(str(string)))
|
|
|
|
|
|
|
|
|
|
|
|
class Singleton(type):
|
|
|
|
"""Meta singleton class."""
|
|
|
|
|
2023-06-28 06:19:11 +00:00
|
|
|
_instances: ClassVar[dict] = {}
|
2021-06-09 18:44:10 +00:00
|
|
|
|
|
|
|
def __call__(cls, *args, **kwargs):
|
|
|
|
if cls not in cls._instances:
|
2023-02-12 14:11:15 +00:00
|
|
|
cls._instances[cls] = super().__call__(*args, **kwargs)
|
2021-06-09 18:44:10 +00:00
|
|
|
return cls._instances[cls]
|