From 17d6f9dcd28e2698466f4f3396ecf8262aeba283 Mon Sep 17 00:00:00 2001 From: Mark Hymers Date: Fri, 29 Jul 2011 13:30:32 +0100 Subject: [PATCH] Cope with missing variables Signed-off-by: Mark Hymers --- dak/update_db.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/dak/update_db.py b/dak/update_db.py index 21475249..62f0889b 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -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, e: + print "FATAL: Failed connect to database (%s)" % str(e) sys.exit(1) database_revision = int(self.get_db_rev()) @@ -198,8 +200,11 @@ Updates dak's database schema to the lastest version. You should disable crontab self.usage(exit_code=1) try: - 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) + 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, 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.") -- 2.39.5