]> err.no Git - dak/commitdiff
Cope with missing variables
authorMark Hymers <mhy@debian.org>
Fri, 29 Jul 2011 12:30:32 +0000 (13:30 +0100)
committerMark Hymers <mhy@debian.org>
Fri, 29 Jul 2011 12:30:32 +0000 (13:30 +0100)
Signed-off-by: Mark Hymers <mhy@debian.org>
dak/update_db.py

index 2147524956b823de7ff11dc972e63aec69f7971e..62f0889b8abe93713851731ff0051e1f742c3161 100755 (executable)
@@ -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.")