From: Holger Levsen Date: Tue, 26 Feb 2013 18:16:05 +0000 (+0100) Subject: count existing images and issue warning if number is greater then 10 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=3e2bad2c1ae93b2ab6758df0727a6a0238ebc41a;p=profitbricks%2Fjenkins-build-scripts.git count existing images and issue warning if number is greater then 10 --- diff --git a/cleanup_liveboot.py b/cleanup_liveboot.py index 4fff2ef..928c239 100755 --- a/cleanup_liveboot.py +++ b/cleanup_liveboot.py @@ -27,6 +27,18 @@ def liveboot_to_keep(name): if cur.fetchone(): return True +def count_liveboots(): + con = db_connect() + cur = con.cursor() + try: + cur.execute("SELECT COUNT(keep_image) FROM liveboot WHERE keep_image = true") + except psycopg2.DatabaseError as e: + logger.debug("SELECT COUNT(keep_image) FROM liveboot WHERE keep_image = true") + return False + print cur.fetchone()[0] + return True + + def set_liveboot_to_delete(name): con = db_connect() cur = con.cursor() @@ -38,7 +50,10 @@ def set_liveboot_to_delete(name): return False if __name__ == '__main__': - if len(sys.argv) != 3 or sys.argv[1] not in ('keep', 'delete'): + if len(sys.argv) == 1: + count_liveboots() + sys.exit(0) + elif len(sys.argv) != 3 or sys.argv[1] not in ('keep', 'delete'): print("usage: %s keep $liveboot_name") print(" will return true or false, depending if 'keep_image' is set for this image") print("usage: %s delete $liveboot_name") diff --git a/debian_repos2db.sh b/debian_repos2db.sh index fd26667..5aae8cf 100755 --- a/debian_repos2db.sh +++ b/debian_repos2db.sh @@ -31,3 +31,10 @@ for REPO in $(seq 0 $REPOS) ; do done done done + +EXISTING_IMAGES=$(./cleanup_liveboot.py) + +if [ "$EXISTING_IMAGES" -gt 10 ] ; then + figlet WARNING + echo "$EXISTING_IMAGES liveboot images exist, you probably need to delete some..." +fi