CMS 3D CMS Logo

TreeCrawler Namespace Reference


Classes

class  Color
class  mymf
class  Package
class  SearchHit

Functions

def getDependenciesFromConfig
def getDependenciesFromPythonFile
def getImportTree
def packageNameFromFilename
def transformIntoGraph

Variables

list _stack = []


Function Documentation

def TreeCrawler::getDependenciesFromConfig (   filename,
  toplevelname,
  path 
)

Definition at line 150 of file TreeCrawler.py.

00150                                                          :
00151     imports = [filename]
00152     config = open(filename)
00153     
00154     for line in config.readlines():
00155         # look for all load statements
00156         if line.startswith("process.load"):
00157             line = line.replace('"', "'") 
00158             moduleName = line.split("'")[1]
00159             module = __import__(moduleName,[],[],"*")
00160             imports.append(inspect.getsourcefile(module))
00161     config.close()
00162 
00163     # sort our loaded files alphabetically in Subsytem/Package pattern
00164     imports.sort(key= lambda x: x.split("python/")[-1])
00165 
00166     # hold a dict of the kind: {package : {dependencies}}
00167     globalDependencyDict = {}
00168 
00169     # create the flat include dictionaries for each load and merge them
00170     for item in imports:
00171         modulefinder = mymf(path)
00172         modulefinder.run_script(item)
00173 
00174         for key, value in modulefinder._depgraph.iteritems():
00175             if key == "__main__": key = packageNameFromFilename(item)
00176             globalDependencyDict[key] = value
00177 
00178     # now set the dependencies of our top level config with the load statements
00179     globalDependencyDict[toplevelname] = {}
00180     for item in imports:
00181         name = packageNameFromFilename(item)
00182         if name != toplevelname:
00183             globalDependencyDict[toplevelname][name] = 1
00184     return globalDependencyDict                                                
00185 
00186 
def getDependenciesFromPythonFile(filename,toplevelname,path):

def TreeCrawler::getDependenciesFromPythonFile (   filename,
  toplevelname,
  path 
)

Definition at line 187 of file TreeCrawler.py.

00187                                                              :
00188     modulefinder = mymf(path)
00189     modulefinder.run_script(filename)
00190     globalDependencyDict = modulefinder._depgraph
00191     globalDependencyDict[toplevelname] = globalDependencyDict["__main__"] 
00192     return globalDependencyDict
00193 
00194 
def getImportTree(filename,path):

def TreeCrawler::getImportTree (   filename,
  path 
)

Definition at line 195 of file TreeCrawler.py.

00195                                 :
00196     config = __import__(filename.rstrip(".py"))
00197     toplevelname = packageNameFromFilename(filename)
00198     # get dependencies from given file
00199     if hasattr(config,"process"):
00200         globalDependencyDict = getDependenciesFromConfig(filename,toplevelname,path)
00201     else:
00202         globalDependencyDict = getDependenciesFromPythonFile(filename,toplevelname,path)
00203     # transform this flat structure in a dependency tree
00204     dependencyGraph = transformIntoGraph(globalDependencyDict,toplevelname)
00205     return dependencyGraph                                               
    return dependencyGraph                                               

def TreeCrawler::packageNameFromFilename (   name  ) 

Definition at line 29 of file TreeCrawler.py.

00029                                  :
00030     return ".".join(name.replace("python/","").replace(".py","").split("/")[-3:])
00031 
00032 
class Color:

def TreeCrawler::transformIntoGraph (   depgraph,
  toplevel 
)

Definition at line 130 of file TreeCrawler.py.

00130                                          :
00131     packageDict = {}
00132     # create the top level config
00133     packageDict[toplevel] = Package(toplevel, top = True) 
00134 
00135     # create package objects
00136     for key, value in depgraph.iteritems():
00137         if key.count(".") == 2: packageDict[key] = Package(key)
00138         for name in value.keys():
00139             if name.count(".") == 2: packageDict[name] = Package(name)
00140     # now create dependencies
00141     for key, value in depgraph.iteritems():
00142         if key.count(".") == 2 or key == toplevel:
00143             package = packageDict[key]
00144             package.dependencies = [packageDict[name] for name in value.keys() if name.count(".") == 2]
00145 
00146     # find and return the top level config
00147     return packageDict[toplevel]
00148 
00149 
def getDependenciesFromConfig(filename,toplevelname,path):


Variable Documentation

list TreeCrawler::_stack = [] [static]

Definition at line 45 of file TreeCrawler.py.


Generated on Tue Jun 9 18:53:04 2009 for CMSSW by  doxygen 1.5.4