CMS 3D CMS Logo

Functions | Variables
cmsCodeRulesChecker Namespace Reference

Functions

def omitLine (lines, line, regEx=None)
 
def printOut (listOfResult, filePath=None)
 
def runRules (ruleNumberList, directory)
 
def splitPaths (listRule, pathHead)
 

Variables

 __author__
 
 __date__
 
 arg
 
 argvLen
 
 checkPath
 
 configuration
 
 createPickle
 
 createTxt
 
 cwd
 
 goodParameters
 
 help
 
 html
 
 i
 
 picklePath
 
 printResult
 
 result
 
 ruleNumbers
 
 RULES
 
 rules
 
 txtPath
 

Function Documentation

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

Definition at line 104 of file cmsCodeRulesChecker.py.

References createfilelist.int, harvestTrackValidationPlots.str, and digi_MixPreMix_cfi.strip.

Referenced by runRules().

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

Definition at line 121 of file cmsCodeRulesChecker.py.

References harvestTrackValidationPlots.str.

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

Definition at line 32 of file cmsCodeRulesChecker.py.

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

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

Definition at line 23 of file cmsCodeRulesChecker.py.

Referenced by runRules().

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

Variable Documentation

cmsCodeRulesChecker.__author__
private

Definition at line 3 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.__date__
private

Definition at line 4 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.arg

Definition at line 159 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.argvLen

Definition at line 153 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.checkPath

Definition at line 19 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.configuration

Definition at line 17 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.createPickle

Definition at line 146 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.createTxt

Definition at line 147 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.cwd

Definition at line 144 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.goodParameters

Definition at line 152 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.help

Definition at line 149 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.html

Definition at line 148 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.i

Definition at line 157 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.picklePath

Definition at line 20 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.printResult

Definition at line 154 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.result

Definition at line 218 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.ruleNumbers

Definition at line 155 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.RULES

Definition at line 18 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.rules
cmsCodeRulesChecker.txtPath

Definition at line 21 of file cmsCodeRulesChecker.py.