]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
use cidb only when using master branch, else use cidb_dev
authorHolger Levsen <holger@layer-acht.org>
Tue, 22 Jan 2013 17:46:45 +0000 (18:46 +0100)
committerHolger Levsen <holger@layer-acht.org>
Tue, 22 Jan 2013 17:46:45 +0000 (18:46 +0100)
cidb.py

diff --git a/cidb.py b/cidb.py
index 2238713d092a4e94a873e8caa49888054bb517bc..108f1aa7323dbe03421fcd2f10274e2f8b60214d 100644 (file)
--- a/cidb.py
+++ b/cidb.py
@@ -1,17 +1,34 @@
 #!/usr/bin/python
 
+import subprocess
 import psycopg2
 import psycopg2.extras
+import logging
 
-DB_USER = "cidb"
-DB_PASSWD = "cidb"
-DB_NAME = "cidb"
-DB_HOST = "jenkins"
-DB_PORT = 5432
+# get current git branch
+p = subprocess.Popen(["git", "rev-parse", "--symbolic-full-name",
+    "--abbrev-ref", "HEAD"], stdout=subprocess.PIPE)
+p.wait()
+branch = p.stdout.read().rstrip()
 
+if branch == "master":
+    DB_USER = "cidb"
+    DB_PASSWD = "cidb"
+    DB_NAME = "cidb"
+    DB_HOST = "jenkins"
+    DB_PORT = 5432
+else:
+    DB_USER = "cidb_dev"
+    DB_PASSWD = "cidb_dev"
+    DB_NAME = "cidb_dev"
+    DB_HOST = "jenkins"
+    DB_PORT = 5432
+
+logger = logging.getLogger()
 
 def db_connect():
     """ Connects to the db and returns the Connection object. """
 
+    logger.info("Connecting to database %s" % DB_NAME)
     return psycopg2.connect(database=DB_NAME, user=DB_USER, password=DB_PASSWD,
             host=DB_HOST, port=DB_PORT)