From: Michael Casadevall Date: Fri, 2 Jan 2009 23:06:39 +0000 (-0500) Subject: Modified update_db.py to handle cases with port/host were non-standard, X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04b294de3910928469880b3b4ee7c4ad7feb4d24;p=dak Modified update_db.py to handle cases with port/host were non-standard, or unspecified in dak.conf (i.e., using default settings) Signed-off-by: Michael Casadevall --- diff --git a/dak/update_db.py b/dak/update_db.py index dc943503..e59a558c 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -100,7 +100,12 @@ Updates dak's database schema to the lastest version. You should disable crontab print "Determining dak database revision ..." try: - self.db = psycopg2.connect("dbname='" + Cnf["DB::Name"] + "' host='" + Cnf["DB::Host"] + "' port='" + str(Cnf["DB::Port"]) + "'") + # Build a connect string + 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"])) + + self.db = psycopg2.connect(connect_str) except: print "FATAL: Failed connect to database" @@ -151,10 +156,10 @@ Updates dak's database schema to the lastest version. You should disable crontab options = Cnf.SubTree("Update-DB::Options") if options["Help"]: - usage() + self.usage() elif arguments: utils.warn("dak update-db takes no arguments.") - usage(exit_code=1) + self.usage(exit_code=1) self.update_db()