CMS 3D CMS Logo

keyFinder.py
Go to the documentation of this file.
1 from builtins import range
2 __author__="Aurelija"
3 __date__ ="$Jul 12, 2010 10:08:20 AM$"
4 
5 import re
6 
7 #fileList is list of files paths or could be a tuple of (path, [fileLines])
8 def finds(fileList, regularExpression, exceptRegEx = []):
9  info = []
10  lines = []
11 
12  for i in range(len(fileList)):
13  if type(fileList[0]).__name__ != 'tuple':
14  file = fileList[i]
15  lines = find(fileList[i], regularExpression, exceptRegEx)
16  else:
17  file = fileList[i][0]
18  lines = find(fileList[i][1], regularExpression, exceptRegEx)
19 
20  if lines:
21  info.append((file, lines))
22 
23  return info
24 
25 #file is the file path or the list of file lines
26 #exceptRegEx is the list of regular expressions that says to skip line if one of these regEx matches
27 def find(file, regularExpression, exceptRegEx = []):
28  lines = []
29 
30  if type(file).__name__ != 'list':
31  fileLines = open(file).readlines()
32  else: fileLines = file
33  for i in range(len(fileLines)):
34  matchException = False
35  if re.search(regularExpression, fileLines[i]) != None:
36  for regEx in exceptRegEx:
37  if re.search(regEx, fileLines[i]) != None:
38  matchException = True
39  break
40  if not matchException:
41  lines.append(i+1)
42  return lines
43 
def find(file, regularExpression, exceptRegEx=[])
Definition: keyFinder.py:27
def finds(fileList, regularExpression, exceptRegEx=[])
Definition: keyFinder.py:8