CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CondCore/RegressionTest/python/webApp.py

Go to the documentation of this file.
00001 import os
00002 import cherrypy
00003 import testRegression
00004 current_dir = os.path.dirname(os.path.abspath(__file__)) # for conf
00005 
00006 class Server:
00007         def ShowTable(self, curs, label):
00008                 res1 = testRegression.WebStatus(curs[0], label)
00009                 res2, stCount = testRegression.WebResultsList(curs[0], label)
00010                 #print stCount
00011                 Code ="""
00012                         <table id="header" bgcolor="#D8D8D8">
00013                                         <tr>
00014                                         <td colspan = "2">Test Sequence:
00015                                         <b>"""+str(curs[2])+"""</b>&nbsp&nbsp&nbsp&nbsp
00016                                         RunID:
00017                                         """+str(curs[0])+"""&nbsp&nbsp&nbsp&nbsp
00018                                         Time:
00019                                         """+str(curs[1])+"""
00020                                         </td>
00021                                         <tr>
00022                                         <td>
00023                                         Candidate:
00024                                         <b>"""+str(curs[3])+"""</b>&nbsp&nbsp&nbsp&nbsp
00025                                         Architecture:
00026                                         <b>"""+str(curs[4])+"""</b>
00027                                         </td>
00028                                         <td class="links"><a href="showLogs?runID="""+str(curs[0])+"""&label="""+label+"""">&gt&gt Logfile</a></td>
00029                                         </tr>
00030                         </table>
00031                         <table id="status">
00032                                         <!--
00033                                         <th>RunID</th>
00034                                         <td>"""+str(curs[0])+"""</td>
00035                                         <th>Time</th>
00036                                         <td>"""+str(curs[1])+"""</td>
00037                                         <th>Test Sequence</th>
00038                                         <td>"""+str(curs[2])+"""</td>
00039                                         </tr>
00040                                         <tr>
00041                                         <th>Candidate release</th>
00042                                         <td>"""+str(curs[3])+"""</td>
00043                                         <th>Candidate architecture</th>
00044                                         <td>"""+str(curs[4])+"""</td>
00045                                         <th colspan = "2" class="links"><a href="showLogs?runID="""+str(curs[0])+"""&label="""+label+"""">Logfile</a></th>
00046                                         </tr>
00047                                         -->
00048                         """
00049                 Code +="""
00050                                         <tr>
00051                                                 <!--<th rowspan="2" colspan = "2">Reference releases</th>-->
00052                                                 <th>Reference release</th>
00053                                                 <th>Reference architecture</th>
00054                                         
00055                 """
00056                 for i in range (0, stCount):
00057                         Code += """<th>"""+str(res2[i][2])+"""</th>
00058                         """
00059                 Code +="""</tr>"""
00060                 for rows in res1:
00061                         Code += """<tr>
00062                                         <td align="left" >"""+str(rows[1])+"""</td>
00063                                         <td>"""+str(rows[2])+"""</td>
00064                         """
00065                         for i in range (0, stCount):
00066                                 if(res2[i][1] == 0):
00067                                         Code +="""<td align="center" bgcolor ="#A7C942"><b>OK</b></td>
00068                                         """
00069                                 else:
00070                                         Code +="""<td align="center" bgcolor ="#FF0000"><b>Failure</b></td>
00071                                         """
00072                         Code += """</tr></tr>
00073                         """
00074                 Code += """</table><hr>
00075                 """
00076                 Code += """
00077                 </body>
00078                 </html>
00079                 """
00080                 return Code
00081         def index(self, **args):
00082                 print "Arguments :"
00083                 print args
00084                 selectRel = False
00085                 if 'reset' in args.keys():
00086                         cherrypy.session.clear()
00087                 it = 0
00088                 for row in testRegression.WebLabels():
00089                         if not 'label' in cherrypy.session.keys():
00090                                 cherrypy.session['label'] = row[0]
00091                         break
00092                 if 'submit' in args.keys():
00093                         cherrypy.session['submit'] = args['submit']
00094                         cherrypy.session['label'] = args['label']
00095                         if 'release' in args.keys() and args['release'] != '':
00096                                 cherrypy.session['release'] = args['release']
00097                         if 'release' in cherrypy.session.keys() and args['release'] != cherrypy.session['release']:
00098                                 cherrypy.session['release'] = args['release']
00099                         if 'arch' in args.keys() and args['arch'] != '':
00100                                 cherrypy.session['arch'] = args['arch']
00101                         if 'arch' in cherrypy.session.keys() and args['arch'] != cherrypy.session['arch']:
00102                                 cherrypy.session['arch'] = args['arch']
00103                         if 'count' in args.keys() and args['count'].isdigit():
00104                                 cherrypy.session['count'] = args['count']
00105                         print "Session :"       
00106                         print cherrypy.session
00107                 if 'arch' in cherrypy.session.keys() and cherrypy.session['arch'] != ''  or 'release' in cherrypy.session.keys() and cherrypy.session['release'] != '':
00108                         selectRel = True
00109                 if 'count' in cherrypy.session.keys() and cherrypy.session['count'].isdigit():
00110                                 stCount = int(cherrypy.session['count'])
00111                 else:
00112                         stCount = 2;
00113                 
00114                 htmlCode = """
00115                 <html>
00116                         <META HTTP-EQUIV="REFRESH" CONTENT="60">
00117                         <head>
00118                                 <style type="text/css">
00119                                         button,
00120                                         input,
00121                                         select,
00122                                         textarea {
00123                                           font-size: 100%;
00124                                           margin: 0;
00125                                           vertical-align: baseline;
00126                                           *vertical-align: middle;
00127                                         }
00128                                         button, input {
00129                                           line-height: normal;
00130                                           *overflow: visible;
00131                                         }
00132                                         button::-moz-focus-inner, input::-moz-focus-inner {
00133                                           border: 0;
00134                                           padding: 0;
00135                                         }
00136                                         select {
00137                                         }
00138                                         button,
00139                                         input[type="submit"] {
00140                                           cursor: pointer;
00141                                           -webkit-appearance: button;
00142                                         }
00143                                         input[type="search"] {
00144                                           -webkit-appearance: textfield;
00145                                           -webkit-box-sizing: content-box;
00146                                           -moz-box-sizing: content-box;
00147                                           box-sizing: content-box;
00148                                         }
00149                                         a {
00150                                           color: #bfbfbf;
00151                                           text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
00152                                           text-decoration:none;
00153                                         }
00154                                         a:hover, .active a {
00155                                           color: #ffffff;
00156                                           text-decoration: none;
00157                                         }
00158                                         .links {
00159                                           background-color: #222;
00160                                           background-color: #222222;
00161                                           background-repeat: repeat-x;
00162                                           background-image: -khtml-gradient(linear, left top, left bottom, from(#333333), to(#222222));
00163                                           background-image: -moz-linear-gradient(top, #333333, #222222);
00164                                           background-image: -ms-linear-gradient(top, #333333, #222222);
00165                                           background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #333333), color-stop(100%, #222222));
00166                                           background-image: -webkit-linear-gradient(top, #333333, #222222);
00167                                           background-image: -o-linear-gradient(top, #333333, #222222);
00168                                           background-image: linear-gradient(top, #333333, #222222);
00169                                           filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#333333', endColorstr='#222222', GradientType=0);
00170                                           -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), inset 0 -1px 0 rgba(0, 0, 0, 0.1);
00171                                           -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), inset 0 -1px 0 rgba(0, 0, 0, 0.1);
00172                                           box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), inset 0 -1px 0 rgba(0, 0, 0, 0.1);
00173                                         }
00174                                         #status, #header
00175                                         {
00176                                                 font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
00177                                                 width:100%;
00178                                                 border-collapse:collapse;
00179                                         }
00180                                         #header td 
00181                                         {
00182                                                 font-size:1em;
00183                                                 border:1px solid #67645B;
00184                                                 padding:3px 7px 2px 7px;
00185                                                 text-align:left;
00186                                         }
00187                                         #status td
00188                                         {
00189                                                 font-size:1em;
00190                                                 border:1px solid #67645B;
00191                                                 padding:3px 7px 2px 7px;
00192                                         }
00193                                         #status th 
00194                                         {
00195                                                 border:1px solid #67645B;
00196                                                 font-size:1.1em;
00197                                                 text-align:center;
00198                                                 padding-top:5px;
00199                                                 padding-bottom:4px;
00200                                                 background-color:#ECAE12;
00201                                                 color:#ffffff;
00202                                         }
00203                                         #controls
00204                                         {
00205                                                 font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
00206                                                 width:100%;
00207                                                 border-collapse:collapse;
00208                                         }
00209                                         #controls td 
00210                                         {
00211                                                 font-size:1.1em;
00212                                                 border:none;
00213                                                 padding-top:5px;
00214                                                 padding-bottom:4px;
00215                                                 text-align:left;
00216                                                 background-color:#393333;
00217                                                 color:#ffffff;
00218                                                 
00219                                         }
00220                                         .topbar {
00221                                           height: 40px;
00222                                           position: fixed;
00223                                           top: 0;
00224                                           left: 0;
00225                                           right: 0;
00226                                           z-index: 10000;
00227                                           overflow: visible;
00228                                           color: #ffffff;
00229                                           width: 100%;
00230                                         }
00231                                         .topbar form {
00232                                           float: left;
00233                                           margin: 5px 0 0 0;
00234                                           position: relative;
00235                                           filter: alpha(opacity=100);
00236                                           -khtml-opacity: 1;
00237                                           -moz-opacity: 1;
00238                                           opacity: 1;
00239                                         }
00240                                         .topbar input {
00241                                           background-color: #444;
00242                                           background-color: rgba(255, 255, 255, 0.3);
00243                                           font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
00244                                           font-size: 80%;
00245                                           font-weight: 13px;
00246                                           line-height: 1;
00247                                           padding: 4px 9px;
00248                                           color: #fff;
00249                                           color: rgba(255, 255, 255, 0.75);
00250                                           border: 1px solid #111;
00251                                           -webkit-border-radius: 4px;
00252                                           -moz-border-radius: 4px;
00253                                           border-radius: 4px;
00254                                           -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1), 0 1px 0px rgba(255, 255, 255, 0.25);
00255                                           -moz-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1), 0 1px 0px rgba(255, 255, 255, 0.25);
00256                                           box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1), 0 1px 0px rgba(255, 255, 255, 0.25);
00257                                           -webkit-transition: none;
00258                                           -moz-transition: none;
00259                                           transition: none;
00260                                         }
00261                                         .topbar input:-moz-placeholder {
00262                                           color: #e6e6e6;
00263                                         }
00264                                         .topbar input::-webkit-input-placeholder {
00265                                           color: #e6e6e6;
00266                                         }
00267                                         .topbar input:hover {
00268                                           background-color: #bfbfbf;
00269                                           background-color: rgba(255, 255, 255, 0.5);
00270                                           color: #fff;
00271                                         }
00272                                         .topbar input:focus, .topbar input.focused {
00273                                           outline: none;
00274                                           background-color: #fff;
00275                                           color: #404040;
00276                                           text-shadow: 0 1px 0 #fff;
00277                                           border: 0;
00278                                           padding: 5px 10px;
00279                                           -webkit-box-shadow: 0 0 3px rgba(0, 0, 0, 0.15);
00280                                           -moz-box-shadow: 0 0 3px rgba(0, 0, 0, 0.15);
00281                                           box-shadow: 0 0 3px rgba(0, 0, 0, 0.15);
00282                                         }
00283                                         .topbar-inner, .topbar .fill {
00284                                           background-color: #222;
00285                                           background-color: #222222;
00286                                           background-repeat: repeat-x;
00287                                           background-image: -khtml-gradient(linear, left top, left bottom, from(#333333), to(#222222));
00288                                           background-image: -moz-linear-gradient(top, #333333, #222222);
00289                                           background-image: -ms-linear-gradient(top, #333333, #222222);
00290                                           background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #333333), color-stop(100%, #222222));
00291                                           background-image: -webkit-linear-gradient(top, #333333, #222222);
00292                                           background-image: -o-linear-gradient(top, #333333, #222222);
00293                                           background-image: linear-gradient(top, #333333, #222222);
00294                                           filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#333333', endColorstr='#222222', GradientType=0);
00295                                           -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), inset 0 -1px 0 rgba(0, 0, 0, 0.1);
00296                                           -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), inset 0 -1px 0 rgba(0, 0, 0, 0.1);
00297                                           box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), inset 0 -1px 0 rgba(0, 0, 0, 0.1);
00298                                         }
00299                                         .buts {
00300                                         float: right;
00301                                         }
00302                                 </style>
00303                         </head>
00304                         <body>
00305                                 <form method="post" action="index" >
00306                                                 <div class="topbar">
00307                                                         <div class="fill">
00308                                                                 <div class="container">
00309                                                                         <select name = "label">"""
00310                 curs = testRegression.WebLabels()
00311                 for row in curs:
00312                         if str(row[0]) == cherrypy.session['label']:
00313                                 htmlCode += """<option value = """+str(row[0])+""" selected = "selected">"""+str(row[0])+"""</option>
00314                                 """
00315                         else:
00316                                 htmlCode += """<option value = """+str(row[0])+""">"""+str(row[0])+"""</option>
00317                                 """
00318                 htmlCode+="""</select>
00319                         """
00320                 if 'release' in cherrypy.session.keys():
00321                         htmlCode += """Candidate Release:<input type="text" name="release" size="30" maxlength="50" value=\""""+str(cherrypy.session['release'])+""""\"/>
00322                         """
00323                 else:
00324                         htmlCode += """Candidate Release:<input type="text" name="release" size="30" maxlength="50"/>
00325                         """
00326                 if 'arch' in cherrypy.session.keys():
00327                         htmlCode += """Candidate Architecture:<input type="text" name="arch" size="15" maxlength="30" value=\""""+cherrypy.session['arch']+""""\"/>
00328                         """
00329                 else:
00330                         htmlCode += """Candidate Architecture:<input type="text" name="arch" size="15" maxlength="30" />
00331                         """
00332                 if 'count' in cherrypy.session.keys():
00333                         htmlCode += """Number of results:<input type="text" name="count" size="1" maxlength="4" value=\""""+cherrypy.session['count']+""""\"/>
00334                         """
00335                 else:
00336                         htmlCode += """Number of results:<input type="text" name="count" size="4" maxlength="4" />
00337                         """
00338                 htmlCode +="""<div class = "buts"><input type="submit" name="submit" value="Refresh"/>
00339                                                         <input type="submit" name="reset" value="Reset"/>
00340                                                 </div></div></div></div>
00341                                                 <br>
00342                                 </form>
00343                         """
00344                 if(selectRel == True):
00345                         if 'arch' in cherrypy.session.keys() and 'release' in cherrypy.session.keys():
00346                                 DBdata = testRegression.WebReleasesHeaders(cherrypy.session['label'], cherrypy.session['release'], cherrypy.session['arch'])
00347                         elif 'release' in cherrypy.session.keys():
00348                                 DBdata = testRegression.WebReleasesHeaders(cherrypy.session['label'], cherrypy.session['release'])
00349                         elif 'arch' in cherrypy.session.keys():
00350                                 DBdata = testRegression.WebReleasesHeaders(cherrypy.session['label'], "", cherrypy.session['arch'])
00351                         counter =0
00352                         for data in DBdata:
00353                                 counter += 1
00354                                 if stCount != 0:
00355                                         htmlCode += self.ShowTable(data, cherrypy.session['label'])
00356                                         stCount = stCount -1
00357                         if (counter == 0):
00358                                 htmlCode += """<h3> No entries found </h3>"""
00359                 else:
00360                         DBdata = testRegression.WebStatusHeaders(cherrypy.session['label'])
00361                         for data in DBdata:
00362                                 if stCount != 0:
00363                                         htmlCode += self.ShowTable(data, cherrypy.session['label'])
00364                                         stCount = stCount -1
00365                 return htmlCode
00366 
00367         index.exposed = True
00368         def showLogs(self, **args):
00369                 runID = int(args['runID'])
00370                 label = args['label']
00371 
00372                 logInfo = "<html><head></head><body><pre>\n"
00373                 logInfo += testRegression.WebReadLogStatusDB(label, runID)
00374                 logInfo += '\n</pre></body></html>'
00375                 return logInfo
00376                                 
00377         showLogs.exposed = True
00378 import os.path
00379 
00380 if __name__ == '__main__':
00381         cherrypy.config.update({'server.socket_port': 8083,
00382                                                         'server.thread_pool' : 10,
00383                                                         'server.socket_host': '0.0.0.0',
00384                                                         "server.environment" : "production"})
00385         cherrypy.quickstart(Server(), config='config.conf')
00386