CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/Utilities/ReleaseScripts/python/cmsCodeRules/keyFinder.py

Go to the documentation of this file.
00001 __author__="Aurelija"
00002 __date__ ="$Jul 12, 2010 10:08:20 AM$"
00003 
00004 import re
00005 
00006 #fileList is list of files paths or could be a tuple of (path, [fileLines])
00007 def finds(fileList, regularExpression, exceptRegEx = []):
00008     info = []
00009     lines = []
00010 
00011     for i in range(len(fileList)):
00012         if type(fileList[0]).__name__ != 'tuple':
00013             file = fileList[i]
00014             lines = find(fileList[i], regularExpression, exceptRegEx)
00015         else:
00016             file = fileList[i][0]
00017             lines = find(fileList[i][1], regularExpression, exceptRegEx)
00018             
00019         if lines:
00020             info.append((file, lines))
00021             
00022     return info
00023 
00024 #file is the file path or the list of file lines
00025 #exceptRegEx is the list of regular expressions that says to skip line if one of these regEx matches
00026 def find(file, regularExpression, exceptRegEx = []):
00027     lines = []
00028 
00029     if type(file).__name__ != 'list':
00030         fileLines = open(file).readlines()
00031     else: fileLines = file
00032     for i in range(len(fileLines)):
00033         matchException = False
00034         if re.search(regularExpression, fileLines[i]) != None:
00035             for regEx in exceptRegEx:
00036                 if re.search(regEx, fileLines[i]) != None:
00037                     matchException = True
00038                     break
00039             if not matchException:
00040                 lines.append(i+1)
00041     return lines
00042