Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-07 22:34:02

0001 #!/usr/bin/env python3
0002 
0003 from __future__ import print_function
0004 from builtins import range
0005 __author__="Aurelija"
0006 __date__ ="$2010-08-12 10.50.40$"
0007 
0008 from optparse import OptionParser
0009 from shutil import rmtree
0010 from os.path import join
0011 import os.path
0012 
0013 from Utilities.ReleaseScripts.cmsCodeRules.Formatter import SimpleHTMLFormatter
0014 from Utilities.ReleaseScripts.cmsCodeRules.pickleFileParser import readPicFiles
0015 from Utilities.ReleaseScripts.cmsCodeRules.config import rulesNames, ordering, Configuration, htmlPath, checkPath
0016 
0017 # helper function:
0018 
0019 def getIB(pathIn):
0020 
0021     ib = None
0022     wkDay = None
0023     dirs = os.path.abspath(pathIn).split('/')
0024     for item in dirs:
0025         if item.startswith('CMSSW_'):
0026             ib = item
0027             break
0028 
0029     if ib:
0030         import datetime
0031         fooYr, m, d, hr = ib.split('-')
0032         wkDay = datetime.date( int(fooYr[-4:]), int(m), int(d) ).strftime("%a")
0033 
0034     return ib, wkDay
0035 
0036 class BuildViewer(object):
0037 
0038     def __init__(self, formatter, pickleDir, logsDir, htmlDir):
0039 
0040         self.formatter = formatter
0041 
0042         self.configuration = Configuration
0043 
0044         self.logsDir = logsDir
0045         self.pickleDir = pickleDir
0046         self.htmlDir = htmlDir
0047         return
0048 
0049     # --------------------------------------------------------------------------------
0050 
0051     def showResults(self):
0052 
0053         ib, wkDay = getIB(checkPath)
0054 
0055         rulesResults = readPicFiles(self.pickleDir, True)
0056         createLogFiles(rulesResults, self.logsDir, ib)
0057 
0058         self.formatter.writeAnchor(ref='top')
0059         self.formatter.writeH2("CMSSW code rules violation for "+ib)
0060 
0061         self.formatter.startTable([20,20,20,20,50], 
0062 ['Rule','Packages', 'Files','Sum of violations','Description'], id =
0063 'descriptionTable', tableAttr='border="0" cellspacing="5" cellpadding="5"')
0064 
0065         for ruleName in rulesNames:
0066             try:
0067                 ruleRes = rulesResults[ruleName]
0068                 totalViolations = 0
0069                 totalFiles = 0
0070                 for package, packageResult in ruleRes:
0071                     totalFiles += len(packageResult)
0072                     for file, lines in packageResult:
0073                         totalViolations += len(lines)
0074                 self.formatter.writeRow([ruleName,str(len(ruleRes)), 
0075 str(totalFiles), str(totalViolations), 
0076 self.configuration[ruleName]['description']])
0077             except KeyError:
0078                 self.formatter.writeRow([ruleName,'-', '-', '-',
0079 self.configuration[ruleName]['description']])
0080         self.formatter.endTable()
0081 
0082         msg = """
0083 <p>
0084 Click on the package links to get list of files
0085 </p>
0086 
0087 """
0088         self.formatter.write(msg)
0089 
0090         colFmt = [   50    ]
0091         colLab = ['Package']
0092 
0093         rules = ordering
0094         for rule in rules:
0095             colFmt.append(20)
0096             colLab.append('Rule %s' %rule)
0097 
0098         self.formatter.startTable(colFmt, colLab, id = 'mainTable', cls='display', tableAttr='border="0" cellspacing="5" cellpadding="5"')
0099 
0100         packages = []
0101         table = []
0102         tableRow = len(colLab)*tuple('')
0103         ruleNr = 0
0104         for ruleName in rules:
0105             try:
0106                 ruleResult = rulesResults[ruleName]
0107                 for package, packageResult in ruleResult:
0108                     try:
0109                         index = packages.index(package)
0110                         tableRow = table[index] +(str(len(packageResult)),)
0111                         table[index] = tableRow
0112                     except ValueError:
0113                         packages.append(package) 
0114                         tableRow = ('<a href="logs/'+package+'/log.html"/>'+package,) + tuple('-' for i in range(ruleNr)) + (str(len(packageResult)),) #
0115                         table.append(tableRow)
0116                 addDash(table, ruleNr)
0117             except KeyError:
0118                 addDash(table, ruleNr)
0119             ruleNr += 1
0120 
0121         for row in table:
0122             self.formatter.writeRow(row)
0123 
0124         self.formatter.endTable()
0125 
0126         return
0127 
0128 def addDash(table, ruleNr):
0129     for index, tableRow in enumerate(table):
0130         if len(tableRow)-1 != ruleNr + 1:
0131             table[index] = table[index] + ('-',)
0132 
0133 def numberConverter(number):
0134     number = str(number)
0135     length = len(number)
0136     if  length < 3:
0137         number = (3-length)*str(0) + number
0138     return number
0139 
0140 def createLogFiles(rulesResult, logsDir, ib):
0141     logDir = join(logsDir,"logs")
0142     if os.path.exists(logDir):
0143         rmtree(logDir)
0144     for ruleName in rulesNames:
0145         try:
0146             ruleResult = rulesResult[ruleName]
0147             for package, packageResult in ruleResult:
0148                 logsDir = join(logDir, package)
0149                 if not os.path.exists(logsDir): os.makedirs(logsDir, 0o755)
0150                 file = open(join(logsDir, "log.html"), 'a')
0151                 file.write('Rule %s'%ruleName)
0152                 file.write("<br/>")
0153                 for path, lineNumbers in packageResult:
0154                     for line in lineNumbers:
0155                         directory = join(package, path)
0156                         file.write('<a href="https://cmssdt.cern.ch/lxr/source/%s?v=%s#%s">%s:%s</a>\n'%(directory, ib, numberConverter(line), directory, line))
0157                         file.write("<br/>")
0158                 file.write('\n')
0159                 file.close()
0160         except KeyError:
0161             pass
0162 
0163 def run(pickleDir, logsDir, htmlDir):
0164     aoSorting = ""
0165     for i in range(len(ordering)):
0166         aoSorting += "["+ str(i+1) +",'desc'],"
0167     aoSorting += "[0, 'asc']"
0168 
0169     style = """
0170 
0171     <style type="text/css" title="currentStyle">
0172        @import "/SDT/html/jsExt/dataTables/media/css/demo_table.css";
0173     </style>
0174 
0175     <script type="text/javascript" src="/SDT/html/jsExt/dataTables/media/js/jquery.js"></script>
0176     <script type="text/javascript" src="/SDT/html/jsExt/dataTables/media/js/jquery.dataTables.js"></script>
0177                         
0178     <script type="text/javascript" charset="utf-8">
0179     /* Initialise the table with the required column sorting data types */
0180     $(document).ready(function() {
0181         $('#mainTable').dataTable( {
0182                         "oLanguage": {
0183                 "sLengthMenu": "Display _MENU_ records per page",
0184                 "sInfoEmpty": "Showing 0 to 0 of 0 records"
0185                 },
0186                         "aaSorting": [%s]
0187             } );
0188                 $('#descriptionTable').dataTable( {
0189                         "aaSorting": [[0, 'asc']],
0190                         "bPaginate": false,
0191             "bLengthChange": false,
0192             "bFilter": false,
0193             "bSort": false,
0194             "bInfo": false,
0195             "bAutoWidth": false
0196                         });
0197                 $('#descriptionTable thead th').css({'border-bottom': '1px solid black'});
0198     } );
0199     </script>
0200     """%(aoSorting)
0201 
0202     fmtr = SimpleHTMLFormatter(title="CMSSW integration builds", style=style, outFile = open(join(htmlDir,"cmsCRPage.html"), "w"))
0203 
0204     bv = BuildViewer(fmtr, pickleDir, logsDir, htmlDir)
0205     bv.showResults()
0206 
0207 def main():
0208 
0209     parser = OptionParser()
0210     parser.add_option("-l", "-L", dest="logDir", help = "creates log files to DIRECTORY", metavar = "DIRECTORY", default = os.getcwd())
0211     parser.add_option("-p", "-P", dest="pickleDir", help = "reads pickle files from DIRECTORY", metavar = "DIRECTORY", default = os.getcwd())
0212     parser.add_option("-c", "-C", dest="htmlDir", help = "creates cmsCRPage.html file to DIRECTORY", metavar = "DIRECTORY", default = os.getcwd())
0213     (options, args) = parser.parse_args()
0214 
0215     logsDir = options.logDir
0216     pickleDir = options.pickleDir
0217     htmlDir = options.htmlDir
0218 
0219     if not os.path.exists(logsDir):
0220         print("Error: wrong directory %s"%logsDir)
0221         return
0222 
0223     if not os.path.exists(pickleDir):
0224         print("Error: wrong directory %s"%pickleDir)
0225         return
0226 
0227     if not os.path.exists(htmlDir):
0228         print("Error: wrong directory %s"%htmlDir)
0229         return
0230 
0231     run(pickleDir, logsDir, htmlDir)
0232 
0233     return
0234 
0235 if __name__ == "__main__":
0236     main()