CMS 3D CMS Logo

Classes | Functions
TreeCrawler Namespace Reference

Classes

class  Color
 
class  mymf
 
class  Package
 
class  SearchHit
 

Functions

def getDependenciesFromPythonFile (filename, toplevelname, path)
 
def getImportTree (filename, path)
 
def packageNameFromFilename (name)
 
def removeRecursiveLoops (node, verbose=False, currentStack=None)
 
def transformIntoGraph (depgraph, toplevel)
 

Function Documentation

def TreeCrawler.getDependenciesFromPythonFile (   filename,
  toplevelname,
  path 
)

Definition at line 285 of file TreeCrawler.py.

Referenced by getImportTree().

285 def getDependenciesFromPythonFile(filename,toplevelname,path):
286  modulefinder = mymf(path)
287  modulefinder.run_script(filename)
288  globalDependencyDict = modulefinder._depgraph
289  globalDependencyDict[toplevelname] = globalDependencyDict["__main__"]
290  return globalDependencyDict
291 
292 
def getDependenciesFromPythonFile(filename, toplevelname, path)
Definition: TreeCrawler.py:285
def TreeCrawler.getImportTree (   filename,
  path 
)

Definition at line 293 of file TreeCrawler.py.

References getDependenciesFromPythonFile(), packageNameFromFilename(), and transformIntoGraph().

293 def getImportTree(filename,path):
294  toplevelname = packageNameFromFilename(filename)
295  # get dependencies from given file
296  globalDependencyDict = getDependenciesFromPythonFile(filename,toplevelname,path)
297 
298  # transform this flat structure in a dependency tree
299  dependencyGraph = transformIntoGraph(globalDependencyDict,toplevelname)
300  return dependencyGraph
301 
def getDependenciesFromPythonFile(filename, toplevelname, path)
Definition: TreeCrawler.py:285
def getImportTree(filename, path)
Definition: TreeCrawler.py:293
def packageNameFromFilename(name)
Definition: TreeCrawler.py:29
def transformIntoGraph(depgraph, toplevel)
Definition: TreeCrawler.py:263
def TreeCrawler.packageNameFromFilename (   name)

Definition at line 29 of file TreeCrawler.py.

References join(), python.rootplot.root2matplotlib.replace(), and split.

Referenced by getImportTree(), and TreeCrawler.Package.search().

30  return ".".join(name.replace("python/","").replace(".py","").split("/")[-3:])
31 
32 
def replace(string, replacements)
def packageNameFromFilename(name)
Definition: TreeCrawler.py:29
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
double split
Definition: MVATrainer.cc:139
def TreeCrawler.removeRecursiveLoops (   node,
  verbose = False,
  currentStack = None 
)

Definition at line 247 of file TreeCrawler.py.

Referenced by transformIntoGraph().

247 def removeRecursiveLoops( node, verbose=False, currentStack=None ) :
248  if currentStack is None : currentStack=[]
249  try :
250  duplicateIndex=currentStack.index( node ) # If there isn't a recursive loop this will raise a ValueError
251  if verbose :
252  print "Removing recursive loop in:"
253  for index in xrange(duplicateIndex,len(currentStack)) :
254  print " ",currentStack[index].name,"-->"
255  print " ",node.name
256  currentStack[-1].dependencies.remove(node)
257  except ValueError:
258  # No recursive loop found, so continue traversing the tree
259  currentStack.append( node )
260  for subnode in node.dependencies :
261  removeRecursiveLoops( subnode, verbose, currentStack[:] )
262 
def removeRecursiveLoops(node, verbose=False, currentStack=None)
Definition: TreeCrawler.py:247
def TreeCrawler.transformIntoGraph (   depgraph,
  toplevel 
)

Definition at line 263 of file TreeCrawler.py.

References removeRecursiveLoops().

Referenced by getImportTree().

263 def transformIntoGraph(depgraph,toplevel):
264  packageDict = {}
265  # create the top level config
266  packageDict[toplevel] = Package(toplevel, top = True)
267 
268  # create package objects
269  for key, value in depgraph.iteritems():
270  if key.count(".") == 2 and key != toplevel:
271  packageDict[key] = Package(key)
272  for name in value.keys():
273  if name.count(".") == 2: packageDict[name] = Package(name)
274  # now create dependencies
275  for key, value in depgraph.iteritems():
276  if key.count(".") == 2 or key == toplevel:
277  package = packageDict[key]
278  package.dependencies = [packageDict[name] for name in value.keys() if name.count(".") == 2]
279 
280  removeRecursiveLoops( packageDict[toplevel] )
281  # find and return the top level config
282  return packageDict[toplevel]
283 
284 
def removeRecursiveLoops(node, verbose=False, currentStack=None)
Definition: TreeCrawler.py:247
def transformIntoGraph(depgraph, toplevel)
Definition: TreeCrawler.py:263