X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fupdate_db.py;h=b757912177e0dfa8c0baf2c9b5f4ddc61c07f557;hb=27e00376e81d1c37ff327ee0d39670b266418869;hp=77d0097604743c40191da00bf970c11b8b0c90ec;hpb=c757aaa7d63b4508ad353a2339507ed837a8e0a3;p=dak.git diff --git a/dak/update_db.py b/dak/update_db.py index 77d00976..b7579121 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -46,7 +46,7 @@ from daklib.daklog import Logger ################################################################################ Cnf = None -required_database_schema = 49 +required_database_schema = 66 ################################################################################ @@ -119,7 +119,7 @@ Updates dak's database schema to the lastest version. You should disable crontab # Ok, try and find the configuration table print "Determining dak database revision ..." cnf = Config() - logger = Logger(cnf.Cnf, 'update-db') + logger = Logger('update-db') try: # Build a connect string @@ -127,13 +127,15 @@ Updates dak's database schema to the lastest version. You should disable crontab connect_str = "service=%s" % cnf["DB::Service"] else: connect_str = "dbname=%s"% (cnf["DB::Name"]) - if cnf["DB::Host"] != '': connect_str += " host=%s" % (cnf["DB::Host"]) - if cnf["DB::Port"] != '-1': connect_str += " port=%d" % (int(cnf["DB::Port"])) + if cnf.has_key("DB::Host") and cnf["DB::Host"] != '': + connect_str += " host=%s" % (cnf["DB::Host"]) + if cnf.has_key("DB::Port") and cnf["DB::Port"] != '-1': + connect_str += " port=%d" % (int(cnf["DB::Port"])) self.db = psycopg2.connect(connect_str) - except: - print "FATAL: Failed connect to database" + except Exception as e: + print "FATAL: Failed connect to database (%s)" % str(e) sys.exit(1) database_revision = int(self.get_db_rev()) @@ -169,7 +171,7 @@ Updates dak's database schema to the lastest version. You should disable crontab message = "updated database schema from %d to %d" % (database_revision, i+1) print message logger.log([message]) - except DBUpdateError, e: + 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 "The error message received was %s" % (e) @@ -198,9 +200,12 @@ Updates dak's database schema to the lastest version. You should disable crontab self.usage(exit_code=1) 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 os.path.isdir(cnf["Dir::Lock"]): + lock_fd = os.open(os.path.join(cnf["Dir::Lock"], 'dinstall.lock'), os.O_RDWR | os.O_CREAT) + fcntl.lockf(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB) + else: + utils.warn("Lock directory doesn't exist yet - not locking") + except IOError as 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.")