#!/usr/bin/env python3 """Global utility methods and classes.""" import os import shlex import subprocess #nosec import sys 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))) def run_command(command): cmd = [x.strip() for x in shlex.split(command)] p = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) #nosec return p def humanize(value): return value.decode("utf-8").strip() class Singleton(type): _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]