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

◆ omitLine()

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

Definition at line 106 of file cmsCodeRulesChecker.py.

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 

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

Referenced by runRules().

◆ printOut()

def cmsCodeRulesChecker.printOut (   listOfResult,
  filePath = None 
)

Definition at line 123 of file cmsCodeRulesChecker.py.

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 

References print(), and str.

◆ runRules()

def cmsCodeRulesChecker.runRules (   ruleNumberList,
  directory 
)

Definition at line 34 of file cmsCodeRulesChecker.py.

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 

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

◆ splitPaths()

def cmsCodeRulesChecker.splitPaths (   listRule,
  pathHead 
)

Definition at line 25 of file cmsCodeRulesChecker.py.

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 

References print(), and FastTimerService_cff.range.

Referenced by runRules().

Variable Documentation

◆ __author__

cmsCodeRulesChecker.__author__
private

Definition at line 5 of file cmsCodeRulesChecker.py.

◆ __date__

cmsCodeRulesChecker.__date__
private

Definition at line 6 of file cmsCodeRulesChecker.py.

◆ arg

cmsCodeRulesChecker.arg

Definition at line 161 of file cmsCodeRulesChecker.py.

◆ argvLen

cmsCodeRulesChecker.argvLen

Definition at line 155 of file cmsCodeRulesChecker.py.

◆ checkPath

cmsCodeRulesChecker.checkPath

Definition at line 21 of file cmsCodeRulesChecker.py.

◆ configuration

cmsCodeRulesChecker.configuration

Definition at line 19 of file cmsCodeRulesChecker.py.

◆ createPickle

cmsCodeRulesChecker.createPickle

Definition at line 148 of file cmsCodeRulesChecker.py.

◆ createTxt

cmsCodeRulesChecker.createTxt

Definition at line 149 of file cmsCodeRulesChecker.py.

◆ cwd

cmsCodeRulesChecker.cwd

Definition at line 146 of file cmsCodeRulesChecker.py.

◆ goodParameters

cmsCodeRulesChecker.goodParameters

Definition at line 154 of file cmsCodeRulesChecker.py.

◆ help

cmsCodeRulesChecker.help

Definition at line 151 of file cmsCodeRulesChecker.py.

◆ html

cmsCodeRulesChecker.html

Definition at line 150 of file cmsCodeRulesChecker.py.

◆ i

cmsCodeRulesChecker.i

Definition at line 159 of file cmsCodeRulesChecker.py.

◆ picklePath

cmsCodeRulesChecker.picklePath

Definition at line 22 of file cmsCodeRulesChecker.py.

◆ printResult

cmsCodeRulesChecker.printResult

Definition at line 156 of file cmsCodeRulesChecker.py.

Referenced by sistrip::SpyUtilities.getMajorityHeader().

◆ result

cmsCodeRulesChecker.result

Definition at line 220 of file cmsCodeRulesChecker.py.

◆ ruleNumbers

cmsCodeRulesChecker.ruleNumbers

Definition at line 157 of file cmsCodeRulesChecker.py.

◆ RULES

cmsCodeRulesChecker.RULES

Definition at line 20 of file cmsCodeRulesChecker.py.

◆ rules

cmsCodeRulesChecker.rules

◆ txtPath

cmsCodeRulesChecker.txtPath

Definition at line 23 of file cmsCodeRulesChecker.py.

FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
cmsCodeRulesChecker.runRules
def runRules(ruleNumberList, directory)
Definition: cmsCodeRulesChecker.py:34
cmsCodeRulesChecker.splitPaths
def splitPaths(listRule, pathHead)
Definition: cmsCodeRulesChecker.py:25
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
filesFinder.getFilePathsFromWalk
def getFilePathsFromWalk(osWalkResult, file, exceptPaths=[])
Definition: filesFinder.py:8
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
cmsCodeRulesChecker.omitLine
def omitLine(lines, line, regEx=None)
Definition: cmsCodeRulesChecker.py:106
str
#define str(s)
Definition: TestProcessor.cc:52
cmsCodeRulesChecker.printOut
def printOut(listOfResult, filePath=None)
Definition: cmsCodeRulesChecker.py:123
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
createfilelist.int
int
Definition: createfilelist.py:10
keyFinder.finds
def finds(fileList, regularExpression, exceptRegEx=[])
Definition: keyFinder.py:8
pathToRegEx
Definition: pathToRegEx.py:1