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

Referenced by getImportTree().

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

Definition at line 295 of file TreeCrawler.py.

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

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

Definition at line 31 of file TreeCrawler.py.

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

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

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

References edm.print().

Referenced by transformIntoGraph().

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

Definition at line 265 of file TreeCrawler.py.

References removeRecursiveLoops().

Referenced by getImportTree().

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