CMS 3D CMS Logo

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