This repository has been archived on 2023-07-17. You can view files and clone it, but cannot push or open issues or pull requests.
pushee/utils.py
2020-06-08 17:39:36 +02:00

35 lines
849 B
Python

#!/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)