test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
cmsCodeRulesChecker Namespace Reference

Functions

def omitLine
 
def printOut
 
def runRules
 
def splitPaths
 

Variables

string __author__ = "Aurelija"
 
string __date__ = "$2010-07-14 16.48.55$"
 
list arg = sys.argv[i]
 
tuple argvLen = len(sys.argv)
 
 checkPath = checkPath
 
 configuration = Configuration
 
 createPickle = False
 
 createTxt = False
 
tuple cwd = os.getcwd()
 
 goodParameters = True
 
 help = False
 
 html = False
 
int i = 1
 
 picklePath = picklePath
 
 printResult = False
 
tuple result = runRules(ruleNumbers, checkPath)
 
 ruleNumbers = RULES
 
 RULES = rulesNames
 
 rules = False
 
 txtPath = txtPath
 

Function Documentation

def cmsCodeRulesChecker.omitLine (   lines,
  line,
  regEx = None 
)

Definition at line 104 of file cmsCodeRulesChecker.py.

Referenced by runRules().

105 def omitLine(lines, line, regEx=None):
106  fileLines = lines
107  if re.match('^\d+$',line):
108  xline = int(line)-1
109  try:
110  if (not regEx) or (re.search(regEx,fileLines[xline].strip())):
111  fileLines[xline] = ''
112  except IndexError:
113  pass
114  else:
115  for i,lineData in enumerate(fileLines):
116  if re.match(line,str(i)):
117  lineData = lineData.strip()
118  if (not regEx) or (re.search(regEx,lineData)):
119  fileLines[i] = ''
120  return fileLines
def cmsCodeRulesChecker.printOut (   listOfResult,
  filePath = None 
)

Definition at line 121 of file cmsCodeRulesChecker.py.

122 def printOut(listOfResult, filePath = None):
123  file = None
124  try:
125  for rule, result in listOfResult:
126  if filePath:
127  file = open('%s/cmsCodeRule%s.txt'%(filePath, rule), 'w')
128  for path, lineNumbers in result:
129  file.write('%s\n'%path)
130  file.write('%s\n'%str(lineNumbers))
131  file.close()
132  else:
133  if not result or result == -1:
134  print 'No results for rule %s'%rule
135  else:
136  print 'Rule %s:' %rule
137  for path, lineNumbers in result:
138  print path
139  print lineNumbers
140  except TypeError:
141  print "Error: wrong type of parameter in function printOut"
def cmsCodeRulesChecker.runRules (   ruleNumberList,
  directory 
)

Definition at line 32 of file cmsCodeRulesChecker.py.

References keyFinder.finds(), filesFinder.getFilePathsFromWalk(), join(), omitLine(), and splitPaths().

32 
33 def runRules(ruleNumberList, directory):
34 
35  result = []
36  osWalk = []
37 
38  for rule in ruleNumberList:
39  if str(rule) not in RULES:
40  print 'Error: wrong rule parameter. There is no such rule: "'+rule+'"\n\n' + rulesDescription
41  print '\nWrite -h for help'
42  return -1
43 
44  for rule in configuration.keys():
45  configuration[rule]['filter'] = re.compile(configuration[rule]['filter'])
46 
47  osWalk.extend(os.walk(directory))
48 
49  exceptPathsForEachRule = []
50  for path in exceptPaths:
51  exceptPathsForEachRule.append(join(checkPath, path))
52 
53  for ruleNr in ruleNumberList:
54  files = []
55  rule = str(ruleNr)
56  rule = configuration[ruleNr]
57 
58  filesToMatch = rule['filesToMatch']
59  exceptRuleLines = []
60  exceptRulePaths = []
61  for path in rule['exceptPaths']:
62  try:
63  file, line = path.split(":",1)
64  xline = line
65  xdata = None
66  try:
67  xline, xdata = line.split(":",1)
68  if not xline: xline = '.*'
69  except ValueError:
70  pass
71  exceptRuleLines.append((pathToRegEx(file), xline,xdata))
72  except ValueError:
73  exceptRulePaths.append(pathToRegEx(path))
74  for fileType in filesToMatch:
75  fileList = getFilePathsFromWalk(osWalk, fileType, exceptPathsForEachRule)
76 # ------------------------------------------------------------------------------
77  for path in exceptRulePaths:
78  xFileList = []
79  for file in fileList:
80  xFile = file.replace(join(checkPath, ""), "")
81  if not re.match(path, xFile):
82  xFileList.append(file)
83  fileList = xFileList
84 # ------------------------------------------------------------------------------
85  filesLinesList = fileList
86  if rule['skip']:
87  for skipper in rule['skip']:
88  filesLinesList = skipper(filesLinesList)
89  else:
90  for i,xFile in enumerate(filesLinesList):
91  filesLinesList[i]=((xFile,open(xFile).readlines()))
92 # ------------------------------------------------------------------------------
93  for Nr, fileLine in enumerate(exceptRuleLines):
94  regEx, line, lineEx = fileLine
95  for index, file in enumerate(fileList):
96  xFile = file.replace(join(checkPath, ""), "")
97  if re.match(regEx, xFile):
98  filesLinesList[index] = (filesLinesList[index][0], omitLine(filesLinesList[index][1], line,lineEx))
99  files.extend(filesLinesList)
100 # ------------------------------------------------------------------------------
101  listRule = finds(files, rule['filter'], rule['exceptFilter'])
102  result.append((ruleNr, splitPaths(listRule, checkPath)))
103  return result
def getFilePathsFromWalk
Definition: filesFinder.py:8
def finds
Definition: keyFinder.py:7
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def cmsCodeRulesChecker.splitPaths (   listRule,
  pathHead 
)

Definition at line 23 of file cmsCodeRulesChecker.py.

Referenced by runRules().

23 
24 def splitPaths(listRule, pathHead):
25  try:
26  for i in range(len(listRule)):
27  path, linesNumbers = listRule[i]
28  listRule[i] = (path.replace(pathHead, '', 1), linesNumbers)
29  except TypeError:
30  print "Error: given wrong type of parameter in function splitPaths."
31  return listRule

Variable Documentation

string cmsCodeRulesChecker.__author__ = "Aurelija"

Definition at line 3 of file cmsCodeRulesChecker.py.

string cmsCodeRulesChecker.__date__ = "$2010-07-14 16.48.55$"

Definition at line 4 of file cmsCodeRulesChecker.py.

list cmsCodeRulesChecker.arg = sys.argv[i]

Definition at line 159 of file cmsCodeRulesChecker.py.

tuple cmsCodeRulesChecker.argvLen = len(sys.argv)

Definition at line 153 of file cmsCodeRulesChecker.py.

list cmsCodeRulesChecker.checkPath = checkPath

Definition at line 19 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.configuration = Configuration

Definition at line 17 of file cmsCodeRulesChecker.py.

Referenced by JsonOutputProducer.output_filename_base(), and JsonOutputProducer.write().

cmsCodeRulesChecker.createPickle = False

Definition at line 146 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.createTxt = False

Definition at line 147 of file cmsCodeRulesChecker.py.

tuple cmsCodeRulesChecker.cwd = os.getcwd()

Definition at line 144 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.goodParameters = True

Definition at line 152 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.help = False

Definition at line 149 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.html = False

Definition at line 148 of file cmsCodeRulesChecker.py.

Referenced by FWDialogBuilder.addHtml().

int cmsCodeRulesChecker.i = 1

Definition at line 157 of file cmsCodeRulesChecker.py.

list cmsCodeRulesChecker.picklePath = picklePath

Definition at line 20 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.printResult = False

Definition at line 154 of file cmsCodeRulesChecker.py.

tuple cmsCodeRulesChecker.result = runRules(ruleNumbers, checkPath)

Definition at line 218 of file cmsCodeRulesChecker.py.

list cmsCodeRulesChecker.ruleNumbers = RULES

Definition at line 155 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.RULES = rulesNames

Definition at line 18 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.rules = False

Definition at line 150 of file cmsCodeRulesChecker.py.

Referenced by edm::FileLocator.applyRules(), edm::EmbeddedRootSource.dropUnwantedBranches_(), and edm::FileLocator.init().

list cmsCodeRulesChecker.txtPath = txtPath

Definition at line 21 of file cmsCodeRulesChecker.py.