CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/Utilities/ReleaseScripts/python/commentSkipper/buildFileCommentSkipper.py

Go to the documentation of this file.
00001 __author__="Aurelija"
00002 __date__ ="$2010-07-20 11.52.22$"
00003 
00004 import sys
00005 
00006 def filterFiles(fileList):
00007     files = []
00008 
00009     for file in fileList:
00010         files.append((file, filterFile(file)))
00011     return files
00012 
00013 
00014 def filterFile(file):
00015     lines = open(file).readlines()
00016     lines = filterMultilineComment(lines, '"""', '"""')
00017     lines = filterMultilineComment(lines, "'''", "'''")
00018     lines = filterMultilineComment(lines, '<!--', '-->')
00019     lines = filterOneLineComment(lines, "#")
00020     return lines
00021 
00022 
00023 def filterOneLineComment(lines, commentStart):
00024     for i in range(len(lines)):
00025         index = lines[i].find(commentStart)
00026         if index != -1:
00027             lines[i] = lines[i].replace(lines[i][index:], '\n')
00028     return lines
00029 
00030 
00031 def filterMultilineComment(lines, commentStart, commentEnd):
00032     i = 0
00033     tlines = len(lines)
00034     while (i < tlines):
00035         startIndex = lines[i].find(commentStart)
00036         startLine = i
00037         while((startIndex != -1) and (i < tlines)):
00038             endIndex = lines[i].find(commentEnd)
00039             if endIndex != -1:
00040                 if startLine == i:
00041                     lines[i] = lines[i].replace(lines[i][startIndex:endIndex+3], '', 1)
00042                 else:
00043                     lines[i] = lines[i].replace(lines[i][:endIndex+3], '')
00044                 startIndex = lines[i].find(commentStart)
00045                 startLine = i
00046             else:
00047                 if startLine == i:
00048                     lines[i] = lines[i].replace(lines[i][startIndex:], '\n', 1)
00049                 else:
00050                     lines[i] = lines[i].replace(lines[i][:], '\n')
00051                 i += 1
00052         i += 1
00053     return lines