docker-tidy/dockertidy/Utils.py

21 lines
448 B
Python
Raw Normal View History

2020-03-01 17:42:29 +00:00
#!/usr/bin/env python3
"""Global utility methods and classes."""
from distutils.util import strtobool
def to_bool(string):
return bool(strtobool(str(string)))
class Singleton(type):
2020-03-06 21:39:32 +00:00
"""Singleton metaclass."""
2020-03-01 17:42:29 +00:00
_instances = {}
2020-03-06 21:39:32 +00:00
def __call__(cls, *args, **kwargs): # noqa
2020-03-01 17:42:29 +00:00
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]