TheBird

paths.py

650 B · python · 26 lines

1import os2from pathlib import Path34HERE = Path(__file__).resolve().parent.parent5DATA_DIR = os.path.join("data", os.path.relpath(HERE))6FILES = HERE / "files"7CUTS = FILES / "cuts"8GRIDS = FILES / "grids"9GIFS = FILES / "gifs"10EXTRAS = FILES / "extras"11HERO = FILES / "hero.png"1213def ensure():14    for folder in (CUTS, GRIDS, GIFS, EXTRAS):15        folder.mkdir(parents=True, exist_ok=True)1617def data(name):18    os.makedirs(DATA_DIR, exist_ok=True)19    return Path(DATA_DIR) / name2021def show(path):22    return os.path.relpath(path)2324def write(path, body):25    with open(path, "w") as f:26        f.write(body if body.endswith("\n") else body + "\n")