CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 106 of file cmsCodeRulesChecker.py.

References str, and digitizers_cfi.strip.

Referenced by runRules().

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

Definition at line 123 of file cmsCodeRulesChecker.py.

References print(), and str.

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

Definition at line 34 of file cmsCodeRulesChecker.py.

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

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

Definition at line 25 of file cmsCodeRulesChecker.py.

References print(), and sistrip::SpyUtilities.range().

Referenced by runRules().

25 
26 def splitPaths(listRule, pathHead):
27  try:
28  for i in range(len(listRule)):
29  path, linesNumbers = listRule[i]
30  listRule[i] = (path.replace(pathHead, '', 1), linesNumbers)
31  except TypeError:
32  print("Error: given wrong type of parameter in function splitPaths.")
33  return listRule
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

Variable Documentation

string cmsCodeRulesChecker.__author__ = "Aurelija"

Definition at line 5 of file cmsCodeRulesChecker.py.

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

Definition at line 6 of file cmsCodeRulesChecker.py.

list cmsCodeRulesChecker.arg = sys.argv[i]

Definition at line 161 of file cmsCodeRulesChecker.py.

tuple cmsCodeRulesChecker.argvLen = len(sys.argv)

Definition at line 155 of file cmsCodeRulesChecker.py.

list cmsCodeRulesChecker.checkPath = checkPath

Definition at line 21 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.configuration = Configuration

Definition at line 19 of file cmsCodeRulesChecker.py.

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

cmsCodeRulesChecker.createPickle = False

Definition at line 148 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.createTxt = False

Definition at line 149 of file cmsCodeRulesChecker.py.

tuple cmsCodeRulesChecker.cwd = os.getcwd()

Definition at line 146 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.goodParameters = True

Definition at line 154 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.help = False

Definition at line 151 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.html = False

Definition at line 150 of file cmsCodeRulesChecker.py.

Referenced by FWDialogBuilder.addHtml().

int cmsCodeRulesChecker.i = 1

Definition at line 159 of file cmsCodeRulesChecker.py.

list cmsCodeRulesChecker.picklePath = picklePath

Definition at line 22 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.printResult = False

Definition at line 156 of file cmsCodeRulesChecker.py.

tuple cmsCodeRulesChecker.result = runRules(ruleNumbers, checkPath)

Definition at line 220 of file cmsCodeRulesChecker.py.

list cmsCodeRulesChecker.ruleNumbers = RULES

Definition at line 157 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.RULES = rulesNames

Definition at line 20 of file cmsCodeRulesChecker.py.

cmsCodeRulesChecker.rules = False

Definition at line 152 of file cmsCodeRulesChecker.py.

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

list cmsCodeRulesChecker.txtPath = txtPath

Definition at line 23 of file cmsCodeRulesChecker.py.