CMS 3D CMS Logo

pickleFileParser.py
Go to the documentation of this file.
1 __author__="Aurelija"
2 __date__ ="$2010-08-13 14.28.08$"
3 
4 import sys
5 import glob
6 import pickle
7 from os.path import join, split
8 
9 rulesNames = []
10 
11 if sys.platform[:3] == 'win':
12  slash = "\\"
13 else:
14  slash = "/"
15 
16 def readPicFiles(directory, toSplit = False):
17 
18  ruleResult = {}
19  rulesResults = {}
20  picFiles = glob.glob(join(directory, "cmsCodeRule*.dat"))
21  picFiles.sort()
22 
23  for file in picFiles:
24  head, fileName = split(file)
25  ruleName = fileName[11:-4]
26  rulesNames.append(ruleName)
27 
28  file = open(file)
29  ruleResult = pickle.load(file)
30  if toSplit:
31  ruleResult = splitToPackages(ruleResult)
32 
33  rulesResults[ruleName] = ruleResult
34 
35  return rulesResults
36 
37 
38 def splitToPackages(ruleResult):
39 
40  packageResult = []
41  info = []
42 
43  if not ruleResult: return info
44 
45  ruleResult = ruleResult.items()
46  ruleResult.sort()
47  file, lines = ruleResult.pop(0)
48  pathList = pathToList(file)
49  package = slash.join(pathList[:2])
50  packageResult.append((slash.join(pathList[2:]), lines))
51 
52  for file, lines in ruleResult:
53  pathList = pathToList(file)
54  head = slash.join(pathList[:2])
55  tail = slash.join(pathList[2:])
56  if package == head:
57  packageResult.append((tail, lines))
58  else:
59  info.append((package, packageResult))
60  packageResult = []
61  package = head
62  packageResult.append((tail, lines))
63  info.append((package, packageResult))
64  return info #list of (package, packageResult)
65 
66 def pathToList(path):
67  list = []
68  head, tail = split(path)
69  if tail != '':
70  list.insert(0, tail)
71  while head != '':
72  head, tail = split(head)
73  if tail != '':
74  list.insert(0, tail)
75  else:
76  break
77  return list
78 
def splitToPackages(ruleResult)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def readPicFiles(directory, toSplit=False)
double split
Definition: MVATrainer.cc:139