|
|
|
|
@ -11,10 +11,16 @@ import zipfile
|
|
|
|
|
|
|
|
|
|
# Global settings of this program
|
|
|
|
|
# ./config.py
|
|
|
|
|
from config import DB_LOCATION, DATA_LOCATION
|
|
|
|
|
from config import DB_LOCATION, DATA_LOCATION, DEST_SHRUNK, DEST_ORIGINAL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# our own util for photo upload and processing
|
|
|
|
|
from util import import_photos as iph
|
|
|
|
|
|
|
|
|
|
# Initialization logic
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
security = HTTPBasic()
|
|
|
|
|
iph.check_database(database_path=DB_LOCATION)
|
|
|
|
|
con = sqlite3.connect(DB_LOCATION)
|
|
|
|
|
con.row_factory = sqlite3.Row
|
|
|
|
|
cur = con.cursor() # NB! single is enough for now, we might require multiple later
|
|
|
|
|
@ -193,13 +199,15 @@ def unpack_pictures_zip(file: UploadFile, time):
|
|
|
|
|
Extract pictures in the DATA_LOCATION/processing
|
|
|
|
|
#TODO: and feed them to util/import_photos.py
|
|
|
|
|
#TODO: Walk the nested DATA_LOCATION/processing ourselves
|
|
|
|
|
Uses: DATA_LOCATION
|
|
|
|
|
Uses: DB_LOCATION, DATA_LOCATION
|
|
|
|
|
"""
|
|
|
|
|
# we only call this function sporadically, so import here
|
|
|
|
|
import os
|
|
|
|
|
from shutil import rmtree
|
|
|
|
|
|
|
|
|
|
print(f"Accepted {file.filename} at {time} into processing")
|
|
|
|
|
os.makedirs(os.path.join(DATA_LOCATION, "processing"), exist_ok=True)
|
|
|
|
|
processing_path = os.path.join(DATA_LOCATION, "processing" + time)
|
|
|
|
|
os.makedirs(processing_path, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
# using private ._file field is a dirty hack, but
|
|
|
|
|
# SpooledTemporaryFile does not implement seekable
|
|
|
|
|
@ -209,9 +217,20 @@ def unpack_pictures_zip(file: UploadFile, time):
|
|
|
|
|
problem_files = photo_zip.testzip()
|
|
|
|
|
if problem_files is not None:
|
|
|
|
|
print(f"Errors in {file.filename} from {time} at {problem_files}")
|
|
|
|
|
photo_zip.extractall(path=os.path.join(DATA_LOCATION, "processing"))
|
|
|
|
|
photo_zip.extractall(path=processing_path)
|
|
|
|
|
photo_zip.close()
|
|
|
|
|
|
|
|
|
|
print(f"Start processing {file.filename} from {time}")
|
|
|
|
|
|
|
|
|
|
iph.check_database(database_path=DB_LOCATION)
|
|
|
|
|
for (dir, _, _) in os.walk(processing_path):
|
|
|
|
|
iph.run(
|
|
|
|
|
db_location=DB_LOCATION,
|
|
|
|
|
source=os.path.join(dir),
|
|
|
|
|
dest_shrunk=os.path.join(DATA_LOCATION, DEST_SHRUNK),
|
|
|
|
|
dest_original=os.path.join(DATA_LOCATION, DEST_ORIGINAL),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
rmtree(processing_path)
|
|
|
|
|
|
|
|
|
|
print(f"Succesfully processed {file.filename} from {time}")
|
|
|
|
|
|