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__ ="$Jul 12, 2010 10:08:20 AM$"
0004 
0005 import re
0006 
0007 #fileList is list of files paths or could be a tuple of (path, [fileLines])
0008 def finds(fileList, regularExpression, exceptRegEx = []):
0009     info = []
0010     lines = []
0011 
0012     for i in range(len(fileList)):
0013         if type(fileList[0]).__name__ != 'tuple':
0014             file = fileList[i]
0015             lines = find(fileList[i], regularExpression, exceptRegEx)
0016         else:
0017             file = fileList[i][0]
0018             lines = find(fileList[i][1], regularExpression, exceptRegEx)
0019             
0020         if lines:
0021             info.append((file, lines))
0022             
0023     return info
0024 
0025 #file is the file path or the list of file lines
0026 #exceptRegEx is the list of regular expressions that says to skip line if one of these regEx matches
0027 def find(file, regularExpression, exceptRegEx = []):
0028     lines = []
0029 
0030     if type(file).__name__ != 'list':
0031         fileLines = open(file).readlines()
0032     else: fileLines = file
0033     for i in range(len(fileLines)):
0034         matchException = False
0035         if re.search(regularExpression, fileLines[i]) != None:
0036             for regEx in exceptRegEx:
0037                 if re.search(regEx, fileLines[i]) != None:
0038                     matchException = True
0039                     break
0040             if not matchException:
0041                 lines.append(i+1)
0042     return lines
0043