From: Luca Falavigna Date: Mon, 29 Apr 2013 19:14:13 +0000 (+0000) Subject: update-db: automatically find the schema nunmber to upgrade to X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8da2a8dd940bf5f7c381c887c1c2fadd6457f5f4;p=dak update-db: automatically find the schema nunmber to upgrade to --- diff --git a/dak/update_db.py b/dak/update_db.py index 4ac0c5db..6f162cbf 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -37,6 +37,8 @@ import os import apt_pkg import time import errno +from glob import glob +from re import findall from daklib import utils from daklib.config import Config @@ -46,7 +48,6 @@ from daklib.daklog import Logger ################################################################################ Cnf = None -required_database_schema = 97 ################################################################################ @@ -155,10 +156,18 @@ Updates dak's database schema to the lastest version. You should disable crontab self.update_db_to_zero() database_revision = 0 + dbfiles = glob(os.path.join(os.path.dirname(__file__), 'dakdb/update*.py')) + required_database_schema = int(max(findall('update(\d+).py', " ".join(dbfiles)))) + print "dak database schema at %d" % database_revision print "dak version requires schema %d" % required_database_schema - if database_revision == required_database_schema: + if database_revision < required_database_schema: + prompt = "Update database? (y/N) " + answer = utils.our_raw_input(prompt) + if answer.upper() != 'Y': + sys.exit(0) + else: print "no updates required" logger.log(["no updates required"]) sys.exit(0)