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