The Gaudi Framework  v36r1 (3e2fb5a8)
RootMap.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
12 
13 from __future__ import print_function
14 import os
15 import sys
16 
17 
18 def _getPath(pathstring=""):
19  pthlist = []
20  if pathstring == "":
21  if sys.platform == "linux2":
22  pathstring = os.environ["LD_LIBRARY_PATH"]
23  else:
24  pathstring = os.environ["PATH"]
25  pthlist += pathstring.split(os.pathsep)
26  return pthlist
27 
28 
29 def _getEntry(line):
30  ll = line.split()
31  entry = ll[0]
32  entry = entry.replace("Library.", "")
33  entry = entry.replace(":", "")
34  entry = entry.replace("@", ":")
35  entry = entry.replace("-", " ")
36  lib = ll[1]
37  return entry, lib
38 
39 
40 def _getBlock(line):
41  if line.find("Begin"):
42  block = line.split()[-1]
43  return block
44 
45 
46 def _procRootMap(rtmpfile, rtmapdict):
47  block = ""
48  for line in open(rtmpfile, 'r'):
49  line = line[:-1]
50  if line:
51  if line[0] != '#':
52  entry, lib = _getEntry(line)
53  if entry not in rtmapdict:
54  rtmapdict[entry] = []
55  rtmapdict[entry].append((os.path.join(
56  os.path.dirname(rtmpfile), lib), block))
57  else:
58  block = _getBlock(line)
59 
60 
61 def _procSysRootMap(rtmapdict):
62  if "ROOTSYS" in os.environ:
63  rtmpfile = os.path.join(os.environ["ROOTSYS"], "etc", "system.rootmap")
64  block = ""
65  for line in open(rtmpfile, 'r'):
66  line = line[:-1]
67  if line:
68  if line[0] != '#':
69  entry, lib = _getEntry(line)
70  if entry not in rtmapdict:
71  rtmapdict[entry] = []
72  rtmapdict[entry].append((os.path.join(
73  os.environ["ROOTSYS"], "lib", lib), block))
74  else:
75  block = _getBlock(line)
76  else:
77  print("WARNING: No ROOTSYS defined!")
78 
79 
80 def _isRootMap(filename):
81  # The file must begin with "rootmap"
82  if (filename.find("rootmap") == 0):
83  return True
84  return False
85 
86 
87 def getMaps(pathstring="", sysrtmap=False):
88  rtmapdict = dict()
89  pthlist = _getPath(pathstring)
90  if sysrtmap:
91  _procSysRootMap(rtmapdict)
92  for p in pthlist:
93  try:
94  for f in filter(_isRootMap, os.listdir(p)):
95  rtmpfile = os.path.join(p, f)
96  if (os.path.exists(rtmpfile)):
97  _procRootMap(rtmpfile, rtmapdict)
98  except:
99  pass
100  return rtmapdict
101 
102 
104  sz = 0
105  for k in maps.keys():
106  if len(k) > sz:
107  sz = len(k)
108  return sz
109 
110 
111 def printMaps(maps, recomp=None):
112  linelen = _getLongestEntry(maps)
113  frmat = r"%-" + str(linelen) + "s\t"
114  kys = maps.keys()
115  kys.sort()
116  if recomp:
117  kys = filter(recomp.search, kys)
118  for k in kys:
119  if len(maps[k]) > 1:
120  print("!!!!!!!!!!!! WARNING - More than one entry !!!!!!!!!!")
121  for l in maps[k]:
122  print(frmat % k, end=' ')
123  for m in l:
124  print(m, end=' ')
125  print(" ")
126  return
127 
128 
129 def shortPrintMaps(maps, recomp=None):
130  kys = maps.keys()
131  kys.sort()
132  if recomp:
133  kys = filter(recomp.search, kys)
134  for k in kys:
135  if len(maps[k]) > 1:
136  print(k, "!!!!!!!!!!!! WARNING - More than one entry !!!!!!!!!!")
137  else:
138  print(k)
139  for l in maps[k]:
140  for m in l:
141  print("\t%s" % m, end=' ')
142  print(" ")
143  return
144 
145 
146 def printKeys(maps, recomp=None):
147  kys = maps.keys()
148  kys.sort()
149  if recomp:
150  kys = filter(recomp.search, kys)
151  for k in kys:
152  if len(maps[k]) > 1:
153  print("!!!!!!!!!!!! WARNING - More than one entry !!!!!!!!!!")
154  for l in maps[k]:
155  print(k)
156  return
157 
158 
159 def checkDict(maps, recomp=None):
160  kys = maps.keys()
161  kys.sort()
162  if recomp:
163  kys = filter(recomp.search, kys)
164  for k in kys:
165  if len(maps[k]) > 1:
166  print("!!!!!!!!!!!! WARNING - More than one entry !!!!!!!!!!")
167  print(k)
168  for l in maps[k]:
169  for m in l:
170  print("\t%s" % m, end=' ')
171  print(" ")
172  return
GaudiKernel.RootMap._getEntry
def _getEntry(line)
Definition: RootMap.py:29
GaudiKernel.RootMap._procRootMap
def _procRootMap(rtmpfile, rtmapdict)
Definition: RootMap.py:46
GaudiKernel.RootMap._procSysRootMap
def _procSysRootMap(rtmapdict)
Definition: RootMap.py:61
GaudiKernel.RootMap._isRootMap
def _isRootMap(filename)
Definition: RootMap.py:80
GaudiKernel.RootMap.shortPrintMaps
def shortPrintMaps(maps, recomp=None)
Definition: RootMap.py:129
GaudiKernel.RootMap.printKeys
def printKeys(maps, recomp=None)
Definition: RootMap.py:146
GaudiKernel.RootMap.checkDict
def checkDict(maps, recomp=None)
Definition: RootMap.py:159
GaudiKernel.RootMap._getBlock
def _getBlock(line)
Definition: RootMap.py:40
GaudiKernel.RootMap.getMaps
def getMaps(pathstring="", sysrtmap=False)
Definition: RootMap.py:87
GaudiKernel.RootMap._getPath
def _getPath(pathstring="")
Definition: RootMap.py:18
GaudiKernel.RootMap._getLongestEntry
def _getLongestEntry(maps)
Definition: RootMap.py:103
GaudiKernel.RootMap.printMaps
def printMaps(maps, recomp=None)
Definition: RootMap.py:111