import socket import os import face_recognition import io import base64 from PIL import Image, ImageOps hostname = socket.gethostname() PROD_HOST="pa_web" ICON={} ICON["Import"]="import" ICON["Storage"]="db" ICON["Bin"]="trash" if hostname == "lappy": PA_JOB_MANAGER_HOST="localhost" DB_URL = 'postgresql+psycopg2://pa:for_now_pa@localhost:5432/pa' elif 'FLASK_ENV' not in os.environ or os.environ['FLASK_ENV'] == "development": PA_JOB_MANAGER_HOST="localhost" DB_URL = 'postgresql+psycopg2://pa:for_now_pa@mara.ddp.net:65432/pa' elif os.environ['FLASK_ENV'] == "production": PA_JOB_MANAGER_HOST="localhost" DB_URL = 'postgresql+psycopg2://pa:for_now_pa@padb/pa' else: print( "ERROR: I do not know which environment (development, etc.) and which DB (on which host to use)" ) exit( -1 ) PA_JOB_MANAGER_PORT=55430 THUMBSIZE=256 def CreateSelect(name, selected, list, js="", add_class="", vals={} ): str = f'' return str def CreateFoldersSelect(selected, add_class=""): str = f'' return str def LocationIcon(obj): return ICON[obj.in_dir.in_path.type.name] # translate a path type, a full FS path and a file into the full FS path of the # symlink on the file system. To note, this is used with file == path, when we # want to just get the symlink to the path itself, otherwise file == ### FIXME: I think this is way over-complicated, want to revist one day, with #what params are passed in, what we need to get out -- I think the overloaded #file/oath use case, and why sometimes we trail with a / or not and then concat #last_dir and bit before last_dir, etc. this feels a bit too complicated for #what it does OR we comment this much better def SymlinkName(ptype, path, file): sig_bit=file.replace(path, "") last_dir=os.path.basename(path[0:-1]) if len(sig_bit) > 0 and sig_bit[-1] == '/': last_bit = os.path.dirname(sig_bit)[0:-1] else: last_bit = os.path.dirname(sig_bit) symlink = 'static/'+ptype+'/'+last_dir+'/'+last_bit if symlink[-1] == '/': symlink=symlink[0:-1] return symlink def GenThumb(fname): try: im_orig = Image.open(fname) im = ImageOps.exif_transpose(im_orig) bands = im.getbands() if 'A' in bands: im = im.convert('RGB') orig_w, orig_h = im.size im.thumbnail((THUMBSIZE,THUMBSIZE)) img_bytearray = io.BytesIO() im.save(img_bytearray, format='JPEG') img_bytearray = img_bytearray.getvalue() thumbnail = base64.b64encode(img_bytearray) thumbnail = str(thumbnail)[2:-1] return thumbnail, orig_w, orig_h except Exception as e: print( f"GenThumb failed: {e}") return None, None, None def GenFace(fname, model): img = face_recognition.load_image_file(fname) # TODO: change face_locations call basedon model location = face_recognition.face_locations(img, model=model) encodings = face_recognition.face_encodings(img, known_face_locations=location) if len(encodings): return encodings[0].tobytes(), location else: return None, None