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

36 lines
815 B
Python
Raw Normal View History

2019-11-22 15:03:21 +01:00
#!/usr/bin/env python3
import os
import re
from subprocess import run, CompletedProcess
from typing import Tuple
2019-11-30 13:49:44 +01:00
DRY_RUN = False
2019-11-22 15:03:21 +01:00
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) -> Tuple[int, CompletedProcess]:
if DRY_RUN:
print(" ".join(args))
return (0, None)
process = run(args, capture_output=True)
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)