CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
web_results_display.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/authentication.xml"
14 #end
15 
16 def extractLogin(login):
17  pattern = re.compile(r'value="([^"]+)')
18  matching = pattern.search(login)
19  version = 0
20  if matching:
21  g = matching.groups()
22  return g[0]
23 def getLogin(auth, connStr):
24  pfile = open(auth, "r")
25  plist = pfile.readlines()
26  for i in range (0, len(plist)):
27  if string.find(plist[i], '<connection name="'+connStr+'">') != -1:
28  PASSWORD = extractLogin(plist[i+2])
29  return (PASSWORD)
30 
32  coralConnStr, USERNAME, PASSWORD, AUTH_PATH = getDBConnectionParams()
33  conn_string = str(USERNAME+"/"+PASSWORD+"@"+DATABASE)
34  conn = cx_Oracle.connect(conn_string)
35  return conn
36 
38  os.environ['TNS_ADMIN'] = "/afs/cern.ch/project/oracle/admin"
39  coralConnStr = "oracle://"+DATABASE+"/"+USERNAME+""
40  PASSWORD = getLogin(AUTH_PATH, coralConnStr)
41  return (coralConnStr,USERNAME,PASSWORD,AUTH_PATH)
42 
44  def __init__(self, connect):
45  self.conn = connect
46 
47  def resultHeaders(self, label):
48  curs = self.conn.cursor()
49  sqlstr = "SELECT RID, TO_CHAR(RDATE, 'DD.MM.YYYY HH24:MI:SS'), LABEL, T_RELEASE, T_ARCH "
50  sqlstr +="FROM RUN_HEADER WHERE LABEL = :labl ORDER BY RID DESC"
51  curs.prepare(sqlstr)
52  curs.execute(sqlstr, labl = label)
53  result = curs.fetchall()
54  return result
55 
56  def labels( self ):
57  curs = self.conn.cursor()
58  sqlstr = "SELECT DISTINCT LABEL FROM RUN_HEADER"
59  curs.prepare(sqlstr)
60  curs.execute(sqlstr)
61  return curs
62 
63  def runResults( self, rid ):
64  curs = self.conn.cursor()
65  sqlstr = "SELECT ID, R_RELEASE, R_ARCH FROM RUN_RESULT WHERE RID = :ids ORDER BY R_RELEASE"
66  curs.prepare(sqlstr)
67  curs.execute(sqlstr, ids=rid)
68  result = curs.fetchall()
69  return result
70 
71  def stepResults( self, id ):
72  curs = self.conn.cursor()
73  sqlstr = "SELECT ID, STATUS, STEP_LABEL FROM RUN_STEP_RESULT WHERE ID= :ids"
74  curs.prepare(sqlstr)
75  curs.execute(sqlstr, ids=id)
76  result = curs.fetchall()
77  count = len(result)
78  return result, count
79 
80  def releasesHeaders( self, label, release="", arch=""):
81  curs = self.conn.cursor()
82  if(release != "" and arch != ""):
83  sqlstr = "SELECT RID, TO_CHAR(RDATE, 'DD.MM.YYYY HH24:MI:SS'), LABEL, T_RELEASE, T_ARCH FROM RUN_HEADER WHERE T_RELEASE = :rel AND T_ARCH = :arc AND LABEL = :labl ORDER BY RID DESC"
84  curs.prepare(sqlstr)
85  curs.execute(sqlstr, rel=release, arc=arch, labl=label)
86  elif(release != ""):
87  sqlstr = "SELECT RID, TO_CHAR(RDATE, 'DD.MM.YYYY HH24:MI:SS'), LABEL, T_RELEASE, T_ARCH FROM RUN_HEADER WHERE T_RELEASE = :rel AND LABEL = :labl ORDER BY RID DESC"
88  curs.prepare(sqlstr)
89  curs.execute(sqlstr, rel=release, labl=label)
90  elif(arch != ""):
91  sqlstr = "SELECT RID, TO_CHAR(RDATE, 'DD.MM.YYYY HH24:MI:SS'), LABEL, T_RELEASE, T_ARCH FROM RUN_HEADER WHERE T_ARCH = :arc AND LABEL = :labl ORDER BY RID DESC"
92  curs.prepare(sqlstr)
93  curs.execute(sqlstr, arc=arch, labl=label)
94  result = curs.fetchall()
95  return result
96 
97  def readLogStatus( self, label, runID):
98  curs = self.conn.cursor()
99  sqlstr = "SELECT LOG FROM RUN_HEADER WHERE RID = :rid"
100  curs.prepare(sqlstr)
101  curs.execute(sqlstr, rid = runID)
102  for row in curs:
103  return row[0].read()
104 
105 def GetRunResults( rid ):
106  conn = createDBConnection()
107  resDb = WebResultsDisplay( conn )
108  stat = resDb.runResults( rid )
109  conn.close
110  return stat
111 
112 def GetResultsList( runID ):
113  conn = createDBConnection()
114  resDb = WebResultsDisplay( conn )
115  resList = resDb.stepResults( runID )
116  conn.close
117  return resList
118 
119 def GetLabels():
120  conn = createDBConnection()
121  resDb = WebResultsDisplay( conn )
122  webLabels = resDb.labels()
123  conn.close
124  return webLabels
125 
126 def GetReleasesHeaders( label, release="", arch="" ):
127  conn = createDBConnection()
128  resDb = WebResultsDisplay( conn )
129  relHeaders = resDb.releasesHeaders( label, release, arch)
130  conn.close
131  return relHeaders
132 
133 def GetResultHeaders( label ):
134  conn = createDBConnection()
135  resDb = WebResultsDisplay( conn )
136  statusHeaders = resDb.resultHeaders( label )
137  conn.close
138  return statusHeaders
139 
140 def GetReadLogStatus( label, runId ):
141  conn = createDBConnection()
142  resDb = WebResultsDisplay( conn )
143  logStatus = resDb.readLogStatus( label, runId )
144  conn.close
145  return logStatus
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31