Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
image = _fix_orientation(image)
except IOError:
image = None
if image:
values['width'] = image.width
values['height'] = image.height
values['transparent'] = image.mode in ('RGBA', 'P')
values['is_asset'] = False
else:
# PIL could not figure out what file type this is, so treat it as
# an asset
values['is_asset'] = True
values['asset_name'] = os.path.join(values['checksum'][:5],
os.path.basename(file_path))
record = model.Image.get(file_path=file_path)
if record:
record.set(**values)
else:
record = model.Image(**values)
orm.commit()
return record
image = fix_orientation(image)
except IOError:
image = None
if image:
values['width'] = image.width
values['height'] = image.height
values['transparent'] = image.mode in ('RGBA', 'P')
values['is_asset'] = False
else:
# PIL could not figure out what file type this is, so treat it as
# an asset
values['is_asset'] = True
values['asset_name'] = os.path.join(values['checksum'][:5],
os.path.basename(file_path))
record = model.Image.get(file_path=file_path)
if record:
record.set(**values)
else:
record = model.Image(**values)
orm.commit()
return record
def _get_asset(file_path):
""" Get the database record for an asset file """
record = model.Image.get(file_path=file_path)
fingerprint = ','.join((utils.file_fingerprint(file_path),
str(RENDITION_VERSION)))
if not record or record.fingerprint != fingerprint:
# Reindex the file
logger.info("Updating image %s -> %s", file_path, fingerprint)
# compute the md5sum; from https://stackoverflow.com/a/3431838/318857
md5 = hashlib.md5()
md5.update(bytes(RENDITION_VERSION))
with open(file_path, 'rb') as file:
for chunk in iter(lambda: file.read(16384), b""):
md5.update(chunk)
values = {
'file_path': file_path,
'checksum': md5.hexdigest(),
def _get_asset(file_path):
""" Get the database record for an asset file """
record = model.Image.get(file_path=file_path)
fingerprint = ','.join((utils.file_fingerprint(file_path),
str(RENDITION_VERSION)))
if not record or record.fingerprint != fingerprint:
# Reindex the file
LOGGER.info("Updating image %s -> %s", file_path, fingerprint)
# compute the md5sum; from https://stackoverflow.com/a/3431838/318857
md5 = hashlib.md5()
md5.update(bytes(RENDITION_VERSION))
with open(file_path, 'rb') as file:
for chunk in iter(lambda: file.read(16384), b""):
md5.update(chunk)
values = {
'file_path': file_path,
'checksum': md5.hexdigest(),