Go to the documentation of this file.00001 __author__="Aurelija"
00002 __date__ ="$2010-08-13 14.28.08$"
00003
00004 import sys
00005 import glob
00006 import pickle
00007 from os.path import join, split
00008
00009 rulesNames = []
00010
00011 if sys.platform[:3] == 'win':
00012 slash = "\\"
00013 else:
00014 slash = "/"
00015
00016 def readPicFiles(directory, toSplit = False):
00017
00018 ruleResult = {}
00019 rulesResults = {}
00020 picFiles = glob.glob(join(directory, "cmsCodeRule*.dat"))
00021 picFiles.sort()
00022
00023 for file in picFiles:
00024 head, fileName = split(file)
00025 ruleName = fileName[11:-4]
00026 rulesNames.append(ruleName)
00027
00028 file = open(file)
00029 ruleResult = pickle.load(file)
00030 if toSplit:
00031 ruleResult = splitToPackages(ruleResult)
00032
00033 rulesResults[ruleName] = ruleResult
00034
00035 return rulesResults
00036
00037
00038 def splitToPackages(ruleResult):
00039
00040 packageResult = []
00041 info = []
00042
00043 if not ruleResult: return info
00044
00045 ruleResult = ruleResult.items()
00046 ruleResult.sort()
00047 file, lines = ruleResult.pop(0)
00048 pathList = pathToList(file)
00049 package = slash.join(pathList[:2])
00050 packageResult.append((slash.join(pathList[2:]), lines))
00051
00052 for file, lines in ruleResult:
00053 pathList = pathToList(file)
00054 head = slash.join(pathList[:2])
00055 tail = slash.join(pathList[2:])
00056 if package == head:
00057 packageResult.append((tail, lines))
00058 else:
00059 info.append((package, packageResult))
00060 packageResult = []
00061 package = head
00062 packageResult.append((tail, lines))
00063 info.append((package, packageResult))
00064 return info
00065
00066 def pathToList(path):
00067 list = []
00068 head, tail = split(path)
00069 if tail != '':
00070 list.insert(0, tail)
00071 while head != '':
00072 head, tail = split(head)
00073 if tail != '':
00074 list.insert(0, tail)
00075 else:
00076 break
00077 return list
00078