CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
common_db.py
Go to the documentation of this file.
1 import re
2 import os
3 import string
4 try:
5  import cx_Oracle
6 except ImportError, e:
7  print "Cannot import cx_Oracle:", e
8 
9 #global varables
10 DATABASE = "cms_orcoff_prep"
11 USERNAME = "CMS_COND_REGRESSION"
12 #USERNAME = "CMS_COND_WEB"
13 AUTH_PATH = "/afs/cern.ch/cms/DB/conddb/test/"
14 AUTH_FILE = "authentication.xml"
15 #end
16 
17 def extractLogin(login):
18  pattern = re.compile(r'value="([^"]+)')
19  matching = pattern.search(login)
20  version = 0
21  if matching:
22  g = matching.groups()
23  return g[0]
24 def getLogin(auth, connStr):
25  pfile = open(auth, "r")
26  plist = pfile.readlines()
27  for i in range (0, len(plist)):
28  if string.find(plist[i], '<connection name="'+connStr+'">') != -1:
29  PASSWORD = extractLogin(plist[i+2])
30  return (PASSWORD)
31 
33  coralConnStr, USERNAME, PASSWORD, AUTH_PATH = getDBConnectionParams()
34  conn_string = str(USERNAME+"/"+PASSWORD+"@"+DATABASE)
35  conn = cx_Oracle.connect(conn_string)
36  return conn
37 
39  os.environ['TNS_ADMIN'] = "/afs/cern.ch/project/oracle/admin"
40  coralConnStr = "oracle://"+DATABASE+"/"+USERNAME+""
41  authFilePath = os.path.join(AUTH_PATH,AUTH_FILE)
42  PASSWORD = getLogin(authFilePath, coralConnStr)
43  return (coralConnStr,USERNAME,PASSWORD,AUTH_PATH)
44 
def getLogin
Definition: common_db.py:24
def getDBConnectionParams
Definition: common_db.py:38
def createDBConnection
Definition: common_db.py:32
def extractLogin
Definition: common_db.py:17