Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-13 23:27:45

0001 __author__="Aurelija"
0002 __date__ ="$2010-08-13 14.28.08$"
0003 
0004 import sys
0005 import glob
0006 import pickle
0007 from os.path import join, split
0008 
0009 rulesNames = []
0010 
0011 if sys.platform[:3] == 'win':
0012     slash = "\\"
0013 else:
0014     slash = "/"
0015 
0016 def readPicFiles(directory, toSplit = False):
0017 
0018     ruleResult = {}
0019     rulesResults = {}
0020     picFiles = sorted(glob.glob(join(directory, "cmsCodeRule*.dat")))
0021 
0022     for file in picFiles:
0023         head, fileName = split(file)
0024         ruleName = fileName[11:-4]
0025         rulesNames.append(ruleName)
0026 
0027         file = open(file, 'rb')
0028         ruleResult = pickle.load(file)
0029         if toSplit:
0030             ruleResult = splitToPackages(ruleResult)
0031 
0032         rulesResults[ruleName] = ruleResult
0033 
0034     return rulesResults
0035 
0036 
0037 def splitToPackages(ruleResult):
0038 
0039     packageResult = []
0040     info = []
0041 
0042     if not ruleResult: return info
0043 
0044     ruleResult = sorted(ruleResult.items())
0045     file, lines = ruleResult.pop(0)
0046     pathList = pathToList(file)
0047     package = slash.join(pathList[:2])
0048     packageResult.append((slash.join(pathList[2:]), lines))
0049 
0050     for file, lines in ruleResult:
0051         pathList = pathToList(file)
0052         head = slash.join(pathList[:2])
0053         tail = slash.join(pathList[2:])
0054         if package == head:
0055             packageResult.append((tail, lines))
0056         else:
0057             info.append((package, packageResult))
0058             packageResult = []
0059             package = head
0060             packageResult.append((tail, lines))
0061     info.append((package, packageResult))
0062     return info #list of (package, packageResult)
0063 
0064 def pathToList(path):
0065     list = []
0066     head, tail = split(path)
0067     if tail != '':
0068         list.insert(0, tail)
0069     while head != '':
0070         head, tail = split(head)
0071         if tail != '':
0072             list.insert(0, tail)
0073         else:
0074             break
0075     return list
0076