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(
":")
66 for fileType
in filesToMatch:
69 for path
in exceptRulePaths:
72 File = file.replace(
join(checkPath,
""),
"")
73 if not re.match(path, File):
79 for skipper
in rule[
'skip']:
80 filesLinesList = skipper(skipLines)
81 skipLines = filesLinesList
82 if not exceptRuleLines
and not rule[
'skip']:
83 filesLinesList = fileList
85 for Nr, fileLine
in enumerate(exceptRuleLines):
86 regEx, line = fileLine
87 for index, file
in enumerate(fileList):
88 File = file.replace(
join(checkPath,
""),
"")
89 if re.match(regEx, File):
90 if rule[
'skip'] !=
None or Nr > 0:
91 filesLinesList[index] = (filesLinesList[index][0],
omitLine(filesLinesList[index][1], line))
93 filesLinesList.append([file,
omitLine(file, line)])
94 elif rule[
'skip'] ==
None:
95 filesLinesList.append((file, open(file).readlines()))
96 files.extend(filesLinesList)
98 listRule =
finds(files, rule[
'filter'], rule[
'exceptFilter'])
99 result.append((ruleNr,
splitPaths(listRule, checkPath)))
104 if type(file).__name__ !=
'list':
105 fileLines = open(file).readlines()
106 else: fileLines = file
107 fileLines[int(line)-1] =
''
109 print 'File = "' + file +
'" has only ' + str(len(fileLines)) +
' lines. Wrong given line number: ' + str(line)
115 for rule, result
in listOfResult:
117 file = open(
'%s/cmsCodeRule%s.txt'%(filePath, rule),
'w')
118 for path, lineNumbers
in result:
119 file.write(
'%s\n'%path)
120 file.write(
'%s\n'%str(lineNumbers))
123 if not result
or result == -1:
124 print 'No results for rule %s'%rule
126 print 'Rule %s:' %rule
127 for path, lineNumbers
in result:
131 print "Error: wrong type of parameter in function printOut"
133 if __name__ ==
"__main__":
143 goodParameters =
True
144 argvLen = len(sys.argv)
149 while (i != argvLen):
158 ruleNumbers = sys.argv[i].
split(
',')
160 goodParameters =
False
161 print 'Error: missing rule parameters. Write -h for help'
166 checkPath = sys.argv[i]
167 if not isdir(checkPath):
168 goodParameters =
False
169 print 'Error: wrong directory "%s"' %checkPath
172 goodParameters =
False
173 print 'Error: missing rule parameters. Write -h for help'
177 if i+1 < argvLen
and sys.argv[i+1][0] !=
'-':
179 picklePath = sys.argv[i]
180 if not isdir(picklePath):
181 goodParameters =
False
182 print 'Error: wrong directory "%s"' %picklePath
186 if i+1 < argvLen
and sys.argv[i+1][0] !=
'-':
188 txtPath = sys.argv[i]
189 if not isdir(txtPath):
190 goodParameters =
False
191 print 'Error: wrong directory "%s"' %txtPath
193 elif (arg ==
'-html'):
199 goodParameters =
False
200 print 'Error: there is no parameter like "%s". Write -h for help' %arg
204 if goodParameters ==
True:
206 if argvLen == 2
and help ==
True:
212 if argvLen == 1
or printResult
or (createPickle ==
False and createTxt ==
False):
216 for rule, ruleResult
in result:
221 run(picklePath, picklePath, picklePath)
static std::string join(char **cmd)