Skip to content

Commit

Permalink
Remove deprecated package and attribute references (#1020)
Browse files Browse the repository at this point in the history
  • Loading branch information
michplunkett authored Aug 12, 2023
1 parent ea861a8 commit d5acbd0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 60 deletions.
41 changes: 0 additions & 41 deletions OpenOversight/app/custom.py

This file was deleted.

22 changes: 11 additions & 11 deletions OpenOversight/app/utils/cloud.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
import hashlib
import imghdr as imghdr
import os
import sys
from io import BytesIO
Expand Down Expand Up @@ -83,9 +82,9 @@ def upload_obj_to_s3(file_obj, dest_filename):
# Folder to store files in on S3 is first two chars of dest_filename
s3_folder = dest_filename[0:2]
s3_filename = dest_filename[2:]
file_ending = imghdr.what(None, h=file_obj.read())
pimage = Pimage.open(file_obj)
file_obj.seek(0)
s3_content_type = f"image/{file_ending}"
s3_content_type = f"image/{pimage.format.lower()}"
s3_path = f"{s3_folder}/{s3_filename}"
s3_client.upload_fileobj(
file_obj,
Expand All @@ -106,22 +105,23 @@ def upload_obj_to_s3(file_obj, dest_filename):

def upload_image_to_s3_and_store_in_db(image_buf, user_id, department_id=None):
"""
Just a quick explaination of the order of operations here...
we have to scrub the image before we do anything else like hash it
Just a quick explanation of the order of operations here...
we have to scrub the image before we do anything else like hash it,
but we also have to get the date for the image before we scrub it.
"""
image_buf.seek(0)
image_type = imghdr.what(image_buf)
if image_type not in current_app.config["ALLOWED_EXTENSIONS"]:
raise ValueError(f"Attempted to pass invalid data type: {image_type}")
image_buf.seek(0)
pimage = Pimage.open(image_buf)
image_format = pimage.format.lower()
if image_format not in current_app.config["ALLOWED_EXTENSIONS"]:
raise ValueError(f"Attempted to pass invalid data type: {image_format}")
image_buf.seek(0)

date_taken = find_date_taken(pimage)
if date_taken:
date_taken = datetime.datetime.strptime(date_taken, "%Y:%m:%d %H:%M:%S")
pimage.getexif().clear()
scrubbed_image_buf = BytesIO()
pimage.save(scrubbed_image_buf, image_type)
pimage.save(scrubbed_image_buf, image_format)
pimage.close()
scrubbed_image_buf.seek(0)
image_data = scrubbed_image_buf.read()
Expand All @@ -130,7 +130,7 @@ def upload_image_to_s3_and_store_in_db(image_buf, user_id, department_id=None):
if existing_image:
return existing_image
try:
new_filename = f"{hash_img}.{image_type}"
new_filename = f"{hash_img}.{image_format}"
scrubbed_image_buf.seek(0)
url = upload_obj_to_s3(scrubbed_image_buf, new_filename)
new_image = Image(
Expand Down
6 changes: 0 additions & 6 deletions OpenOversight/app/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@

from flask import current_app, url_for

from OpenOversight.app.custom import add_jpeg_patch


# Call JPEG patch function
add_jpeg_patch()


def ac_can_edit_officer(officer, ac):
if officer.department_id == ac.ac_department_id:
Expand Down
2 changes: 1 addition & 1 deletion OpenOversight/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ def browser(app, server_port):
# start headless webdriver
visual_display = Xvfb()
visual_display.start()
driver = webdriver.Firefox(log_path="/tmp/geckodriver.log")
driver = webdriver.Firefox(service_log_path="/tmp/geckodriver.log")
# wait for browser to start up
time.sleep(3)
yield driver
Expand Down
3 changes: 2 additions & 1 deletion OpenOversight/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from io import BytesIO

import PIL
import pytest
from flask import current_app
from flask_login import current_user
Expand Down Expand Up @@ -264,7 +265,7 @@ def test_upload_image_to_s3_and_store_in_db_saves_filename_in_correct_format(
def test_upload_image_to_s3_and_store_in_db_throws_exception_for_unrecognized_format(
mockdata, client
):
with pytest.raises(ValueError):
with pytest.raises(PIL.UnidentifiedImageError):
upload_image_to_s3_and_store_in_db(BytesIO(b"invalid-image"), 1, 1)


Expand Down

0 comments on commit d5acbd0

Please sign in to comment.