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