CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
duplicateReflexLibrarySearch Namespace Reference

Functions

def searchClassDefXml
 
def searchDuplicatePlugins
 

Variables

string action = 'store_true'
 
 default = False,
 
tuple dumpGroup = optparse.OptionGroup(parser, "EdmPluginDump options")
 
 equivDict = \
 
string help = "Search for duplicate definitions"
 
dictionary ignoreEdmDP
 
tuple parser
 
 typedefsDict = \
 
tuple xmlGroup = optparse.OptionGroup(parser, "ClassDef XML options")
 

Function Documentation

def duplicateReflexLibrarySearch.searchClassDefXml ( )
Searches through the requested directory looking at
'classes_def.xml' files looking for duplicate Reflex definitions.

Definition at line 79 of file duplicateReflexLibrarySearch.py.

References cond::persistency.search().

79 
80 def searchClassDefXml ():
81  """ Searches through the requested directory looking at
82  'classes_def.xml' files looking for duplicate Reflex definitions."""
83  # compile necessary RE statements
84  classNameRE = re.compile (r'class\s+name\s*=\s*"([^"]*)"')
85  spacesRE = re.compile (r'\s+')
86  stdRE = re.compile (r'std::')
87  srcClassNameRE = re.compile (r'(\w+)/src/classes_def.xml')
88  ignoreSrcRE = re.compile (r'.*/FWCore/Skeletons/scripts/mkTemplates/.+')
89  braketRE = re.compile (r'<.+>')
90  print "Searching for 'classes_def.xml' in '%s'." % os.path.join(os.environ.get('CMSSW_BASE'),'src')
91  xmlFiles = []
92  for srcDir in [os.environ.get('CMSSW_BASE'),os.environ.get('CMSSW_RELEASE_BASE')]:
93  if not len(srcDir): continue
94  for xml in commands.getoutput ('cd '+os.path.join(srcDir,'src')+'; find . -name "*classes_def.xml" -follow -print').split ('\n'):
95  if xml and (not xml in xmlFiles):
96  xmlFiles.append(xml)
97  if options.showXMLs:
98  pprint.pprint (xmlFiles)
99  # try and figure out the names of the packages
100  xmlPackages = []
101  packagesREs = {}
102  equivREs = {}
103  explicitREs = []
104  for item in equivDict:
105  for pack in item:
106  for equiv in item[pack]:
107  explicitREs.append( (re.compile(r'\b' + equiv + r'\b'),pack))
108  if options.lostDefs:
109  for filename in xmlFiles:
110  if (not filename) or (ignoreSrcRE.match(filename)): continue
111  match = srcClassNameRE.search (filename)
112  if not match: continue
113  packageName = match.group(1)
114  xmlPackages.append (packageName)
115  matchString = r'\b' + packageName + r'\b'
116  packagesREs[packageName] = re.compile (matchString)
117  equivList = equivREs.setdefault (packageName, [])
118  for item in equivDict:
119  for equiv in item.get (packageName, []):
120  matchString = re.compile(r'\b' + equiv + r'\b')
121  equivList.append( (matchString, equiv) )
122  equivList.append( (packagesREs[packageName], packageName) )
123  classDict = {}
124  ncdict = {'class' : 'className'}
125  for filename in xmlFiles:
126  if (not filename) or (ignoreSrcRE.match(filename)): continue
127  dupProblems = ''
128  exceptName = ''
129  regexList = []
130  localObjects = []
131  simpleObjectREs = []
132  if options.lostDefs:
133  lostMatch = srcClassNameRE.search (filename)
134  if lostMatch:
135  exceptName = lostMatch.group (1)
136  regexList = equivREs[exceptName]
137  xcount = len(regexList)-1
138  if not regexList[xcount][0].search (exceptName):
139  print '%s not found in' % exceptName,
140  print regexList[xcount][0]
141  sys.exit()
142  else: continue
143  if options.verbose:
144  print "filename", filename
145  try:
146  filepath = os.path.join(os.environ.get('CMSSW_BASE'),'src',filename)
147  if not os.path.exists(filepath):
148  filepath = os.path.join(os.environ.get('CMSSW_RELEASE_BASE'),'src',filename)
149  xmlObj = xml2obj (filename = filepath,
150  filtering = True,
151  nameChangeDict = ncdict)
152  except Exception as detail:
153  print "File %s is malformed XML. Please fix." % filename
154  print " ", detail
155  continue
156  try:
157  classList = xmlObj.selection.className
158  except:
159  try:
160  classList = xmlObj.className
161  except:
162  # this isn't a real classes_def.xml file. Skip it
163  print "**** SKIPPING '%s' - Doesn't seem to have proper information." % filename
164  continue
165  for piece in classList:
166  try:
167  className = spacesRE.sub ('', piece.name)
168  except:
169  # must be one of these class pattern things. Skip it
170  #print " skipping %s" % filename, piece.__repr__()
171  continue
172  className = stdRE.sub ('', className)
173  # print " ", className
174  # Now get rid of any typedefs
175  for typedef, tdList in typedefsDict.iteritems():
176  for alias in tdList:
177  className = re.sub (alias, typedef, className)
178  classDict.setdefault (className, set()).add (filename)
179  # should we check for lost definitions?
180  if not options.lostDefs:
181  continue
182  localObjects.append (className)
183  if options.lazyLostDefs and not braketRE.search (className):
184  #print " ", className
185  matchString = r'\b' + className + r'\b'
186  simpleObjectREs.append( (re.compile (matchString), className ) )
187  for className in localObjects:
188  # if we see our name (or equivalent) here, then let's
189  # skip complaining about this
190  foundEquiv = False
191  for equivRE in regexList:
192  #print "searching %s for %s" % (equivRE[1], className)
193  if equivRE[0].search (className):
194  foundEquiv = True
195  break
196  for simpleRE in simpleObjectREs:
197  if simpleRE[0].search (className):
198  foundEquiv = True
199  if options.verbose and simpleRE[1] != className:
200  print " Using %s to ignore %s" \
201  % (simpleRE[1], className)
202  break
203  if foundEquiv: continue
204  for exRes in explicitREs:
205  if exRes[0].search(className):
206  dupProblems += " %s : %s\n" % (exRes[1], className)
207  foundEquiv = True
208  break
209  if foundEquiv: continue
210  for packageName in xmlPackages:
211  # don't bother looking for the name of this
212  # package in this package
213  if packagesREs[packageName].search (className):
214  dupProblems += " %s : %s\n" % (packageName, className)
215  break
216  # for piece
217  if dupProblems:
218  print '\n%s\n%s\n' % (filename, dupProblems)
219  # for filename
220  if options.dups:
221  for name, fileSet in sorted( classDict.iteritems() ):
222  if len (fileSet) < 2:
223  continue
224  print name
225  fileList = list (fileSet)
226  fileList.sort()
227  for filename in fileList:
228  print " ", filename
229  print
230  # for name, fileSet
231  # if not noDups
232  #pprint.pprint (classDict)
233 
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:229
def duplicateReflexLibrarySearch.searchDuplicatePlugins ( )
Searches the edmpluginFile to find any duplicate
plugins.

Definition at line 234 of file duplicateReflexLibrarySearch.py.

References split.

236  """ Searches the edmpluginFile to find any duplicate
237  plugins."""
238  edmpluginFile = ''
239  libenv = 'LD_LIBRARY_PATH'
240  if os.environ.get('SCRAM_ARCH').startswith('osx'): libenv = 'DYLD_FALLBACK_LIBRARY_PATH'
241  for libdir in os.environ.get(libenv).split(':'):
242  if os.path.exists(libdir+'/.edmplugincache'): edmpluginFile = edmpluginFile + ' ' + libdir+'/.edmplugincache'
243  if edmpluginFile == '': edmpluginFile = os.path.join(os.environ.get('CMSSW_BASE'),'lib',os.environ.get('SCRAM_ARCH'),'.edmplugincache')
244  cmd = "cat %s | awk '{print $2\" \"$1}' | sort | uniq | awk '{print $1}' | sort | uniq -c | grep '2 ' | awk '{print $2}'" % edmpluginFile
245  output = commands.getoutput (cmd).split('\n')
246  for line in output:
247  if ignoreEdmDP.has_key(line): continue
248  line = line.replace("*","\*")
249  cmd = "cat %s | grep ' %s ' | awk '{print $1}' | sort | uniq " % (edmpluginFile,line)
250  out1 = commands.getoutput (cmd).split('\n')
251  print line
252  for plugin in out1:
253  if plugin:
254  print " **"+plugin+"**"
255  print
double split
Definition: MVATrainer.cc:139

Variable Documentation

string duplicateReflexLibrarySearch.action = 'store_true'

Definition at line 270 of file duplicateReflexLibrarySearch.py.

string duplicateReflexLibrarySearch.default = False,

Definition at line 264 of file duplicateReflexLibrarySearch.py.

tuple duplicateReflexLibrarySearch.dumpGroup = optparse.OptionGroup(parser, "EdmPluginDump options")

Definition at line 262 of file duplicateReflexLibrarySearch.py.

duplicateReflexLibrarySearch.equivDict = \

Definition at line 33 of file duplicateReflexLibrarySearch.py.

string duplicateReflexLibrarySearch.help = "Search for duplicate definitions"

Definition at line 265 of file duplicateReflexLibrarySearch.py.

dictionary duplicateReflexLibrarySearch.ignoreEdmDP
Initial value:
1 = {
2  'LCGReflex/__gnu_cxx::__normal_iterator<std::basic_string<char>*,std::vector<std::basic_string<char>%>%>' : 1,
3  '' : 1
4 }

Definition at line 74 of file duplicateReflexLibrarySearch.py.

tuple duplicateReflexLibrarySearch.parser
Initial value:
1 = optparse.OptionParser("Usage: %prog [options]\n"\
2  "Searches classes_def.xml for wrong/duplicate "\
3  "definitions")

Definition at line 258 of file duplicateReflexLibrarySearch.py.

duplicateReflexLibrarySearch.typedefsDict = \

Definition at line 15 of file duplicateReflexLibrarySearch.py.

tuple duplicateReflexLibrarySearch.xmlGroup = optparse.OptionGroup(parser, "ClassDef XML options")

Definition at line 261 of file duplicateReflexLibrarySearch.py.