#!/usr/bin/env python3
import os
import re
from subprocess import run, CompletedProcess
from typing import Tuple
DRY_RUN = False
def handle_error(process: CompletedProcess) -> int:
if process.stdout:
print(f"stdout: {process.stdout}")
if process.stderr:
print(f"stderr: {process.stderr}")
return process.returncode
def run_cmd(*args: str, shell: bool = False) -> Tuple[int, CompletedProcess]:
if DRY_RUN:
print(" ".join(args))
return (0, None)
process = run(args, capture_output=True, shell=shell)
return (handle_error(process), process)
def make_pair(submission: str) -> Tuple[str, str]:
login = re.search("(x[a-z0-9]*)_.*", submission).group(1)
return (login, submission)
def mkcd(directory: str) -> None:
os.makedirs(directory, exist_ok=True)
os.chdir(directory)