From dffc6022bea8f89ab80b970a8d8d459b43cc2889 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Mon, 17 Feb 2025 13:50:45 -0600 Subject: [PATCH] make the directory if we need to --- home/private_bin/executable_mkscratch | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/home/private_bin/executable_mkscratch b/home/private_bin/executable_mkscratch index 0ae5914..af4114a 100644 --- a/home/private_bin/executable_mkscratch +++ b/home/private_bin/executable_mkscratch @@ -7,11 +7,14 @@ from tempfile import mkdtemp SCRATCH_DIR = Path.home() / "scratch" WEEK_SCRATCH = SCRATCH_DIR / datetime.now().strftime("%Y/%U") + (SCRATCH_DIR / "current").unlink() (SCRATCH_DIR / "current").symlink_to(WEEK_SCRATCH) -def clean_up(): +def scratch_maintenance(): + if not WEEK_SCRATCH.is_dir(): + WEEK_SCRATCH.mkdir(exist_ok=True) for p in WEEK_SCRATCH.iterdir(): if p.is_dir() and len(list(p.iterdir())) == 0: sys.stderr.write(f"removing: {p}\n") @@ -27,15 +30,18 @@ def make_named(name: str) -> Path: d.mkdir(exist_ok=True) return d + def return_last() -> Path: - dirs = [ d for d in WEEK_SCRATCH.iterdir() if d.is_dir()] + dirs = [d for d in WEEK_SCRATCH.iterdir() if d.is_dir()] if len(dirs) == 0: sys.stderr.write("no directores. exiting...") - return sorted(dirs, key = lambda p: p.stat().st_mtime, reverse=True)[0] + return sorted(dirs, key=lambda p: p.stat().st_mtime, reverse=True)[0] + def main(): - clean_up() + scratch_maintenance() + if len(sys.argv) > 2: sys.exit("unexpected number of arguments") @@ -50,5 +56,6 @@ def main(): print(d) + if __name__ == "__main__": main()