Add an orphans lookup script

This commit is contained in:
Joseph Schorr 2014-09-26 11:20:26 -04:00
parent 6070c251ae
commit 3002371f5a

View file

@ -1,22 +1,15 @@
from data.database import Image
from app import app, storage as store
from data.database import Image, ImageStorage
from peewee import JOIN_LEFT_OUTER, fn
from app import app
live_image_id_set = set()
orphaned = (ImageStorage
.select()
.where(ImageStorage.uploading == False)
.join(Image, JOIN_LEFT_OUTER)
.group_by(ImageStorage)
.having(fn.Count(Image.id) == 0))
for image in Image.select():
live_image_id_set.add(image.docker_image_id)
storage_image_id_set = set()
for customer in store.list_directory('images/'):
for repo in store.list_directory(customer):
for image in store.list_directory(repo):
storage_image_id_set.add(image.split('/')[-1])
orphans = storage_image_id_set.difference(live_image_id_set)
missing_image_data = live_image_id_set.difference(storage_image_id_set)
for orphan in orphans:
print "Orphan: %s" % orphan
for missing in missing_image_data:
print "Missing: %s" % missing
counter = 0
for orphan in orphaned:
counter += 1
print orphan.uuid