| # Gaudi Framework, version v21r9 |

Home |  | Generated: 3 May 2010

# RootMap.py

Go to the documentation of this file.

    00001 #!/usr/bin/env python
    00002
    00003 import os
    00004 import sys
    00005
    00006
    00007 def _getPath(pathstring = ""):
    00008     pthlist = []
    00009     if pathstring == "":
    00010         if sys.platform == "linux2":
    00011             pathstring = os.environ["LD_LIBRARY_PATH"]
    00012         else:
    00013             pathstring = os.environ["PATH"]
    00014     pthlist += pathstring.split(os.pathsep)
    00015     return pthlist
    00016
    00017
    00018 def _getEntry(line):
    00019     ll=line.split()
    00020     entry = ll[0]
    00021     entry=entry.replace("Library.","")
    00022     entry=entry.replace(":","")
    00023     entry=entry.replace("@",":")
    00024     entry=entry.replace("-"," ")
    00025     lib = ll[1]
    00026     return entry,lib
    00027
    00028 def _getBlock(line):
    00029     if line.find("Begin"):
    00030         block=line.split()[-1]
    00031     return block
    00032
    00033
    00034 def _procRootMap(rtmpfile,rtmapdict):
    00035     block = ""
    00036     for line in open(rtmpfile,'r'):
    00037         line = line[:-1]
    00038         if line:
    00039             if line[0] != '#':
    00040                 entry,lib=_getEntry(line)
    00041                 if not rtmapdict.has_key(entry):
    00042                     rtmapdict[entry] = []
    00043                 rtmapdict[entry].append((os.path.join(os.path.dirname(rtmpfile),lib),block))
    00044             else:
    00045                 block=_getBlock(line)
    00046
    00047 def _procSysRootMap(rtmapdict):
    00048     if os.environ.has_key("ROOTSYS"):
    00049         rtmpfile = os.path.join(os.environ["ROOTSYS"],"etc","system.rootmap")
    00050         block = ""
    00051         for line in open(rtmpfile,'r'):
    00052             line = line[:-1]
    00053             if line:
    00054                 if line[0] != '#':
    00055                     entry,lib=_getEntry(line)
    00056                     if not rtmapdict.has_key(entry):
    00057                         rtmapdict[entry] = []
    00058                     rtmapdict[entry].append((os.path.join(os.environ["ROOTSYS"],"lib",lib),block))
    00059                 else:
    00060                     block=_getBlock(line)
    00061     else:
    00062         print "WARNING: No ROOTSYS defined!"
    00063
    00064 def _isRootMap(filename):
    00065     # The file must begin with "rootmap"
    00066     if (filename.find("rootmap")==0) :
    00067         return True
    00068     return False
    00069
    00070 def getMaps(pathstring = "",sysrtmap=False):
    00071     rtmapdict = dict()
    00072     pthlist = _getPath(pathstring)
    00073     if sysrtmap :
    00074         _procSysRootMap(rtmapdict)
    00075     for p in pthlist:
    00076         try:
    00077             for f in filter(_isRootMap,os.listdir(p)):
    00078                 rtmpfile = os.path.join(p,f)
    00079                 if (os.path.exists(rtmpfile)):
    00080                     _procRootMap(rtmpfile,rtmapdict)
    00081         except: pass
    00082     return rtmapdict
    00083
    00084 def _getLongestEntry(maps):
    00085     sz = 0
    00086     for k in maps.keys():
    00087         if len(k)>sz:
    00088             sz = len(k)
    00089     return sz
    00090
    00091
    00092 def printMaps(maps,recomp=None):
    00093     linelen = _getLongestEntry(maps)
    00094     frmat = r"%-" + str(linelen) + "s\t"
    00095     kys = maps.keys()
    00096     kys.sort()
    00097     if recomp: kys = filter(recomp.search,kys)
    00098     for k in kys:
    00099         if len(maps[k])>1:
    00100             print "!!!!!!!!!!!! WARNING - More than one entry !!!!!!!!!!"
    00101         for l in maps[k]:
    00102             print frmat%k,
    00103             for m in l:
    00104                 print m,
    00105             print " "
    00106     return
    00107
    00108 def shortPrintMaps(maps,recomp=None):
    00109     kys = maps.keys()
    00110     kys.sort()
    00111     if recomp: kys = filter(recomp.search,kys)
    00112     for k in kys:
    00113         if len(maps[k])>1:
    00114             print k,"!!!!!!!!!!!! WARNING - More than one entry !!!!!!!!!!"
    00115         else:
    00116             print k
    00117         for l in maps[k]:
    00118             for m in l:
    00119                 print "\t%s"%m,
    00120             print " "
    00121     return
    00122
    00123 def printKeys(maps,recomp=None):
    00124     kys = maps.keys()
    00125     kys.sort()
    00126     if recomp: kys = filter(recomp.search,kys)
    00127     for k in kys:
    00128         if len(maps[k])>1:
    00129             print "!!!!!!!!!!!! WARNING - More than one entry !!!!!!!!!!"
    00130         for l in maps[k]:
    00131             print k
    00132     return
    00133
    00134 def checkDict(maps,recomp=None):
    00135     kys = maps.keys()
    00136     kys.sort()
    00137     if recomp: kys = filter(recomp.search,kys)
    00138     for k in kys:
    00139         if len(maps[k])>1:
    00140             print "!!!!!!!!!!!! WARNING - More than one entry !!!!!!!!!!"
    00141             print k
    00142             for l in maps[k]:
    00143                 for m in l:
    00144                     print "\t%s"%m,
    00145                 print " "
    00146     return