]> git.decadent.org.uk Git - dak.git/commitdiff
Merge remote-tracking branch 'drkranz/fixes' into merge
authorJoerg Jaspert <joerg@debian.org>
Tue, 7 May 2013 18:35:40 +0000 (20:35 +0200)
committerJoerg Jaspert <joerg@debian.org>
Tue, 7 May 2013 18:35:40 +0000 (20:35 +0200)
* drkranz/fixes:
  ad348f8d has been superseded by 3daf09a3
  rrd-release-freeze-dates: drop obsolete dates
  rrd-release-freeze-dates: add wheezy release date
  upload.source can be null, fall back to upload.changes
  update-db: display descriptions before deploying update modules
  update-db: automatically find the schema nunmber to upgrade to

dak/update_db.py
scripts/debian/rrd-release-freeze-dates

index 4ac0c5db382e9804f5598f1affc6c78dfa2a5a97..5bbc40c5e80f0282cbc7456546667be6087dadfe 100755 (executable)
@@ -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
 
 ################################################################################
 
@@ -120,6 +121,7 @@ Updates dak's database schema to the lastest version. You should disable crontab
         print "Determining dak database revision ..."
         cnf = Config()
         logger = Logger('update-db')
+        modules = []
 
         try:
             # Build a connect string
@@ -155,25 +157,39 @@ 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:
+            print "\nUpdates to be applied:"
+            for i in range(database_revision, required_database_schema):
+                i += 1
+                dakdb = __import__("dakdb", globals(), locals(), ['update'+str(i)])
+                update_module = getattr(dakdb, "update"+str(i))
+                print "Update %d: %s" % (i, next(s for s in update_module.__doc__.split("\n") if s))
+                modules.append((update_module, i))
+            prompt = "\nUpdate 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)
 
-        for i in range (database_revision, required_database_schema):
+        for module in modules:
+            (update_module, i) = module
             try:
-                dakdb = __import__("dakdb", globals(), locals(), ['update'+str(i+1)])
-                update_module = getattr(dakdb, "update"+str(i+1))
                 update_module.do_update(self)
-                message = "updated database schema from %d to %d" % (database_revision, i+1)
+                message = "updated database schema from %d to %d" % (database_revision, i)
                 print message
                 logger.log([message])
             except DBUpdateError as e:
                 # Seems the update did not work.
-                print "Was unable to update database schema from %d to %d." % (database_revision, i+1)
+                print "Was unable to update database schema from %d to %d." % (database_revision, i)
                 print "The error message received was %s" % (e)
                 logger.log(["DB Schema upgrade failed"])
                 logger.close()
index 457e23367ca030cadb21551acb40c8adcf5dfba0..4d1c436310729d2f6bea62011a0d5a4f51c8d0e5 100644 (file)
@@ -1,4 +1,3 @@
-VRULE:1234691928#632a5b:lenny release
-VRULE:1281102258#0b19c1:squeeze freeze
 VRULE:1296908977#0b19c1:squeeze release
 VRULE:1341078720#00ff00:wheezy freeze
+VRULE:1367689920#00ff00:wheezy release