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 286 of file TreeCrawler.py.

Referenced by getImportTree().

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

Definition at line 294 of file TreeCrawler.py.

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

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

Definition at line 30 of file TreeCrawler.py.

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

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

31  return ".".join(name.replace("python/","").replace(".py","").split("/")[-3:])
32 
33 
def replace(string, replacements)
def packageNameFromFilename(name)
Definition: TreeCrawler.py:30
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 248 of file TreeCrawler.py.

Referenced by transformIntoGraph().

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

Definition at line 264 of file TreeCrawler.py.

References removeRecursiveLoops().

Referenced by getImportTree().

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