当前位置: 首页>>代码示例>>Python>>正文


Python Tree.leaves方法代码示例

本文整理汇总了Python中treelib.Tree.leaves方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.leaves方法的具体用法?Python Tree.leaves怎么用?Python Tree.leaves使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在treelib.Tree的用法示例。


在下文中一共展示了Tree.leaves方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Scansion

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import leaves [as 别名]
class Scansion(object):
    """
        .src    : list of strings
    """

    #///////////////////////////////////////////////////////////////////////////
    def __init__(self, source_file):
        """
                Scansion.__init__

                source_file     : (src) source file's name.
        """
        self.htree = Tree()
        self.src = []

        # creating root node (level 0) :
        self.htree.create_node(tag           = "root",
                               identifier    = "root",
                               data          = Hypothesis(htree = self.htree,
                                                          level=0,
                                                          language=None,
                                                          src=source_file))

        # calling root node :
        msg(0, "Calling the root node.")
        stop = False
        while not stop:
            leaves_to_be_extended = [leave for leave in self.htree.leaves() if not leave.data.dead]

            for leave in leaves_to_be_extended:
                leave.data.go_on()

            if len(leaves_to_be_extended)==0:
                stop = True
开发者ID:suizokukan,项目名称:anceps,代码行数:36,代码来源:pyscansion.py

示例2: __init__

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import leaves [as 别名]
class DependencyReader:
    """DependencyReader object"""

    def __init__(self):
        self.tempDirectoryPath = mkdtemp(dir=".")
        self.tree = Tree()
        self.dependencies = {}
        self.graphRelationships = []

    def getPom(self, pomPath):
        shutil.copy(pomPath, self.tempDirectoryPath)
        os.chdir(self.tempDirectoryPath)

    def getDependencies(self):
        mavenTreeOutput = subprocess.Popen('mvn org.apache.maven.plugins:maven-dependency-plugin:RELEASE:tree -DoutputType=tgf', stdout=subprocess.PIPE, shell=True)

        while True:
            line = mavenTreeOutput.stdout.readline().rstrip()

            if not line or re.search(r"BUILD SUCCESS", line):
                break

            match = re.match(r"\[INFO\]\s(\d*)\s*(.*):(.*):(\w+):([0-9\.]*)", line)

            if match:
                if not match.group(1) in self.dependencies.keys():
                    self.dependencies[match.group(1)] = DependencyNode(match.group(2), match.group(3), match.group(5), match.group(1))

                if not self.tree.leaves():
                    self.tree.create_node(match.group(1), match.group(1), data=self.dependencies[match.group(1)])

                self.dependencies[match.group(1)].get('jar', self.tempDirectoryPath)

            match = re.match(r"\[INFO\]\s(\d*)\s(\d*)", line)

            if match and match.group(2):
                self.graphRelationships.append((match.group(1), match.group(2)))

    def relateDependencies(self):
        while self.graphRelationships:
            for item in self.graphRelationships:
                node = self.tree.get_node(item[0])

                if node is not None:
                    parent = self.dependencies[item[0]]
                    child = self.dependencies[item[1]]
                    self.tree.create_node(child.referenceId, child.referenceId, parent=parent.referenceId, data=child)
                    self.graphRelationships.remove(item)

    def scanDependencies(self):
        # Need to run on each package with oneshot to get identifiers
        # unless update dosocsv2 to create identifiers on scan
        # or fix up dosocsv2 to create identifiers on scan instead
        for node in self.tree.expand_tree(mode=Tree.DEPTH):
            treeNode = self.tree.get_node(node)
            subprocess.call('dosocs2 oneshot ' + treeNode.data.jarName, shell=True)

    def createRelationships(self):
        # Pass packages as relationships to new dosocsv2 command created
        self.recursiveRelationship(self.tree.root)

    def recursiveRelationship(self, parent):
        for node in self.tree.is_branch(parent):
            parentNode = self.tree.get_node(parent)
            childNode = self.tree.get_node(node)
            subprocess.call('dosocs2 packagerelate ' + parentNode.data.jarName + ' ' + childNode.data.jarName, shell=True)
            self.recursiveRelationship(node)

    def retrieve_dependencies(self, jarName):
        if jarName is None:
            root = self.tree.get_node(self.tree.root)
            root = root.data.jarName
        else:
            root = jarName

        tgfOutput = subprocess.Popen('dosocs2 dependencies ' + root, stdout=subprocess.PIPE, shell=True)
        count = 0
        tree = Tree()
        dependencies = []
        relationships = []
        while True:
            line = tgfOutput.stdout.readline()

            if not line:
                break

            match = re.match(r"(\d+) - (.*)", line)
            if match:
                if count == 0:
                    count = count + 1
                    tree.create_node(match.group(2), match.group(1))
                else:
                    dependencies.append((match.group(2), match.group(1)))

            match = re.match(r"(\d+) (\d+)", line)

            if match:
                relationships.append((match.group(1), match.group(2)))

        if not relationships:
#.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:CSCI4900,代码行数:103,代码来源:dependency_reader.py


注:本文中的treelib.Tree.leaves方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。