CMS 3D CMS Logo

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