From: Mark Hymers Date: Fri, 29 Jul 2011 12:30:32 +0000 (+0100) Subject: Cope with missing variables X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17d6f9dcd28e2698466f4f3396ecf8262aeba283;p=dak Cope with missing variables Signed-off-by: Mark Hymers --- 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.")