From 250f09153d2500e358a950a6e122e0f1c950f31e Mon Sep 17 00:00:00 2001 From: rrr-marble Date: Sun, 26 Sep 2021 22:32:52 +0300 Subject: [PATCH] ref: use explicit paths instead of chdir --- main.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index ccd852f..90da7c2 100644 --- a/main.py +++ b/main.py @@ -225,9 +225,7 @@ def unpack_pictures_zip(file: UploadFile, time): import os print(f"Accepted {file.filename} at {time} into processing") - os.chdir(DATA_LOCATION) - os.makedirs("processing", exist_ok=True) - os.chdir("processing") + os.makedirs(os.path.join(DATA_LOCATION, "processing"), exist_ok=True) # using private ._file field is a dirty hack, but # SpooledTemporaryFile does not implement seekable @@ -236,7 +234,10 @@ def unpack_pictures_zip(file: UploadFile, time): with zipfile.ZipFile(file.file._file) as photo_zip: problem_files = photo_zip.testzip() if problem_files is not None: - print(f"Errors in {file.filename} accepted at {time}: {problem_files}") - photo_zip.extractall() + print(f"Errors in {file.filename} from {time} at {problem_files}") + photo_zip.extractall(path=os.path.join(DATA_LOCATION, "processing")) photo_zip.close() - print(f"Succesfully processed {file.filename} accepted at {time}") + + print(f"Start processing {file.filename} from {time}") + + print(f"Succesfully processed {file.filename} from {time}")