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 = sorted(glob.glob(join(directory, "cmsCodeRule*.dat")))
21 
22  for file in picFiles:
23  head, fileName = split(file)
24  ruleName = fileName[11:-4]
25  rulesNames.append(ruleName)
26 
27  file = open(file)
28  ruleResult = pickle.load(file)
29  if toSplit:
30  ruleResult = splitToPackages(ruleResult)
31 
32  rulesResults[ruleName] = ruleResult
33 
34  return rulesResults
35 
36 
37 def splitToPackages(ruleResult):
38 
39  packageResult = []
40  info = []
41 
42  if not ruleResult: return info
43 
44  ruleResult = sorted(ruleResult.items())
45  file, lines = ruleResult.pop(0)
46  pathList = pathToList(file)
47  package = slash.join(pathList[:2])
48  packageResult.append((slash.join(pathList[2:]), lines))
49 
50  for file, lines in ruleResult:
51  pathList = pathToList(file)
52  head = slash.join(pathList[:2])
53  tail = slash.join(pathList[2:])
54  if package == head:
55  packageResult.append((tail, lines))
56  else:
57  info.append((package, packageResult))
58  packageResult = []
59  package = head
60  packageResult.append((tail, lines))
61  info.append((package, packageResult))
62  return info #list of (package, packageResult)
63 
64 def pathToList(path):
65  list = []
66  head, tail = split(path)
67  if tail != '':
68  list.insert(0, tail)
69  while head != '':
70  head, tail = split(head)
71  if tail != '':
72  list.insert(0, tail)
73  else:
74  break
75  return list
76 
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
submitPVValidationJobs.split
def split(sequence, size)
Definition: submitPVValidationJobs.py:352
pickleFileParser.splitToPackages
def splitToPackages(ruleResult)
Definition: pickleFileParser.py:37
pickleFileParser.readPicFiles
def readPicFiles(directory, toSplit=False)
Definition: pickleFileParser.py:16
pickleFileParser.pathToList
def pathToList(path)
Definition: pickleFileParser.py:64