This repository has been archived on 2023-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
drone-cleanup-agents/cleanupagents/Utils.py

36 lines
819 B
Python

#!/usr/bin/env python3
"""Global utility methods and classes."""
import os
import shlex
import subprocess # nosec
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]