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
849 B
Python
Raw Permalink 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
2020-06-08 17:39:36 +02:00
def run_cmd(*args: str, shell: bool = False) -> Tuple[int, CompletedProcess]:
2019-11-22 15:03:21 +01:00
if DRY_RUN:
print(" ".join(args))
return (0, None)
2020-06-08 17:39:36 +02:00
process = run(args, capture_output=True, shell=shell)
2019-11-22 15:03:21 +01:00
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)