ATLAS Offline Software
checkPlugins.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 
5 
9 
10 from __future__ import print_function
11 
12 __author__ = "Sebastien Binet"
13 
14 import os
15 import sys
16 from PyUtils import Dso
17 
18 _suppression_dct = {
19  'TMath' : ('libCore.so', 'libMathCore.so'),
20  'string': ('libGaudiKernelDict.so',
21  'libCore.so',
22  'liblcg_PyCoolDict.so',
23  'libSTLAddRflx.so'),
24  'vector<vector<double> >': ('libMathCore.so',
25  'libAtlasSTLAddReflexDict.so'),
26  'RooStats': ('libHistFactory.so',
27  'libRooStats.so'),
28  'vector<unsigned int>': ('libSTLRflx.so',
29  'libSTLAddRflx.so'),
30  'vector<double>': ('libSTLRflx.so',
31  'libSTLAddRflx.so'),
32  }
33 
35  return os.environ.get('AtlasProject')
36 
37 
38 def printDb( db, detailedDump = False ):
39  if detailedDump : fct = lambda x: x
40  else: fct = os.path.basename
41  keys = list(db.keys())
42  keys.sort()
43  for k in keys:
44  print ("%s:" % k)
45  libs = db[k]
46  libs.sort()
47  for lib in libs:
48  print (" ",fct(lib))
49  return
50 
51 if __name__ == "__main__":
52 
53  from optparse import OptionParser
54  parser = OptionParser(usage="usage: %prog [options]")
55  parser.add_option(
56  "--capabilities",
57  dest = "capabilities",
58  default = None,
59  help = "Dump the capabilities of a given library (ex: libAthenaServices.so)"
60  )
61  parser.add_option(
62  "--dups",
63  dest = "checkDups",
64  default = None,
65  help = "Check if there is any duplicates among dictionaries for a given library"
66  )
67  parser.add_option(
68  "--dump-content",
69  dest = "dumpContent",
70  action = "store_true",
71  default = False,
72  help = "Dump the content of all the known plugins (dicts. and components)"
73  )
74  parser.add_option(
75  "--dso",
76  dest = "dumpDso",
77  action = "store_true",
78  default = False,
79  help = "Dump all the dsomap/rootmap files known to the Dso repository"
80  )
81  parser.add_option(
82  "--libs",
83  dest = "dumpLibs",
84  action = "store_true",
85  default = False,
86  help = "Dump all the libraries known to the Dso repository"
87  )
88  parser.add_option(
89  "--check-dict-dups",
90  action = "store_true",
91  default = False,
92  dest = "checkDictDuplicates",
93  help = "Check if there is any duplicates among dictionaries"
94  )
95  parser.add_option(
96  "--check-pf-dups",
97  action = "store_true",
98  default = False,
99  dest = "checkPfDuplicates",
100  help = "Check if there is any duplicates among components declared to the PluginSvc"
101  )
102  parser.add_option(
103  "--check-all-dups",
104  dest = "checkAllDuplicates",
105  action = "store_true",
106  default = False,
107  help = "Check dictionaries *and* components"
108  )
109  parser.add_option(
110  "--detailed-dump",
111  action = "store_true",
112  dest = "detailedDump",
113  default = False,
114  help = "Performs a detailed dump if duplicates are found"
115  )
116  parser.add_option(
117  "--pedantic",
118  action = "store_true",
119  dest = "isPedantic",
120  default = False,
121  help = "Pedantic mode: if a component is found in 2 libraries which have the same name (usual case of a developer working on a (set of) package(s)), it is still being reported as being duplicated"
122  )
123  parser.add_option(
124  "-l",
125  "--level",
126  dest = "logLvl",
127  default = "INFO",
128  help = "Logging level (aka verbosity)"
129  )
130 
131  (options, args) = parser.parse_args()
132 
133  print (":"*80)
134  print ("::: checkPlugins :::")
135  sc = 0
136  dsoDb = Dso.DsoDb()
137 
138  if len(args) > 0 and args[0][0] != "-":
139  options.capabilities = args[0]
140  pass
141 
142  if options.capabilities:
143  libName = options.capabilities
144  try:
145  capabilities = dsoDb.capabilities(libName)
146  print ("::: capabilities of [%s]" % libName)
147  print (os.linesep.join( [ " "+str(c) for c in capabilities ] ))
148  except ValueError:
149  sc = 1
150  pass
151 
152  if options.checkDups:
153  libName = options.checkDups
154  try:
155  print ("::: checking duplicates for [%s]..." % libName)
156  dups = dsoDb.duplicates(libName, pedantic = options.isPedantic)
157  for k in dups:
158  print (" -",k)
159  print (os.linesep.join( [ " "+str(v) for v in dups[k] ] ))
160  if len(dups.keys())>0: sc = 1
161  except ValueError:
162  sc = 1
163  pass
164 
165  if options.dumpContent:
166  print ("::: dumping content of all known plugins...")
167  entries = dsoDb.content( pedantic = options.isPedantic )
168  printDb(entries, options.detailedDump)
169  print ("::: known entries:",len(entries.keys()))
170 
171  if options.dumpLibs:
172  print ("::: dumping all known libraries...")
173  libs = dsoDb.libs(options.detailedDump)
174  for lib in libs:
175  print (" -",lib)
176  print ("::: known libs:",len(libs))
177 
178  if options.dumpDso:
179  print ("::: dumping all known dsomap/rootmap files...")
180  dsoFiles = [ dso for dso in dsoDb.dsoFiles]
181  dsoFiles.sort()
182  for dsoFile in dsoFiles:
183  if not options.detailedDump: dsoFile = os.path.basename(dsoFile)
184  print (" -",dsoFile)
185  print ("::: known dsos:",len(dsoFiles))
186 
187  if options.checkDictDuplicates or options.checkAllDuplicates:
188  print (":: checking dict. duplicates...")
189  dups = dsoDb.dictDuplicates( pedantic = options.isPedantic )
190  # restrict to just this project
191  #currProj = _currentProject()
192  #restrictedDups = {}
193  #for label, libPaths in dups.items():
194  # paths = [l for l in libPaths if ('/%s/' % currProj) in l]
195  # if paths:
196  # restrictedDups[label] = paths
197  #dups = restrictedDups
198 
199  sc = 0
200  suppression_log = []
201  for k in dups:
202  v = dups[k]
203 
204  # mark as error only if it isn't a know dup'
205  if k in _suppression_dct:
206  suppressed = [os.path.basename(ii) in _suppression_dct[k]
207  for ii in v]
208  if all(suppressed):
209  msg = "---> ignoring [%s]" % k
210  suppression_log.append(k[:])
211  #print (msg)
212  pass
213  else:
214  # that's a new one !
215  sc = 1
216  else:
217  # that's a new one !
218  sc = 1
219  #print ("---> NOT ignoring [%s]" % k)
220  printDb(dups, options.detailedDump)
221  if len(suppression_log):
222  print ("-"*40)
223  print ("## ignoring the following dups':")
224  for k in suppression_log:
225  print (" -",k)
226  print ("-"*40)
227  print ("## all dups:",len(dups.keys()))
228  print ("## dups:",len(dups.keys())-len(suppression_log))
229  if options.checkPfDuplicates or options.checkAllDuplicates:
230  print (":: checking (plugin factories) components duplicates...")
231  dups = dsoDb.pfDuplicates( pedantic = options.isPedantic )
232  if len(dups.keys()) > 0: sc = 1
233  printDb(dups, options.detailedDump)
234  print ("## dups:",len(dups.keys()))
235 
236  if sc != 0: print (":: ERROR !!")
237  else: print (":: All good.")
238 
239  print (":"*80)
240  sys.exit(sc)
python.AthDsoLogger.fct
fct
Definition: AthDsoLogger.py:43
checkPlugins.printDb
def printDb(db, detailedDump=False)
Definition: checkPlugins.py:38
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
Cut::all
@ all
Definition: SUSYToolsAlg.cxx:67
str
Definition: BTagTrackIpAccessor.cxx:11
checkPlugins._currentProject
def _currentProject()
Definition: checkPlugins.py:34