From 3002371f5aa2c94aa207731088a45ad4a1674130 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 26 Sep 2014 11:20:26 -0400 Subject: [PATCH] Add an orphans lookup script --- tools/orphans.py | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/tools/orphans.py b/tools/orphans.py index 17babf31a..a8990f79b 100644 --- a/tools/orphans.py +++ b/tools/orphans.py @@ -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