git-batch/gitbatch/utils.py

26 lines
568 B
Python
Raw Normal View History

2019-12-02 08:53:35 +00:00
#!/usr/bin/env python3
"""Global utility methods and classes."""
import os
from distutils.util import strtobool
def normalize_path(path):
if path:
return os.path.abspath(os.path.expanduser(os.path.expandvars(path)))
def to_bool(string):
return bool(strtobool(str(string)))
class Singleton(type):
2020-04-11 11:17:01 +00:00
"""Meta singleton class."""
2019-12-02 08:53:35 +00:00
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]