CMS 3D CMS Logo

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 (   file,
  line 
)

Definition at line 102 of file cmsCodeRulesChecker.py.

00103                         :
00104     try:
00105         if type(file).__name__ != 'list':
00106             fileLines = open(file).readlines()
00107         else: fileLines = file
00108         fileLines[int(line)-1] = ''
00109     except IndexError:
00110         print 'File = "' + file +'" has only ' + str(len(fileLines)) + ' lines. Wrong given line number: ' + str(line)
00111     return fileLines

def cmsCodeRulesChecker::printOut (   listOfResult,
  filePath = None 
)

Definition at line 112 of file cmsCodeRulesChecker.py.

00113                                            :
00114     file = None
00115     try:
00116         for rule, result in listOfResult:
00117             if filePath:
00118                 file = open('%s/cmsCodeRule%s.txt'%(filePath, rule), 'w')
00119                 for path, lineNumbers in result:
00120                     file.write('%s\n'%path)
00121                     file.write('%s\n'%str(lineNumbers))
00122                 file.close()
00123             else:
00124                 if not result or result == -1:
00125                     print 'No results for rule %s'%rule
00126                 else:
00127                     print 'Rule %s:' %rule
00128                     for path, lineNumbers in result:
00129                         print path
00130                         print lineNumbers
00131     except TypeError:
00132         print "Error: wrong type of parameter in function printOut"

def cmsCodeRulesChecker::runRules (   ruleNumberList,
  directory 
)

Definition at line 32 of file cmsCodeRulesChecker.py.

00033                                        :
00034 
00035     result = []
00036     osWalk = []
00037     
00038     for rule in ruleNumberList:
00039         if str(rule) not in RULES:
00040             print 'Error: wrong rule parameter. There is no such rule: "'+rule+'"\n\n' + rulesDescription
00041             print '\nWrite -h for help'
00042             return -1
00043 
00044     for rule in configuration.keys():
00045         configuration[rule]['filter'] = re.compile(configuration[rule]['filter'])
00046 
00047     osWalk.extend(os.walk(directory))
00048 
00049     exceptPathsForEachRule = []
00050     for path in exceptPaths:
00051         exceptPathsForEachRule.append(join(checkPath, path))
00052 
00053     for ruleNr in ruleNumberList:
00054         files = []
00055         rule = str(ruleNr)
00056         rule = configuration[ruleNr]
00057 
00058         filesToMatch = rule['filesToMatch']
00059         exceptRuleLines = []
00060         exceptRulePaths = []
00061         for path in rule['exceptPaths']:
00062             try:
00063                 file, line = path.split(":")
00064                 exceptRuleLines.append((pathToRegEx(file), line))
00065             except ValueError:
00066                 exceptRulePaths.append(pathToRegEx(path))
00067         for fileType in filesToMatch:
00068             fileList = getFilePathsFromWalk(osWalk, fileType, exceptPathsForEachRule)
00069 # ------------------------------------------------------------------------------
00070             for path in exceptRulePaths:
00071                 FileList = []
00072                 for file in fileList:
00073                     File = file.replace(join(checkPath, ""), "")
00074                     if not re.match(path, File):
00075                         FileList.append(file)
00076                 fileList = FileList
00077 # ------------------------------------------------------------------------------
00078             filesLinesList = []
00079             skipLines = fileList
00080             for skipper in rule['skip']:
00081                 filesLinesList = skipper(skipLines)
00082                 skipLines = filesLinesList
00083             if not exceptRuleLines and not rule['skip']:
00084                 filesLinesList = fileList
00085 # ------------------------------------------------------------------------------
00086             for Nr, fileLine in enumerate(exceptRuleLines):
00087                 regEx, line = fileLine
00088                 for index, file in enumerate(fileList):
00089                     File = file.replace(join(checkPath, ""), "")
00090                     if re.match(regEx, File):
00091                         if rule['skip'] != None or Nr > 0:
00092                             filesLinesList[index] = (filesLinesList[index][0], omitLine(filesLinesList[index][1], line))
00093                         else:
00094                             filesLinesList.append([file, omitLine(file, line)])
00095                     elif rule['skip'] == None:
00096                         filesLinesList.append((file, open(file).readlines()))
00097             files.extend(filesLinesList)
00098 # ------------------------------------------------------------------------------
00099         listRule = finds(files, rule['filter'], rule['exceptFilter'])
00100         result.append((ruleNr, splitPaths(listRule, checkPath)))
00101     return result

def cmsCodeRulesChecker::splitPaths (   listRule,
  pathHead 
)

Definition at line 23 of file cmsCodeRulesChecker.py.

00024                                   :
00025     try:
00026         for i in range(len(listRule)):
00027             path, linesNumbers = listRule[i]
00028             listRule[i] = (path.replace(pathHead, '', 1), linesNumbers)
00029     except TypeError:
00030         print "Error: given wrong type of parameter in function splitPaths."
00031     return listRule


Variable Documentation

string cmsCodeRulesChecker::__author__ = "Aurelija"

Definition at line 3 of file cmsCodeRulesChecker.py.

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

Definition at line 4 of file cmsCodeRulesChecker.py.

list cmsCodeRulesChecker::arg = sys.argv[i]
tuple cmsCodeRulesChecker::argvLen = len(sys.argv)

Definition at line 144 of file cmsCodeRulesChecker.py.

Definition at line 19 of file cmsCodeRulesChecker.py.

Definition at line 17 of file cmsCodeRulesChecker.py.

Definition at line 137 of file cmsCodeRulesChecker.py.

Definition at line 138 of file cmsCodeRulesChecker.py.

tuple cmsCodeRulesChecker::cwd = os.getcwd()

Definition at line 135 of file cmsCodeRulesChecker.py.

Referenced by DQMProvInfo::getShowTags().

Definition at line 143 of file cmsCodeRulesChecker.py.

Definition at line 140 of file cmsCodeRulesChecker.py.

Definition at line 139 of file cmsCodeRulesChecker.py.

Definition at line 148 of file cmsCodeRulesChecker.py.

Definition at line 20 of file cmsCodeRulesChecker.py.

Definition at line 145 of file cmsCodeRulesChecker.py.

Definition at line 209 of file cmsCodeRulesChecker.py.

Definition at line 146 of file cmsCodeRulesChecker.py.

Definition at line 18 of file cmsCodeRulesChecker.py.

Definition at line 21 of file cmsCodeRulesChecker.py.