3 from __future__
import print_function
4 from builtins
import range
6 __date__ =
"$2010-07-14 16.48.55$" 8 from os.path
import join, isdir
12 from Utilities.ReleaseScripts.cmsCodeRules.keyFinder
import finds
13 from Utilities.ReleaseScripts.cmsCodeRules.filesFinder
import getFilePathsFromWalk
14 from Utilities.ReleaseScripts.cmsCodeRules.pickleFileCreater
import createPickleFile
15 from Utilities.ReleaseScripts.cmsCodeRules.config
import Configuration, rulesNames, rulesDescription, helpMsg, checkPath, picklePath, txtPath, exceptPaths
16 from Utilities.ReleaseScripts.cmsCodeRules.pathToRegEx
import pathToRegEx
17 from Utilities.ReleaseScripts.cmsCodeRules.showPage
import run
19 configuration = Configuration
22 picklePath = picklePath
27 for i
in range(len(listRule)):
28 path, linesNumbers = listRule[i]
29 listRule[i] = (path.replace(pathHead,
'', 1), linesNumbers)
31 print(
"Error: given wrong type of parameter in function splitPaths.")
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')
45 for rule
in configuration.keys():
46 configuration[rule][
'filter'] = re.compile(configuration[rule][
'filter'])
48 osWalk.extend(os.walk(directory))
50 exceptPathsForEachRule = []
51 for path
in exceptPaths:
52 exceptPathsForEachRule.append(
join(checkPath, path))
54 for ruleNr
in ruleNumberList:
57 rule = configuration[ruleNr]
59 filesToMatch = rule[
'filesToMatch']
62 for path
in rule[
'exceptPaths']:
64 file, line = path.split(
":",1)
68 xline, xdata = line.split(
":",1)
69 if not xline: xline =
'.*' 72 exceptRuleLines.append((
pathToRegEx(file), xline,xdata))
75 for fileType
in filesToMatch:
78 for path
in exceptRulePaths:
81 xFile = file.replace(
join(checkPath,
""),
"")
82 if not re.match(path, xFile):
83 xFileList.append(file)
86 filesLinesList = fileList
88 for skipper
in rule[
'skip']:
89 filesLinesList = skipper(filesLinesList)
91 for i,xFile
in enumerate(filesLinesList):
92 filesLinesList[i]=((xFile,open(xFile).readlines()))
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)
102 listRule =
finds(files, rule[
'filter'], rule[
'exceptFilter'])
103 result.append((ruleNr,
splitPaths(listRule, checkPath)))
108 if re.match(
'^\d+$',line):
111 if (
not regEx)
or (re.search(regEx,fileLines[xline].
strip())):
112 fileLines[xline] =
'' 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)):
126 for rule, result
in listOfResult:
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))
134 if not result
or result == -1:
135 print(
'No results for rule %s'%rule)
137 print(
'Rule %s:' %rule)
138 for path, lineNumbers
in result:
142 print(
"Error: wrong type of parameter in function printOut")
144 if __name__ ==
"__main__":
154 goodParameters =
True 155 argvLen = len(sys.argv)
160 while (i != argvLen):
169 ruleNumbers = sys.argv[i].
split(
',')
171 goodParameters =
False 172 print(
'Error: missing rule parameters. Write -h for help')
177 checkPath = sys.argv[i]
178 if not isdir(checkPath):
179 goodParameters =
False 180 print(
'Error: wrong directory "%s"' %checkPath)
183 goodParameters =
False 184 print(
'Error: missing rule parameters. Write -h for help')
188 if i+1 < argvLen
and sys.argv[i+1][0] !=
'-':
190 picklePath = sys.argv[i]
191 if not isdir(picklePath):
192 goodParameters =
False 193 print(
'Error: wrong directory "%s"' %picklePath)
197 if i+1 < argvLen
and sys.argv[i+1][0] !=
'-':
199 txtPath = sys.argv[i]
200 if not isdir(txtPath):
201 goodParameters =
False 202 print(
'Error: wrong directory "%s"' %txtPath)
204 elif (arg ==
'-html'):
210 goodParameters =
False 211 print(
'Error: there is no parameter like "%s". Write -h for help' %arg)
215 if goodParameters ==
True:
217 if argvLen == 2
and help ==
True:
223 if argvLen == 1
or printResult
or (createPickle ==
False and createTxt ==
False):
227 for rule, ruleResult
in result:
232 run(picklePath, picklePath, picklePath)
def splitPaths(listRule, pathHead)
S & print(S &os, JobReport::InputFile const &f)
def printOut(listOfResult, filePath=None)
def createPickleFile(fileName, listRule, path=os.getcwd())
def omitLine(lines, line, regEx=None)
def getFilePathsFromWalk(osWalkResult, file, exceptPaths=[])
static std::string join(char **cmd)
def finds(fileList, regularExpression, exceptRegEx=[])
def runRules(ruleNumberList, directory)