import pickle
import subprocess
import tarfile
import tempfile

import yaml


def load_yaml(raw: str):
    return yaml.load(raw)


def restore(payload: bytes):
    return pickle.loads(payload)


def run_command(command: str):
    return subprocess.run(command, shell=True, check=True)


def unpack(archive_path: str, target: str):
    with tarfile.open(archive_path) as archive:
        archive.extractall(target)


def make_temp_copy(data: bytes):
    path = tempfile.mkdtemp()
    return path