CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
results_db.py
Go to the documentation of this file.
1 try:
2  import cx_Oracle
3 except ImportError, e:
4  print "Cannot import cx_Oracle:", e
5 import common_db
6 
7 def printRun( row ):
8  print '============================================================='
9  print 'run=%s date=[%s] test=%s'%(row[0],row[1],row[2])
10  print 'cand=[%s on %s]'%(row[3],row[4])
11 
12 def printResult( row ):
13  print '-------------------------------------------------------------'
14  print 'ref=[%s on %s]'%(row[1],row[2])
15 
16 def printStepResult( row ):
17  step=row[0]
18  code = row[1]
19  check = 'v'
20  marker = ' '
21  if (code!=0):
22  marker = ' <----ERROR'
23  check = 'x'
24  if (step==None):
25  step='setting up'
26  print '%s [%s]=%d %s'%(check,step,code,marker)
27 
28 
29 class ResultsDB:
30  def __init__(self, connect):
31  self.conn = connect
32 
33  def create( self ):
34  curs = self.conn.cursor()
35  sqlstr = "CREATE TABLE RUN_HEADER (RID NUMBER, RDATE DATE, LABEL VARCHAR2(20), "
36  sqlstr += "T_RELEASE VARCHAR2(50), T_ARCH VARCHAR2(30), LOG CLOB "
37  sqlstr += "CONSTRAINT PK_ID0 PRIMARY KEY(RID))"
38  curs.prepare(sqlstr)
39  curs.execute(sqlstr)
40  sqlstr = "CREATE TABLE RUN_RESULT (ID NUMBER, RID NUMBER, R_RELEASE VARCHAR(50), R_ARCH VARCHAR2(30) "
41  sqlstr += "CONSTRAINT PK_ID PRIMARY KEY(ID))"
42  curs.prepare(sqlstr)
43  curs.execute(sqlstr)
44  sqlstr = "CREATE TABLE RUN_STEP_RESULT (ID NUMBER, STEP_LABEL VARCHAR(100), STATUS NUMBER)"
45  curs.prepare(sqlstr)
46  curs.execute(sqlstr)
47  sqlstr = "CREATE SEQUENCE RUN_ID_SEQ INCREMENT BY 1 START WITH 1"
48  curs.prepare(sqlstr)
49  curs.execute(sqlstr)
50  sqlstr = "CREATE SEQUENCE RES_ID_SEQ INCREMENT BY 1 START WITH 1"
51  curs.prepare(sqlstr)
52  curs.execute(sqlstr)
53  self.conn.commit()
54  print 'RESULTS DATABASE CREATED'
55 
56  def drop( self ):
57  curs = self.conn.cursor()
58  sqlstr = "DROP TABLE RUN_HEADER"
59  curs.prepare(sqlstr)
60  curs.execute(sqlstr)
61  sqlstr = "DROP TABLE RUN_RESULT"
62  curs.prepare(sqlstr)
63  curs.execute(sqlstr)
64  sqlstr = "DROP TABLE RUN_STEP_RESULT"
65  curs.prepare(sqlstr)
66  curs.execute(sqlstr)
67  sqlstr = "DROP SEQUENCE RES_ID_SEQ"
68  curs.prepare(sqlstr)
69  curs.execute(sqlstr)
70  self.conn.commit()
71  print 'RESULT DATABASE DROPPED'
72 
73  def read( self ):
74  curs = self.conn.cursor()
75  sqlstr = "SELECT RID, TO_CHAR(RDATE, 'DD.MM.YYYY HH24:MI:SS'), LABEL, T_RELEASE, T_ARCH "
76  sqlstr +="FROM RUN_HEADER ORDER BY RID"
77  curs.prepare(sqlstr)
78  curs.execute(sqlstr)
79  for row in curs:
80  printRun( row )
81  self.readRun( row[0] )
82 
83  def readRun( self, rid ):
84  curs = self.conn.cursor()
85  sqlstr = "SELECT ID, R_RELEASE, R_ARCH "
86  sqlstr +="FROM RUN_RESULT WHERE RID=:rids ORDER BY ID"
87  curs.prepare(sqlstr)
88  curs.execute(sqlstr, rids=rid)
89  for row in curs:
90  printResult( row )
91  self.readResults(row[0])
92 
93  def readResults(self, id):
94  curs = self.conn.cursor()
95  sqlstr = "SELECT STEP_LABEL, STATUS FROM RUN_STEP_RESULT WHERE ID = :ids"
96  curs.prepare(sqlstr)
97  curs.execute(sqlstr, ids = id)
98  self.conn.commit()
99  for row in curs:
100  printStepResult( row )
101 
102  def readSelection( self, runId, label, trel, tarch, full ):
103  curs = self.conn.cursor()
104  sqlstr = "SELECT RID, TO_CHAR(RDATE, 'DD.MM.YYYY HH24:MI:SS'), LABEL, T_RELEASE, T_ARCH, LOG "
105  sqlstr +="FROM RUN_HEADER "
106  putAnd = False
107  if( runId != None ):
108  sqlstr += "WHERE RID="+runId
109  putAnd = True
110  if( label != None ):
111  if( putAnd == True ):
112  sqlstr += " AND "
113  else:
114  sqlstr += "WHERE "
115  sqlstr += "LABEL='"+label+"'"
116  putAnd = True
117  if( trel != None ):
118  if( putAnd == True ):
119  sqlstr += " AND "
120  else:
121  sqlstr += "WHERE "
122  sqlstr += "T_RELEASE='"+trel+"'"
123  putAnd = True
124  if( tarch != None ):
125  if( putAnd == True ):
126  sqlstr += " AND "
127  else:
128  sqlstr += "WHERE "
129  sqlstr += "T_ARCH='"+tarch+"'"
130  putAnd = True
131  sqlstr += " ORDER BY RID"
132  print sqlstr
133  curs.prepare(sqlstr)
134  curs.execute(sqlstr)
135  for row in curs:
136  print '###########'
137  print row[0]
138  printRun( row )
139  self.readRun( row[0] )
140  if( full == True ):
141  if ( row[8]!=None ):
142  print row[8].read()
143 
144  def deleteRun( self,rid ):
145  curs = self.conn.cursor()
146  sqlstr = "SELECT ID FROM RUN_RESULT WHERE RID = :rids"
147  curs.prepare(sqlstr)
148  curs.execute(sqlstr, rids=rid)
149  for row in curs:
150  self.deleteResultSteps( row[0] )
151  sqlstr = "DELETE FROM RUN_RESULT WHERE RID = :rids"
152  curs.prepare(sqlstr)
153  curs.execute(sqlstr, rids=rid)
154  sqlstr = "DELETE FROM RUN_HEADER WHERE RID = :rids"
155  curs.prepare(sqlstr)
156  curs.execute(sqlstr, rids=rid)
157  self.conn.commit()
158 
159  def deleteResultSteps( self, id ):
160  curs = self.conn.cursor()
161  sqlstr = "DELETE FROM RUN_STEP_RESULT WHERE ID=:ids"
162  curs.prepare(sqlstr)
163  curs.execute(sqlstr, ids=id)
164 
165  def writeResult(self, runID, timeStamp, match, resTags):
166  curs = self.conn.cursor()
167  sqlstr = "SELECT RID FROM RUN_HEADER WHERE RID = :rid"
168  curs.prepare(sqlstr)
169  curs.execute(sqlstr, rid = runID)
170  foundRun = False
171  for row in curs:
172  foundRun = True
173  if( foundRun == False ):
174  sqlstr = "INSERT INTO RUN_HEADER(RID, RDATE, LABEL, T_RELEASE, T_ARCH) VALUES (:rid, :ts, :labl, :trel, :tarc)"
175  curs.prepare(sqlstr)
176  curs.execute(sqlstr, rid = runID, ts=timeStamp, labl=match[0], trel = match[1], tarc = match[2])
177  id = self.getNewResId()
178  sqlstr = "INSERT INTO RUN_RESULT(ID, RID, R_RELEASE, R_ARCH)"
179  sqlstr +="VALUES(:ids, :rid, :rrel, :rarc)"
180  curs.prepare(sqlstr)
181  curs.execute(sqlstr, ids=id, rid = runID, rrel = match[3], rarc = match[4])
182  self.conn.commit()
183  for i in range(5, len(match)):
184  if resTags[i-5] != "%NONE":
185  self.writeStepResult(id, resTags[i-5], match[i])
186 
187  def writeStepResult(self, id, step_label, status):
188  curs = self.conn.cursor()
189  sqlstr = "INSERT INTO RUN_STEP_RESULT(ID, STEP_LABEL, STATUS)"
190  sqlstr +="VALUES(:ids, :labl, :stat)"
191  curs.prepare(sqlstr)
192  curs.execute(sqlstr, ids=id, labl=step_label, stat = status)
193  self.conn.commit()
194 
195  def addResultLog(self, runID, logStr):
196  curs = self.conn.cursor()
197  sqlstr = "UPDATE RUN_HEADER SET LOG = :lstr WHERE RID = :rid"
198  curs.prepare(sqlstr)
199  curs.execute(sqlstr, lstr = logStr, rid=runID)
200  self.conn.commit()
201 
202  def checkResult( self, runID ):
203  curs = self.conn.cursor()
204  sqlstr = "SELECT ID FROM RUN_RESULT WHERE RID=:rid"
205  curs.prepare(sqlstr)
206  curs.execute(sqlstr, rid=runID)
207  for row in curs:
208  innercur = self.conn.cursor()
209  isqlstr = "SELECT STATUS FROM RUN_STEP_RESULT WHERE ID= :ids"
210  innercur.prepare(isqlstr)
211  innercur.execute(isqlstr, ids=row[0])
212  for irow in innercur:
213  if irow[0] != 0:
214  return False
215  return True
216 
217  def getNewResId( self ):
218  curs = self.conn.cursor()
219  sqlstr = "SELECT RES_ID_SEQ.NextVal FROM DUAL"
220  curs.prepare(sqlstr)
221  curs.execute(sqlstr)
222  for row in curs:
223  return row[0]
224 
225  def getNewRunId( self ):
226  curs = self.conn.cursor()
227  sqlstr = "SELECT RUN_ID_SEQ.NextVal FROM DUAL"
228  curs.prepare(sqlstr)
229  curs.execute(sqlstr)
230  for row in curs:
231  return row[0]
232 
233  def getDate( self ):
234  curs = self.conn.cursor()
235  sqlstr = "SELECT SYSTIMESTAMP AS \"NOW\" FROM DUAL"
236  curs.prepare(sqlstr)
237  curs.execute(sqlstr)
238  for row in curs:
239  return row[0]
240 
def printRun
Definition: results_db.py:7
def printStepResult
Definition: results_db.py:16
if(dp >Float(M_PI)) dp-
def printResult
Definition: results_db.py:12