Eradicate the s3 versions of the checksum and the uploading flag.

This commit is contained in:
Jake Moshenko 2014-06-12 19:27:43 -04:00
parent af9b0904d9
commit fb465fd66f
4 changed files with 6 additions and 105 deletions

View file

@ -1,21 +0,0 @@
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
logging.getLogger('boto').setLevel(logging.CRITICAL)
from data.database import ImageStorage
from app import storage
for image_storage in ImageStorage.select().where(ImageStorage.uploading == None):
mark_path = storage.image_mark_path(None, None, None, image_storage.uuid)
json_path = storage.image_json_path(None, None, None, image_storage.uuid)
logger.info('Mark path: %s Json path: %s', mark_path, json_path)
if storage.exists(json_path):
image_storage.uploading = storage.exists(mark_path)
logger.info('Image existed and was currently uploading: %s', image_storage.uploading)
image_storage.save()
else:
logger.warning('Image does not exist.')

View file

@ -1,52 +0,0 @@
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)