4 __date__ =
"$2010-07-14 16.48.55$"
6 from os.path
import join, isdir
10 from Utilities.ReleaseScripts.cmsCodeRules.keyFinder
import finds
11 from Utilities.ReleaseScripts.cmsCodeRules.filesFinder
import getFilePathsFromWalk
12 from Utilities.ReleaseScripts.cmsCodeRules.pickleFileCreater
import createPickleFile
13 from Utilities.ReleaseScripts.cmsCodeRules.config
import Configuration, rulesNames, rulesDescription, helpMsg, checkPath, picklePath, txtPath, exceptPaths
14 from Utilities.ReleaseScripts.cmsCodeRules.pathToRegEx
import pathToRegEx
15 from Utilities.ReleaseScripts.cmsCodeRules.showPage
import run
17 configuration = Configuration
20 picklePath = picklePath
25 for i
in range(len(listRule)):
26 path, linesNumbers = listRule[i]
27 listRule[i] = (path.replace(pathHead,
'', 1), linesNumbers)
29 print "Error: given wrong type of parameter in function splitPaths."
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'
43 for rule
in configuration.keys():
44 configuration[rule][
'filter'] = re.compile(configuration[rule][
'filter'])
46 osWalk.extend(os.walk(directory))
48 exceptPathsForEachRule = []
49 for path
in exceptPaths:
50 exceptPathsForEachRule.append(
join(checkPath, path))
52 for ruleNr
in ruleNumberList:
55 rule = configuration[ruleNr]
57 filesToMatch = rule[
'filesToMatch']
60 for path
in rule[
'exceptPaths']:
62 file, line = path.split(
":",1)
66 xline, xdata = line.split(
":",1)
67 if not xline: xline =
'.*'
70 exceptRuleLines.append((
pathToRegEx(file), xline,xdata))
73 for fileType
in filesToMatch:
76 for path
in exceptRulePaths:
79 xFile = file.replace(
join(checkPath,
""),
"")
80 if not re.match(path, xFile):
81 xFileList.append(file)
84 filesLinesList = fileList
86 for skipper
in rule[
'skip']:
87 filesLinesList = skipper(filesLinesList)
89 for i,xFile
in enumerate(filesLinesList):
90 filesLinesList[i]=((xFile,open(xFile).readlines()))
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)
100 listRule =
finds(files, rule[
'filter'], rule[
'exceptFilter'])
101 result.append((ruleNr,
splitPaths(listRule, checkPath)))
106 if re.match(
'^\d+$',line):
109 if (
not regEx)
or (re.search(regEx,fileLines[xline].strip())):
110 fileLines[xline] =
''
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)):
124 for rule, result
in listOfResult:
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))
132 if not result
or result == -1:
133 print 'No results for rule %s'%rule
135 print 'Rule %s:' %rule
136 for path, lineNumbers
in result:
140 print "Error: wrong type of parameter in function printOut"
142 if __name__ ==
"__main__":
152 goodParameters =
True
153 argvLen = len(sys.argv)
158 while (i != argvLen):
167 ruleNumbers = sys.argv[i].
split(
',')
169 goodParameters =
False
170 print 'Error: missing rule parameters. Write -h for help'
175 checkPath = sys.argv[i]
176 if not isdir(checkPath):
177 goodParameters =
False
178 print 'Error: wrong directory "%s"' %checkPath
181 goodParameters =
False
182 print 'Error: missing rule parameters. Write -h for help'
186 if i+1 < argvLen
and sys.argv[i+1][0] !=
'-':
188 picklePath = sys.argv[i]
189 if not isdir(picklePath):
190 goodParameters =
False
191 print 'Error: wrong directory "%s"' %picklePath
195 if i+1 < argvLen
and sys.argv[i+1][0] !=
'-':
197 txtPath = sys.argv[i]
198 if not isdir(txtPath):
199 goodParameters =
False
200 print 'Error: wrong directory "%s"' %txtPath
202 elif (arg ==
'-html'):
208 goodParameters =
False
209 print 'Error: there is no parameter like "%s". Write -h for help' %arg
213 if goodParameters ==
True:
215 if argvLen == 2
and help ==
True:
221 if argvLen == 1
or printResult
or (createPickle ==
False and createTxt ==
False):
225 for rule, ruleResult
in result:
230 run(picklePath, picklePath, picklePath)
static std::string join(char **cmd)