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