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 78 of file duplicateReflexLibrarySearch.py.

References dataformats.search().

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

Definition at line 233 of file duplicateReflexLibrarySearch.py.

References split.

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

Variable Documentation

string duplicateReflexLibrarySearch.action = 'store_true'

Definition at line 266 of file duplicateReflexLibrarySearch.py.

string duplicateReflexLibrarySearch.default = False,

Definition at line 260 of file duplicateReflexLibrarySearch.py.

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

Definition at line 258 of file duplicateReflexLibrarySearch.py.

duplicateReflexLibrarySearch.equivDict = \

Definition at line 33 of file duplicateReflexLibrarySearch.py.

string duplicateReflexLibrarySearch.help = "Search for duplicate definitions"

Definition at line 261 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 73 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 254 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 257 of file duplicateReflexLibrarySearch.py.