ref: extract globals into common config.py

main^2
rrr-marble 4 years ago
parent ffc3ce75cc
commit 822e512a01

@ -0,0 +1,11 @@
# use database residing here
DB_LOCATION = (
"testbox/photovoter.dblite" # Q: any allowances for this being not OUR database?
)
DATA_LOCATION = "/tmp/123"
# place compressed images here (needs to exist)
DEST_SHRUNK = "image/"
# move originals here (needs to exist)
DEST_ORIGINAL = "original/"

@ -9,12 +9,9 @@ from uuid import uuid4
import sqlite3 import sqlite3
import zipfile import zipfile
# Global settings of this program
# use database residing here # ./config.py
DB_LOCATION = ( from config import DB_LOCATION, DATA_LOCATION
"../testbox/photovoter.dblite" # Q: any allowances for this being not OUR database?
)
DATA_LOCATION = "/tmp/123"
app = FastAPI() app = FastAPI()
security = HTTPBasic() security = HTTPBasic()
@ -219,9 +216,9 @@ async def upload_pictures(
def unpack_pictures_zip(file: UploadFile, time): def unpack_pictures_zip(file: UploadFile, time):
""" """
Unpack and process zip archived photo Unpack and process zip archived photo
Extract pictures in the DATA_LOCATION/processing Extract pictures in the DATA_LOCATION/processing
#TODO: and feed them to util/import_photos.py #TODO: and feed them to util/import_photos.py
#TODO: Walk the nested DATA_LOCATION/processing ourselves #TODO: Walk the nested DATA_LOCATION/processing ourselves
Uses: DATA_LOCATION Uses: DATA_LOCATION
""" """
# we only call this function sporadically, so import here # we only call this function sporadically, so import here
@ -229,7 +226,7 @@ def unpack_pictures_zip(file: UploadFile, time):
print(f"Accepted {file.filename} at {time} into processing") print(f"Accepted {file.filename} at {time} into processing")
os.chdir(DATA_LOCATION) os.chdir(DATA_LOCATION)
os.mkdir("processing") os.makedirs("processing", exist_ok=True)
os.chdir("processing") os.chdir("processing")
# using private ._file field is a dirty hack, but # using private ._file field is a dirty hack, but

@ -8,15 +8,6 @@ from sys import argv, stderr
from shutil import move from shutil import move
import sqlite3 import sqlite3
# update database residing here
DB_LOCATION = (
"db/photovoter.dblite" # Q: any allowances for this being not OUR database?
)
# place compressed images here (needs to exist)
DEST_SHRUNK = "db/image/"
# move originals here (needs to exist)
DEST_ORIGINAL = "db/original/"
def process_pictures(source: str, dest_shrunk: str, dest_original: str): def process_pictures(source: str, dest_shrunk: str, dest_original: str):
"""Process images from the base directory in the first command line argument. """Process images from the base directory in the first command line argument.
@ -187,7 +178,15 @@ def main():
usage() usage()
exit(1) exit(1)
run(DB_LOCATION, argv[1], DEST_SHRUNK, DEST_ORIGINAL) import sys
import os
# append root directory to sys.path
# to allow import globals from ../config.py
sys.path.append(os.path.dirname(__file__) + "/..")
import config as cfg
run(cfg.DB_LOCATION, argv[1], cfg.DEST_SHRUNK, cfg.DEST_ORIGINAL)
if __name__ == "__main__": if __name__ == "__main__":

Loading…
Cancel
Save