CMS 3D CMS Logo

showPage.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import print_function
4 from builtins import range
5 __author__="Aurelija"
6 __date__ ="$2010-08-12 10.50.40$"
7 
8 from optparse import OptionParser
9 from shutil import rmtree
10 from os.path import join
11 import os.path
12 
13 from Utilities.ReleaseScripts.cmsCodeRules.Formatter import SimpleHTMLFormatter
14 from Utilities.ReleaseScripts.cmsCodeRules.pickleFileParser import readPicFiles
15 from Utilities.ReleaseScripts.cmsCodeRules.config import rulesNames, ordering, Configuration, htmlPath, checkPath
16 
17 # helper function:
18 
19 def getIB(pathIn):
20 
21  ib = None
22  wkDay = None
23  dirs = os.path.abspath(pathIn).split('/')
24  for item in dirs:
25  if item.startswith('CMSSW_'):
26  ib = item
27  break
28 
29  if ib:
30  import datetime
31  fooYr, m, d, hr = ib.split('-')
32  wkDay = datetime.date( int(fooYr[-4:]), int(m), int(d) ).strftime("%a")
33 
34  return ib, wkDay
35 
37 
38  def __init__(self, formatter, pickleDir, logsDir, htmlDir):
39 
40  self.formatter = formatter
41 
42  self.configuration = Configuration
43 
44  self.logsDir = logsDir
45  self.pickleDir = pickleDir
46  self.htmlDir = htmlDir
47  return
48 
49  # --------------------------------------------------------------------------------
50 
51  def showResults(self):
52 
53  ib, wkDay = getIB(checkPath)
54 
55  rulesResults = readPicFiles(self.pickleDir, True)
56  createLogFiles(rulesResults, self.logsDir, ib)
57 
58  self.formatter.writeAnchor(ref='top')
59  self.formatter.writeH2("CMSSW code rules violation for "+ib)
60 
61  self.formatter.startTable([20,20,20,20,50],
62 ['Rule','Packages', 'Files','Sum of violations','Description'], id =
63 'descriptionTable', tableAttr='border="0" cellspacing="5" cellpadding="5"')
64 
65  for ruleName in rulesNames:
66  try:
67  ruleRes = rulesResults[ruleName]
68  totalViolations = 0
69  totalFiles = 0
70  for package, packageResult in ruleRes:
71  totalFiles += len(packageResult)
72  for file, lines in packageResult:
73  totalViolations += len(lines)
74  self.formatter.writeRow([ruleName,str(len(ruleRes)),
75 str(totalFiles), str(totalViolations),
76 self.configuration[ruleName]['description']])
77  except KeyError:
78  self.formatter.writeRow([ruleName,'-', '-', '-',
79 self.configuration[ruleName]['description']])
80  self.formatter.endTable()
81 
82  msg = """
83 <p>
84 Click on the package links to get list of files
85 </p>
86 
87 """
88  self.formatter.write(msg)
89 
90  colFmt = [ 50 ]
91  colLab = ['Package']
92 
93  rules = ordering
94  for rule in rules:
95  colFmt.append(20)
96  colLab.append('Rule %s' %rule)
97 
98  self.formatter.startTable(colFmt, colLab, id = 'mainTable', cls='display', tableAttr='border="0" cellspacing="5" cellpadding="5"')
99 
100  packages = []
101  table = []
102  tableRow = len(colLab)*tuple('')
103  ruleNr = 0
104  for ruleName in rules:
105  try:
106  ruleResult = rulesResults[ruleName]
107  for package, packageResult in ruleResult:
108  try:
109  index = packages.index(package)
110  tableRow = table[index] +(str(len(packageResult)),)
111  table[index] = tableRow
112  except ValueError:
113  packages.append(package)
114  tableRow = ('<a href="logs/'+package+'/log.html"/>'+package,) + tuple('-' for i in range(ruleNr)) + (str(len(packageResult)),) #
115  table.append(tableRow)
116  addDash(table, ruleNr)
117  except KeyError:
118  addDash(table, ruleNr)
119  ruleNr += 1
120 
121  for row in table:
122  self.formatter.writeRow(row)
123 
124  self.formatter.endTable()
125 
126  return
127 
128 def addDash(table, ruleNr):
129  for index, tableRow in enumerate(table):
130  if len(tableRow)-1 != ruleNr + 1:
131  table[index] = table[index] + ('-',)
132 
133 def numberConverter(number):
134  number = str(number)
135  length = len(number)
136  if length < 3:
137  number = (3-length)*str(0) + number
138  return number
139 
140 def createLogFiles(rulesResult, logsDir, ib):
141  logDir = join(logsDir,"logs")
142  if os.path.exists(logDir):
143  rmtree(logDir)
144  for ruleName in rulesNames:
145  try:
146  ruleResult = rulesResult[ruleName]
147  for package, packageResult in ruleResult:
148  logsDir = join(logDir, package)
149  if not os.path.exists(logsDir): os.makedirs(logsDir, 0o755)
150  file = open(join(logsDir, "log.html"), 'a')
151  file.write('Rule %s'%ruleName)
152  file.write("<br/>")
153  for path, lineNumbers in packageResult:
154  for line in lineNumbers:
155  directory = join(package, path)
156  file.write('<a href="https://cmssdt.cern.ch/lxr/source/%s?v=%s#%s">%s:%s</a>\n'%(directory, ib, numberConverter(line), directory, line))
157  file.write("<br/>")
158  file.write('\n')
159  file.close()
160  except KeyError:
161  pass
162 
163 def run(pickleDir, logsDir, htmlDir):
164  aoSorting = ""
165  for i in range(len(ordering)):
166  aoSorting += "["+ str(i+1) +",'desc'],"
167  aoSorting += "[0, 'asc']"
168 
169  style = """
170 
171  <style type="text/css" title="currentStyle">
172  @import "/SDT/html/jsExt/dataTables/media/css/demo_table.css";
173  </style>
174 
175  <script type="text/javascript" src="/SDT/html/jsExt/dataTables/media/js/jquery.js"></script>
176  <script type="text/javascript" src="/SDT/html/jsExt/dataTables/media/js/jquery.dataTables.js"></script>
177 
178  <script type="text/javascript" charset="utf-8">
179  /* Initialise the table with the required column sorting data types */
180  $(document).ready(function() {
181  $('#mainTable').dataTable( {
182  "oLanguage": {
183  "sLengthMenu": "Display _MENU_ records per page",
184  "sInfoEmpty": "Showing 0 to 0 of 0 records"
185  },
186  "aaSorting": [%s]
187  } );
188  $('#descriptionTable').dataTable( {
189  "aaSorting": [[0, 'asc']],
190  "bPaginate": false,
191  "bLengthChange": false,
192  "bFilter": false,
193  "bSort": false,
194  "bInfo": false,
195  "bAutoWidth": false
196  });
197  $('#descriptionTable thead th').css({'border-bottom': '1px solid black'});
198  } );
199  </script>
200  """%(aoSorting)
201 
202  fmtr = SimpleHTMLFormatter(title="CMSSW integration builds", style=style, outFile = open(join(htmlDir,"cmsCRPage.html"), "w"))
203 
204  bv = BuildViewer(fmtr, pickleDir, logsDir, htmlDir)
205  bv.showResults()
206 
207 def main():
208 
209  parser = OptionParser()
210  parser.add_option("-l", "-L", dest="logDir", help = "creates log files to DIRECTORY", metavar = "DIRECTORY", default = os.getcwd())
211  parser.add_option("-p", "-P", dest="pickleDir", help = "reads pickle files from DIRECTORY", metavar = "DIRECTORY", default = os.getcwd())
212  parser.add_option("-c", "-C", dest="htmlDir", help = "creates cmsCRPage.html file to DIRECTORY", metavar = "DIRECTORY", default = os.getcwd())
213  (options, args) = parser.parse_args()
214 
215  logsDir = options.logDir
216  pickleDir = options.pickleDir
217  htmlDir = options.htmlDir
218 
219  if not os.path.exists(logsDir):
220  print("Error: wrong directory %s"%logsDir)
221  return
222 
223  if not os.path.exists(pickleDir):
224  print("Error: wrong directory %s"%pickleDir)
225  return
226 
227  if not os.path.exists(htmlDir):
228  print("Error: wrong directory %s"%htmlDir)
229  return
230 
231  run(pickleDir, logsDir, htmlDir)
232 
233  return
234 
235 if __name__ == "__main__":
236  main()
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
showPage.BuildViewer.htmlDir
htmlDir
Definition: showPage.py:46
showPage.createLogFiles
def createLogFiles(rulesResult, logsDir, ib)
Definition: showPage.py:140
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
showPage.BuildViewer.__init__
def __init__(self, formatter, pickleDir, logsDir, htmlDir)
Definition: showPage.py:38
showPage.numberConverter
def numberConverter(number)
Definition: showPage.py:133
showPage.BuildViewer.pickleDir
pickleDir
Definition: showPage.py:45
submitPVValidationJobs.split
def split(sequence, size)
Definition: submitPVValidationJobs.py:352
str
#define str(s)
Definition: TestProcessor.cc:51
showPage.BuildViewer
Definition: showPage.py:36
showPage.BuildViewer.formatter
formatter
Definition: showPage.py:40
showPage.main
def main()
Definition: showPage.py:207
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
createfilelist.int
int
Definition: createfilelist.py:10
showPage.BuildViewer.logsDir
logsDir
Definition: showPage.py:44
showPage.BuildViewer.showResults
def showResults(self)
Definition: showPage.py:51
main
Definition: main.py:1
showPage.run
def run(pickleDir, logsDir, htmlDir)
Definition: showPage.py:163
writeEcalDQMStatus.write
write
Definition: writeEcalDQMStatus.py:48
pickleFileParser.readPicFiles
def readPicFiles(directory, toSplit=False)
Definition: pickleFileParser.py:16
showPage.BuildViewer.configuration
configuration
Definition: showPage.py:42
showPage.getIB
def getIB(pathIn)
Definition: showPage.py:19
showPage.addDash
def addDash(table, ruleNr)
Definition: showPage.py:128