X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fupdate_db.py;h=dc943503900a672920063f8fca40189d4a81d9e2;hb=203e76d0f6eddac1ad270d68df5e96357d0d0011;hp=33d3ebb9e64a2d94239f6ba5e37da75bc52a35fd;hpb=e4d65e532a06cc2785514cb9c5ebed5e1ec97cc7;p=dak.git diff --git a/dak/update_db.py b/dak/update_db.py index 33d3ebb9..dc943503 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -26,7 +26,7 @@ ################################################################################ -import psycopg2, sys +import psycopg2, sys, fcntl, os import apt_pkg import time from daklib import database @@ -115,7 +115,7 @@ Updates dak's database schema to the lastest version. You should disable crontab print "Please make sure you have a database backup handy. If you don't, press Ctrl-C now!" print "" print "Continuing in five seconds ..." - #time.sleep(5) + time.sleep(5) print "" print "Attempting to upgrade pre-zero database to zero" @@ -134,7 +134,7 @@ Updates dak's database schema to the lastest version. You should disable crontab dakdb = __import__("dakdb", globals(), locals(), ['update'+str(i+1)]) update_module = getattr(dakdb, "update"+str(i+1)) update_module.do_update(self) - database_revision =+ 1 + database_revision += 1 ################################################################################ @@ -156,8 +156,17 @@ Updates dak's database schema to the lastest version. You should disable crontab utils.warn("dak update-db takes no arguments.") usage(exit_code=1) + self.update_db() + try: + lock_fd = os.open(Cnf["Dinstall::LockFile"], os.O_RDWR | os.O_CREAT) + fcntl.lockf(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB) + except IOError, e: + if errno.errorcode[e.errno] == 'EACCES' or errno.errorcode[e.errno] == 'EAGAIN': + utils.fubar("Couldn't obtain lock; assuming another 'dak process-unchecked' is already running.") + + ################################################################################ if __name__ == '__main__':