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 106 of file cmsCodeRulesChecker.py.

References createfilelist.int, str, and digitizers_cfi.strip.

Referenced by runRules().

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

Definition at line 123 of file cmsCodeRulesChecker.py.

References edm.print(), and str.

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

Definition at line 34 of file cmsCodeRulesChecker.py.

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

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

Definition at line 25 of file cmsCodeRulesChecker.py.

References edm.print().

Referenced by runRules().

25 def splitPaths(listRule, pathHead):
26  try:
27  for i in range(len(listRule)):
28  path, linesNumbers = listRule[i]
29  listRule[i] = (path.replace(pathHead, '', 1), linesNumbers)
30  except TypeError:
31  print("Error: given wrong type of parameter in function splitPaths.")
32  return listRule
33 
def splitPaths(listRule, pathHead)
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66

Variable Documentation

cmsCodeRulesChecker.__author__
private

Definition at line 5 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.__date__
private

Definition at line 6 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.arg

Definition at line 161 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.argvLen

Definition at line 155 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.checkPath

Definition at line 21 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.configuration

Definition at line 19 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.createPickle

Definition at line 148 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.createTxt

Definition at line 149 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.cwd

Definition at line 146 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.goodParameters

Definition at line 154 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.help

Definition at line 151 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.html

Definition at line 150 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.i

Definition at line 159 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.picklePath

Definition at line 22 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.printResult

Definition at line 156 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.result

Definition at line 220 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.ruleNumbers

Definition at line 157 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.RULES

Definition at line 20 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.rules
cmsCodeRulesChecker.txtPath

Definition at line 23 of file cmsCodeRulesChecker.py.