X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=lightcards%2Fprogress.py;h=8956b63ab7043063850bb29adf837eb8f4fb2eb0;hb=b50ac3096f5138870bd3bebb60e15b3f51e3e128;hp=665ae315485cba08b742073af68e188608f031d3;hpb=23bedf0b57ac06fbee12af000f42c992d3227dd1;p=lightcards.git diff --git a/lightcards/progress.py b/lightcards/progress.py index 665ae31..8956b63 100644 --- a/lightcards/progress.py +++ b/lightcards/progress.py @@ -4,29 +4,30 @@ import hashlib import os import pickle -import shutil -global dired dired = f"{os.path.expanduser('~')}/.cache/lightcards/" + def name_gen(stra): - hasher = hashlib.md5() - hasher.update(str(stra).encode("utf-8")) - return(hasher.hexdigest()) + """Generate hash of stack for name of pickle file""" + return hashlib.md5(str([str(x) for x in stra]).encode("utf-8")).hexdigest() def make_dirs(dired): + """mkdir -p equivalent""" if not os.path.exists(dired): os.makedirs(dired) def dump(obj, stra): + """Write pickle file""" make_dirs(dired) pickle.dump(obj, open(f"{dired}/{name_gen(stra)}.p", "wb")) def dive(stra): + """Get pickle file""" file = f"{dired}/{name_gen(stra)}.p" make_dirs(dired) if os.path.exists(file): @@ -36,15 +37,7 @@ def dive(stra): def purge(stra): - file = f"{dired}/{name_gen(stra)}/" + """Delete pickle file""" + file = f"{dired}/{name_gen(stra)}.p" if os.path.exists(file): - shutil.rmtree(file) - - -def purge_all(): - if os.path.exists(dired): - shutil.rmtree(dired) - - -if __name__ == "__main__": - main() + os.remove(file)