Functions | |
def | getReleaseBaseDir |
def | getXmlName |
def | searchClassDefXml |
def | searchDuplicatePlugins |
def | searchEdmPluginDump |
Variables | |
string | action = 'store_true' |
default = False, | |
tuple | dumpGroup = optparse.OptionGroup(parser, "EdmPluginDump options") |
equivDict = \ | |
string | help = "Search for duplicate definitions" |
dictionary | ignoreEdmDP |
dictionary | packageMatchDict = {} |
list | packageREs = [] |
tuple | parser |
typedefsDict = \ | |
tuple | xmlGroup = optparse.OptionGroup(parser, "ClassDef XML options") |
def duplicateReflexLibrarySearch::getReleaseBaseDir | ( | ) |
return CMSSW_RELEASE_BASE or CMSSW_BASE depending on the dev area of release area
Definition at line 78 of file duplicateReflexLibrarySearch.py.
def duplicateReflexLibrarySearch::getXmlName | ( | line | ) |
Given a line from EDM plugin dump, try to get XML file name.
Definition at line 339 of file duplicateReflexLibrarySearch.py.
00340 : 00341 """Given a line from EDM plugin dump, try to get XML file name.""" 00342 global packageMatchDict 00343 retval = packageMatchDict.get (line) 00344 if retval: 00345 return retval 00346 for regex in packageREs: 00347 match = regex.search (line) 00348 if match: 00349 xmlFile = "./%s/%s/src/classes_def.xml" % \ 00350 (match.group(1), match.group(2)) 00351 if os.path.exists (xmlFile): 00352 packageMatchDict [line] = xmlFile 00353 return xmlFile 00354 #return "**%s/%s**" % (match.group(1), match.group(2)) If 00355 # we're here, then we haven't been successful yet. Let's try the 00356 # brute force approach. 00357 # Try 1 00358 cmd = 'find . -name classes_def.xml -print | grep %s' % line 00359 output = commands.getoutput (cmd).split ('\n') 00360 if output and len (output) == 1: 00361 retval = output[0]; 00362 if retval: 00363 packageMatchDict [line] = retval 00364 return retval 00365 # Try 2 00366 cmd = 'find . -name "BuildFile" -exec grep -q %s {} \; -print' % line 00367 output = commands.getoutput (cmd).split ('\n') 00368 if output and len (output) == 1: 00369 retval = output[0]; 00370 if retval: 00371 retval = retval + ' (%s)' % line 00372 packageMatchDict [line] = retval 00373 return retval 00374 return "**" + line + "**" 00375 00376
def duplicateReflexLibrarySearch::searchClassDefXml | ( | srcDir | ) |
Searches through the requested directory looking at 'classes_def.xml' files looking for duplicate Reflex definitions.
Definition at line 87 of file duplicateReflexLibrarySearch.py.
00088 : 00089 """ Searches through the requested directory looking at 00090 'classes_def.xml' files looking for duplicate Reflex definitions.""" 00091 # compile necessary RE statements 00092 classNameRE = re.compile (r'class\s+name\s*=\s*"([^"]*)"') 00093 spacesRE = re.compile (r'\s+') 00094 stdRE = re.compile (r'std::') 00095 srcClassNameRE = re.compile (r'(\w+)/src/classes_def.xml') 00096 ignoreSrcRE = re.compile (r'.*/FWCore/Skeletons/scripts/mkTemplates/.+') 00097 braketRE = re.compile (r'<.+>') 00098 # get the source directory we want 00099 if not len (srcDir): 00100 try: 00101 srcDir = getReleaseBaseDir() + '/src' 00102 except: 00103 raise RuntimeError, "$CMSSW_RELEASE_BASE not found." 00104 try: 00105 os.chdir (srcDir) 00106 except: 00107 raise RuntimeError, "'%s' is not a valid directory." % srcDir 00108 print "Searching for 'classes_def.xml' in '%s'." % srcDir 00109 xmlFiles = commands.getoutput ('find . -name "*classes_def.xml" -print').\ 00110 split ('\n') 00111 # print out the XML files, if requested 00112 if options.showXMLs: 00113 pprint.pprint (xmlFiles) 00114 # try and figure out the names of the packages 00115 xmlPackages = [] 00116 packagesREs = {} 00117 equivREs = {} 00118 explicitREs = [] 00119 for item in equivDict: 00120 for pack in item: 00121 for equiv in item[pack]: 00122 explicitREs.append( (re.compile(r'\b' + equiv + r'\b'),pack)) 00123 if options.lostDefs: 00124 for filename in xmlFiles: 00125 if (not filename) or (ignoreSrcRE.match(filename)): continue 00126 match = srcClassNameRE.search (filename) 00127 if not match: continue 00128 packageName = match.group(1) 00129 xmlPackages.append (packageName) 00130 matchString = r'\b' + packageName + r'\b' 00131 packagesREs[packageName] = re.compile (matchString) 00132 equivList = equivREs.setdefault (packageName, []) 00133 for item in equivDict: 00134 for equiv in item.get (packageName, []): 00135 matchString = re.compile(r'\b' + equiv + r'\b') 00136 equivList.append( (matchString, equiv) ) 00137 equivList.append( (packagesREs[packageName], packageName) ) 00138 #pprint.pprint (equivREs, width=109) 00139 classDict = {} 00140 ncdict = {'class' : 'className'} 00141 for filename in xmlFiles: 00142 if (not filename) or (ignoreSrcRE.match(filename)): continue 00143 dupProblems = '' 00144 exceptName = '' 00145 regexList = [] 00146 localObjects = [] 00147 simpleObjectREs = [] 00148 if options.lostDefs: 00149 lostMatch = srcClassNameRE.search (filename) 00150 if lostMatch: 00151 exceptName = lostMatch.group (1) 00152 regexList = equivREs[exceptName] 00153 xcount = len(regexList)-1 00154 if not regexList[xcount][0].search (exceptName): 00155 print '%s not found in' % exceptName, 00156 print regexList[xcount][0] 00157 sys.exit() 00158 else: continue 00159 if options.verbose: 00160 print "filename", filename 00161 try: 00162 xmlObj = xml2obj (filename = filename, 00163 filtering = True, 00164 nameChangeDict = ncdict) 00165 except Exception as detail: 00166 print "File %s is malformed XML. Please fix." % filename 00167 print " ", detail 00168 continue 00169 try: 00170 classList = xmlObj.selection.className 00171 except: 00172 try: 00173 classList = xmlObj.className 00174 except: 00175 # this isn't a real classes_def.xml file. Skip it 00176 print "**** SKIPPING '%s' - Doesn't seem to have proper information." % filename 00177 continue 00178 for piece in classList: 00179 try: 00180 className = spacesRE.sub ('', piece.name) 00181 except: 00182 # must be one of these class pattern things. Skip it 00183 #print " skipping %s" % filename, piece.__repr__() 00184 continue 00185 className = stdRE.sub ('', className) 00186 # print " ", className 00187 # Now get rid of any typedefs 00188 for typedef, tdList in typedefsDict.iteritems(): 00189 for alias in tdList: 00190 className = re.sub (alias, typedef, className) 00191 classDict.setdefault (className, set()).add (filename) 00192 # should we check for lost definitions? 00193 if not options.lostDefs: 00194 continue 00195 localObjects.append (className) 00196 if options.lazyLostDefs and not braketRE.search (className): 00197 #print " ", className 00198 matchString = r'\b' + className + r'\b' 00199 simpleObjectREs.append( (re.compile (matchString), className ) ) 00200 for className in localObjects: 00201 # if we see our name (or equivalent) here, then let's 00202 # skip complaining about this 00203 foundEquiv = False 00204 for equivRE in regexList: 00205 #print "searching %s for %s" % (equivRE[1], className) 00206 if equivRE[0].search (className): 00207 foundEquiv = True 00208 break 00209 for simpleRE in simpleObjectREs: 00210 if simpleRE[0].search (className): 00211 foundEquiv = True 00212 if options.verbose and simpleRE[1] != className: 00213 print " Using %s to ignore %s" \ 00214 % (simpleRE[1], className) 00215 break 00216 if foundEquiv: continue 00217 for exRes in explicitREs: 00218 if exRes[0].search(className): 00219 dupProblems += " %s : %s\n" % (exRes[1], className) 00220 foundEquiv = True 00221 break 00222 if foundEquiv: continue 00223 for packageName in xmlPackages: 00224 # don't bother looking for the name of this 00225 # package in this package 00226 if packagesREs[packageName].search (className): 00227 dupProblems += " %s : %s\n" % (packageName, className) 00228 break 00229 # for piece 00230 if dupProblems: 00231 print '\n%s\n%s\n' % (filename, dupProblems) 00232 # for filename 00233 if options.dups: 00234 for name, fileSet in sorted( classDict.iteritems() ): 00235 if len (fileSet) < 2: 00236 continue 00237 print name 00238 fileList = list (fileSet) 00239 fileList.sort() 00240 for filename in fileList: 00241 print " ", filename 00242 print 00243 # for name, fileSet 00244 # if not noDups 00245 #pprint.pprint (classDict) 00246
def duplicateReflexLibrarySearch::searchDuplicatePlugins | ( | edmpluginFile | ) |
Searches the edmpluginFile to find any duplicate plugins.
Definition at line 247 of file duplicateReflexLibrarySearch.py.
00248 : 00249 """ Searches the edmpluginFile to find any duplicate 00250 plugins.""" 00251 cmd = "cat %s | awk '{print $2\" \"$1}' | sort | uniq | awk '{print $1}' | sort | uniq -c | grep '2 ' | awk '{print $2}'" % edmpluginFile 00252 output = commands.getoutput (cmd).split('\n') 00253 for line in output: 00254 if ignoreEdmDP.has_key(line): continue 00255 line = line.replace("*","\*") 00256 cmd = "cat %s | grep ' %s ' | awk '{print $1}' | sort | uniq " % (edmpluginFile,line) 00257 out1 = commands.getoutput (cmd).split('\n') 00258 print line 00259 for plugin in out1: 00260 if plugin: 00261 print " **"+plugin+"**" 00262 print
def duplicateReflexLibrarySearch::searchEdmPluginDump | ( | edmpluginFile, | |
srcDir | |||
) |
Searches the edmpluginFile to find any duplicate Reflex definitions.
Definition at line 263 of file duplicateReflexLibrarySearch.py.
00264 : 00265 """ Searches the edmpluginFile to find any duplicate Reflex 00266 definitions.""" 00267 if not len (edmpluginFile): 00268 try: 00269 edmpluginFile = getReleaseBaseDir() + '/lib/' + \ 00270 os.environ.get('SCRAM_ARCH') + '/.edmplugincache' 00271 except: 00272 raise RuntimeError, \ 00273 "$CMSSW_RELEASE_BASE or $SCRAM_ARCH not found." 00274 if not len (srcDir): 00275 try: 00276 srcDir = getReleaseBaseDir() + '/src' 00277 except: 00278 raise RuntimeError, "$CMSSW_RELEASE_BASE not found." 00279 try: 00280 os.chdir (srcDir) 00281 except: 00282 raise RuntimeError, "'%s' is not a valid directory." % srcDir 00283 searchDuplicatePlugins (edmpluginFile) 00284 packageNames = commands.getoutput ('ls -1').split ('\n') 00285 global packageREs 00286 #print "pN", packageNames 00287 for package in packageNames: 00288 packageREs.append( re.compile( r'^(' + package + r')(\S+)$') ) 00289 # read the pipe of the grep command 00290 prevLine = '' 00291 searchREs = []; 00292 doSearch = False 00293 if options.searchFor: 00294 fixSpacesRE = re.compile (r'\s+'); 00295 doSearch = True 00296 words = options.searchFor.split('|') 00297 #print "words:", words 00298 for word in words: 00299 word = fixSpacesRE.sub (r'.*', word); 00300 searchREs.append( re.compile (word) ) 00301 problemSet = set() 00302 cmd = "grep Reflex %s | awk '{print $2}' | sort" % edmpluginFile 00303 for line in commands.getoutput (cmd).split('\n'): 00304 if doSearch: 00305 for regex in searchREs: 00306 if regex.search (line): 00307 problemSet.add (line) 00308 break 00309 else: 00310 if line == prevLine: 00311 if not ignoreEdmDP.has_key(line): 00312 problemSet.add (line) 00313 # print line 00314 prevLine = line 00315 # Look up in which libraries the problems are found 00316 pluginCapRE = re.compile (r'plugin(\S+?)Capabilities.so') 00317 fixStarsRE = re.compile (r'\*') 00318 lcgReflexRE = re.compile (r'^LCGReflex/') 00319 percentRE = re.compile (r'%') 00320 problemList = sorted (list (problemSet)) 00321 for problem in problemList: 00322 # Unbackwhacked stars will mess with the grep command. So 00323 # let's fix them now and not worry about it 00324 fixedProblem = fixStarsRE.sub (r'\*', problem) 00325 cmd = 'grep "%s" %s | awk \'{print $1}\'' % (fixedProblem, 00326 edmpluginFile) 00327 # print 'cmd', cmd 00328 output = commands.getoutput (cmd).split('\n') 00329 problem = lcgReflexRE.sub (r'', problem) 00330 problem = percentRE.sub (r' ', problem) 00331 print problem 00332 #if doSearch: continue 00333 for line in output: 00334 match = pluginCapRE.match (line) 00335 if match: 00336 line = match.group(1) 00337 print " ", getXmlName (line) 00338 print
string duplicateReflexLibrarySearch::action = 'store_true' |
Definition at line 394 of file duplicateReflexLibrarySearch.py.
string duplicateReflexLibrarySearch::default = False, |
Definition at line 388 of file duplicateReflexLibrarySearch.py.
tuple duplicateReflexLibrarySearch::dumpGroup = optparse.OptionGroup(parser, "EdmPluginDump options") |
Definition at line 386 of file duplicateReflexLibrarySearch.py.
Definition at line 33 of file duplicateReflexLibrarySearch.py.
string duplicateReflexLibrarySearch::help = "Search for duplicate definitions" |
Definition at line 389 of file duplicateReflexLibrarySearch.py.
dictionary duplicateReflexLibrarySearch::ignoreEdmDP |
00001 { 00002 'LCGReflex/__gnu_cxx::__normal_iterator<std::basic_string<char>*,std::vector<std::basic_string<char>%>%>' : 1, 00003 '' : 1 00004 }
Definition at line 73 of file duplicateReflexLibrarySearch.py.
dictionary duplicateReflexLibrarySearch::packageMatchDict = {} |
Definition at line 378 of file duplicateReflexLibrarySearch.py.
list duplicateReflexLibrarySearch::packageREs = [] |
Definition at line 377 of file duplicateReflexLibrarySearch.py.
00001 optparse.OptionParser("Usage: %prog [options]\n"\ 00002 "Searches classes_def.xml for duplicate "\ 00003 "definitions")
Definition at line 382 of file duplicateReflexLibrarySearch.py.
Definition at line 15 of file duplicateReflexLibrarySearch.py.
tuple duplicateReflexLibrarySearch::xmlGroup = optparse.OptionGroup(parser, "ClassDef XML options") |
Definition at line 385 of file duplicateReflexLibrarySearch.py.