test
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', 'function' : 'functionName'}
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  if not classList:
166  classList = xmlObj.functionName
167  if not classList:
168  print "**** SKIPPING '%s' - Dosen't seem to have proper information(not class/function)." % filename
169  continue
170  for piece in classList:
171  try:
172  className = spacesRE.sub ('', piece.name)
173  except:
174  # must be one of these class pattern things. Skip it
175  #print " skipping %s" % filename, piece.__repr__()
176  continue
177  className = stdRE.sub ('', className)
178  # print " ", className
179  # Now get rid of any typedefs
180  for typedef, tdList in typedefsDict.iteritems():
181  for alias in tdList:
182  className = re.sub (alias, typedef, className)
183  classDict.setdefault (className, set()).add (filename)
184  # should we check for lost definitions?
185  if not options.lostDefs:
186  continue
187  localObjects.append (className)
188  if options.lazyLostDefs and not braketRE.search (className):
189  #print " ", className
190  matchString = r'\b' + className + r'\b'
191  simpleObjectREs.append( (re.compile (matchString), className ) )
192  for className in localObjects:
193  # if we see our name (or equivalent) here, then let's
194  # skip complaining about this
195  foundEquiv = False
196  for equivRE in regexList:
197  #print "searching %s for %s" % (equivRE[1], className)
198  if equivRE[0].search (className):
199  foundEquiv = True
200  break
201  for simpleRE in simpleObjectREs:
202  if simpleRE[0].search (className):
203  foundEquiv = True
204  if options.verbose and simpleRE[1] != className:
205  print " Using %s to ignore %s" \
206  % (simpleRE[1], className)
207  break
208  if foundEquiv: continue
209  for exRes in explicitREs:
210  if exRes[0].search(className):
211  dupProblems += " %s : %s\n" % (exRes[1], className)
212  foundEquiv = True
213  break
214  if foundEquiv: continue
215  for packageName in xmlPackages:
216  # don't bother looking for the name of this
217  # package in this package
218  if packagesREs[packageName].search (className):
219  dupProblems += " %s : %s\n" % (packageName, className)
220  break
221  # for piece
222  if dupProblems:
223  print '\n%s\n%s\n' % (filename, dupProblems)
224  # for filename
225  if options.dups:
226  for name, fileSet in sorted( classDict.iteritems() ):
227  if len (fileSet) < 2:
228  continue
229  print name
230  fileList = list (fileSet)
231  fileList.sort()
232  for filename in fileList:
233  print " ", filename
234  print
235  # for name, fileSet
236  # if not noDups
237  #pprint.pprint (classDict)
238 
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:282
def duplicateReflexLibrarySearch.searchDuplicatePlugins ( )
Searches the edmpluginFile to find any duplicate
plugins.

Definition at line 239 of file duplicateReflexLibrarySearch.py.

References split.

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

Variable Documentation

string duplicateReflexLibrarySearch.action = 'store_true'

Definition at line 277 of file duplicateReflexLibrarySearch.py.

string duplicateReflexLibrarySearch.default = False,

Definition at line 271 of file duplicateReflexLibrarySearch.py.

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

Definition at line 269 of file duplicateReflexLibrarySearch.py.

duplicateReflexLibrarySearch.equivDict = \

Definition at line 33 of file duplicateReflexLibrarySearch.py.

string duplicateReflexLibrarySearch.help = "Search for duplicate definitions"

Definition at line 272 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 265 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 268 of file duplicateReflexLibrarySearch.py.