Add a script to fix the images.
This commit is contained in:
parent
0e14493edd
commit
af9b0904d9
1 changed files with 52 additions and 0 deletions
52
tools/fiximages.py
Normal file
52
tools/fiximages.py
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
|
from data.database import Image, ImageStorage
|
||||||
|
from app import storage
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logging.getLogger('boto').setLevel(logging.CRITICAL)
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_checksum(image_storage):
|
||||||
|
checksum_path = storage.image_checksum_path(image_storage.uuid)
|
||||||
|
try:
|
||||||
|
checksum = storage.get_content(checksum_path)
|
||||||
|
image_storage.checksum = checksum
|
||||||
|
logger.debug('Backfilled checksum for image: %s as: %s', image_storage.uuid, checksum)
|
||||||
|
return True
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def fix_images(image_storage_query):
|
||||||
|
for image_storage in image_storage_query:
|
||||||
|
dirty = False
|
||||||
|
if image_storage.checksum is None:
|
||||||
|
dirty = migrate_checksum(image_storage)
|
||||||
|
|
||||||
|
if image_storage.uploading is None:
|
||||||
|
dirty = True
|
||||||
|
mark_path = storage.image_mark_path(image_storage.uuid)
|
||||||
|
if storage.exists(mark_path):
|
||||||
|
image_storage.uploading = True
|
||||||
|
else:
|
||||||
|
image_storage.uploading = image_storage.checksum is None
|
||||||
|
|
||||||
|
logger.debug('Set uploading flag to %s for image: %s', image_storage.uploading,
|
||||||
|
image_storage.uuid)
|
||||||
|
|
||||||
|
if dirty:
|
||||||
|
image_storage.save()
|
||||||
|
|
||||||
|
|
||||||
|
storage_to_fix = (ImageStorage.select()
|
||||||
|
.where((ImageStorage.checksum >> None) &
|
||||||
|
((ImageStorage.uploading >> None) | (ImageStorage.uploading == False))))
|
||||||
|
|
||||||
|
logger.debug('Fixing %s images', storage_to_fix.count())
|
||||||
|
|
||||||
|
fix_images(storage_to_fix)
|
Reference in a new issue