Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:32:00

0001 from builtins import range
0002 __author__="Aurelija"
0003 __date__ ="$2010-07-20 11.52.22$"
0004 
0005 import sys
0006 
0007 def filterFiles(fileList):
0008     files = []
0009 
0010     for file in fileList:
0011         files.append((file, filterFile(file)))
0012     return files
0013 
0014 
0015 def filterFile(file):
0016     lines = open(file).readlines()
0017     lines = filterMultilineComment(lines, '"""', '"""')
0018     lines = filterMultilineComment(lines, "'''", "'''")
0019     lines = filterMultilineComment(lines, '<!--', '-->')
0020     lines = filterOneLineComment(lines, "#")
0021     return lines
0022 
0023 
0024 def filterOneLineComment(lines, commentStart):
0025     for i in range(len(lines)):
0026         index = lines[i].find(commentStart)
0027         if index != -1:
0028             lines[i] = lines[i].replace(lines[i][index:], '\n')
0029     return lines
0030 
0031 
0032 def filterMultilineComment(lines, commentStart, commentEnd):
0033     i = 0
0034     tlines = len(lines)
0035     while (i < tlines):
0036         startIndex = lines[i].find(commentStart)
0037         startLine = i
0038         while((startIndex != -1) and (i < tlines)):
0039             endIndex = lines[i].find(commentEnd)
0040             if endIndex != -1:
0041                 if startLine == i:
0042                     lines[i] = lines[i].replace(lines[i][startIndex:endIndex+3], '', 1)
0043                 else:
0044                     lines[i] = lines[i].replace(lines[i][:endIndex+3], '')
0045                 startIndex = lines[i].find(commentStart)
0046                 startLine = i
0047             else:
0048                 if startLine == i:
0049                     lines[i] = lines[i].replace(lines[i][startIndex:], '\n', 1)
0050                 else:
0051                     lines[i] = lines[i].replace(lines[i][:], '\n')
0052                 i += 1
0053         i += 1
0054     return lines