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

37 lines
830 B
Python
Raw Normal View History

2019-12-18 19:24:58 +00:00
#!/usr/bin/env python3
"""Global utility methods and classes."""
import os
import shlex
2019-12-18 19:40:08 +00:00
import subprocess # nosec
2019-12-18 19:24:58 +00:00
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)]
2019-12-18 19:40:08 +00:00
p = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) # nosec
2019-12-18 19:24:58 +00:00
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]