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


Python flow_utils.flatten函数代码示例

本文整理汇总了Python中taskflow.utils.flow_utils.flatten函数的典型用法代码示例。如果您正苦于以下问题:Python flatten函数的具体用法?Python flatten怎么用?Python flatten使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_flatten_checks_for_dups_globally

 def test_flatten_checks_for_dups_globally(self):
     flo = gf.Flow("test").add(
         gf.Flow("int1").add(t_utils.DummyTask(name="a")),
         gf.Flow("int2").add(t_utils.DummyTask(name="a")))
     with self.assertRaisesRegexp(exc.InvariantViolationException,
                                  '^Tasks with duplicate names'):
         f_utils.flatten(flo)
开发者ID:SEJeff,项目名称:taskflow,代码行数:7,代码来源:test_flattening.py

示例2: compile

    def compile(self):
        """Compiles the contained flow into a structure which the engine can
        use to run or if this can not be done then an exception is thrown
        indicating why this compilation could not be achieved.
        """
        if self._root is not None:
            return

        assert self._graph_action is not None, ('Graph action class must be'
                                                ' specified')
        self._change_state(states.RESUMING)  # does nothing in PENDING state
        task_graph = flow_utils.flatten(self._flow)
        if task_graph.number_of_nodes() == 0:
            raise exc.EmptyFlow("Flow %s is empty." % self._flow.name)
        self._root = self._graph_action(task_graph)
        for task in task_graph.nodes_iter():
            try:
                task_id = self.storage.get_uuid_by_name(task.name)
            except exc.NotFound:
                task_id = uuidutils.generate_uuid()
                task_version = misc.get_version_string(task)
                self.storage.add_task(task_name=task.name, uuid=task_id,
                                      task_version=task_version)

            self.storage.set_result_mapping(task_id, task.save_as)
            self._root.add(task, task_action.TaskAction(task, task_id))
        self._change_state(states.SUSPENDED)  # does nothing in PENDING state
开发者ID:bentwire,项目名称:taskflow,代码行数:27,代码来源:engine.py

示例3: _translate_flow_to_action

 def _translate_flow_to_action(self):
     # Flatten the flow into just 1 graph.
     task_graph = flow_utils.flatten(self._flow)
     ga = graph_action.SequentialGraphAction(task_graph)
     for n in task_graph.nodes_iter():
         ga.add(n, task_action.TaskAction(n, self))
     return ga
开发者ID:kebray,项目名称:taskflow,代码行数:7,代码来源:engine.py

示例4: test_graph_flatten

    def test_graph_flatten(self):
        a, b, c, d = _make_many(4)
        flo = gf.Flow("test")
        flo.add(a, b, c, d)

        g = f_utils.flatten(flo)
        self.assertEquals(4, len(g))
        self.assertEquals(0, g.number_of_edges())
开发者ID:SEJeff,项目名称:taskflow,代码行数:8,代码来源:test_flattening.py

示例5: _translate_flow_to_action

 def _translate_flow_to_action(self):
     assert self._graph_action is not None, ('Graph action class must be'
                                             ' specified')
     task_graph = flow_utils.flatten(self._flow)
     ga = self._graph_action(task_graph)
     for n in task_graph.nodes_iter():
         ga.add(n, task_action.TaskAction(n, self))
     return ga
开发者ID:jessicalucci,项目名称:TaskManagement,代码行数:8,代码来源:engine.py

示例6: test_targeted_flow_one_node

 def test_targeted_flow_one_node(self):
     wf = gw.TargetedFlow("test")
     test_1 = utils.ProvidesRequiresTask('test-1',
                                         provides=['a'], requires=[])
     wf.add(test_1)
     wf.set_target(test_1)
     g = fu.flatten(wf)
     self.assertEqual(1, len(g))
     self.assertTrue(g.has_node(test_1))
开发者ID:citrix-openstack-build,项目名称:taskflow,代码行数:9,代码来源:test_graph_flow.py

示例7: test_unordered_flatten

 def test_unordered_flatten(self):
     a, b, c, d = _make_many(4)
     flo = uf.Flow("test")
     flo.add(a, b, c, d)
     g = f_utils.flatten(flo)
     self.assertEquals(4, len(g))
     self.assertEquals(0, g.number_of_edges())
     self.assertEquals(set([a, b, c, d]),
                       set(g_utils.get_no_successors(g)))
     self.assertEquals(set([a, b, c, d]),
                       set(g_utils.get_no_predecessors(g)))
开发者ID:SEJeff,项目名称:taskflow,代码行数:11,代码来源:test_flattening.py

示例8: test_graph_flatten_nested_graph

    def test_graph_flatten_nested_graph(self):
        a, b, c, d, e, f, g = _make_many(7)
        flo = gf.Flow("test")
        flo.add(a, b, c, d)

        flo2 = gf.Flow('test2')
        flo2.add(e, f, g)
        flo.add(flo2)

        g = f_utils.flatten(flo)
        self.assertEquals(7, len(g))
        self.assertEquals(0, g.number_of_edges())
开发者ID:SEJeff,项目名称:taskflow,代码行数:12,代码来源:test_flattening.py

示例9: test_graph_flatten_links

    def test_graph_flatten_links(self):
        a, b, c, d = _make_many(4)
        flo = gf.Flow("test")
        flo.add(a, b, c, d)
        flo.link(a, b)
        flo.link(b, c)
        flo.link(c, d)

        g = f_utils.flatten(flo)
        self.assertEquals(4, len(g))
        self.assertEquals(3, g.number_of_edges())
        self.assertEquals(set([a]),
                          set(g_utils.get_no_predecessors(g)))
        self.assertEquals(set([d]),
                          set(g_utils.get_no_successors(g)))
开发者ID:SEJeff,项目名称:taskflow,代码行数:15,代码来源:test_flattening.py

示例10: test_flatten_attribute

 def test_flatten_attribute(self):
     wf = gw.Flow("the-test-action")
     test_1 = utils.ProvidesRequiresTask('test-1',
                                         requires=[],
                                         provides=[])
     test_2 = utils.ProvidesRequiresTask('test-2',
                                         provides=[],
                                         requires=[])
     wf.add(test_1, test_2)
     wf.link(test_1, test_2)
     g = fu.flatten(wf)
     self.assertEqual(2, len(g))
     edge_attrs = gu.get_edge_attrs(g, test_1, test_2)
     self.assertTrue(edge_attrs.get('manual'))
     self.assertTrue(edge_attrs.get('flatten'))
开发者ID:citrix-openstack-build,项目名称:taskflow,代码行数:15,代码来源:test_graph_flow.py

示例11: test_linear_flatten

    def test_linear_flatten(self):
        a, b, c, d = _make_many(4)
        flo = lf.Flow("test")
        flo.add(a, b, c)
        sflo = lf.Flow("sub-test")
        sflo.add(d)
        flo.add(sflo)

        g = f_utils.flatten(flo)
        self.assertEquals(4, len(g))

        order = nx.topological_sort(g)
        self.assertEquals([a, b, c, d], order)
        self.assertTrue(g.has_edge(c, d))
        self.assertEquals([d], list(g_utils.get_no_successors(g)))
        self.assertEquals([a], list(g_utils.get_no_predecessors(g)))
开发者ID:SEJeff,项目名称:taskflow,代码行数:16,代码来源:test_flattening.py

示例12: test_targeted_flow_reset

 def test_targeted_flow_reset(self):
     wf = gw.TargetedFlow("test")
     test_1 = utils.ProvidesRequiresTask('test-1',
                                         provides=['a'], requires=[])
     test_2 = utils.ProvidesRequiresTask('test-2',
                                         provides=['b'], requires=['a'])
     test_3 = utils.ProvidesRequiresTask('test-3',
                                         provides=[], requires=['b'])
     test_4 = utils.ProvidesRequiresTask('test-4',
                                         provides=['c'], requires=['b'])
     wf.add(test_1, test_2, test_3, test_4)
     wf.set_target(test_3)
     wf.reset_target()
     g = fu.flatten(wf)
     self.assertEqual(4, len(g))
     self.assertTrue(g.has_node(test_4))
开发者ID:citrix-openstack-build,项目名称:taskflow,代码行数:16,代码来源:test_graph_flow.py

示例13: compile

 def compile(self):
     if self._compiled:
         return
     task_graph = flow_utils.flatten(self._flow)
     if task_graph.number_of_nodes() == 0:
         raise exc.EmptyFlow("Flow %s is empty." % self._flow.name)
     self._analyzer = self._graph_analyzer_cls(task_graph, self.storage)
     if self._task_executor is None:
         self._task_executor = self._task_executor_cls()
     if self._task_action is None:
         self._task_action = self._task_action_cls(self.storage, self._task_executor, self.task_notifier)
     self._root = self._graph_action_cls(self._analyzer, self.storage, self._task_action)
     # NOTE(harlowja): Perform initial state manipulation and setup.
     #
     # TODO(harlowja): This doesn't seem like it should be in a compilation
     # function since compilation seems like it should not modify any
     # external state.
     self._ensure_storage_for(task_graph)
     self._compiled = True
开发者ID:zhujzhuo,项目名称:trove-1.0.10.4,代码行数:19,代码来源:engine.py

示例14: compile

    def compile(self):
        """Compiles the contained flow into a structure which the engine can
        use to run or if this can not be done then an exception is thrown
        indicating why this compilation could not be achieved.
        """
        if self._root is not None:
            return

        assert self._graph_action is not None, ('Graph action class must be'
                                                ' specified')
        self._change_state(states.RESUMING)  # does nothing in PENDING state
        task_graph = flow_utils.flatten(self._flow)
        self._root = self._graph_action(task_graph)
        loaded_failures = {}

        for task in task_graph.nodes_iter():
            try:
                task_id = self.storage.get_uuid_by_name(task.name)
            except exc.NotFound:
                task_id = uuidutils.generate_uuid()
                task_version = misc.get_version_string(task)
                self.storage.add_task(task_name=task.name, uuid=task_id,
                                      task_version=task_version)
            try:
                result = self.storage.get(task_id)
            except exc.NotFound:
                result = None

            if isinstance(result, misc.Failure):
                # NOTE(imelnikov): old failure may have exc_info which
                # might get lost during serialization, so we preserve
                # old failure object if possible.
                old_failure = self._failures.get(task_id, None)
                if result.matches(old_failure):
                    loaded_failures[task_id] = old_failure
                else:
                    loaded_failures[task_id] = result

            self.storage.set_result_mapping(task_id, task.save_as)
            self._root.add(task, task_action.TaskAction(task, task_id))
        self._failures = loaded_failures
        self._change_state(states.SUSPENDED)  # does nothing in PENDING state
开发者ID:ntt-sic,项目名称:taskflow,代码行数:42,代码来源:engine.py

示例15: compile

    def compile(self):
        """Compiles the contained flow into a structure which the engine can
        use to run or if this can not be done then an exception is thrown
        indicating why this compilation could not be achieved.
        """
        if self._root is not None:
            return

        assert self._graph_action_cls is not None, (
            'Graph action class must be specified')
        self._change_state(states.RESUMING)  # does nothing in PENDING state
        task_graph = flow_utils.flatten(self._flow)
        if task_graph.number_of_nodes() == 0:
            raise exc.EmptyFlow("Flow %s is empty." % self._flow.name)
        self._root = self._graph_action_cls(task_graph)
        for task in task_graph.nodes_iter():
            task_version = misc.get_version_string(task)
            self.storage.ensure_task(task.name, task_version, task.save_as)

        self._change_state(states.SUSPENDED)  # does nothing in PENDING state
开发者ID:rl-0x0,项目名称:taskflow,代码行数:20,代码来源:engine.py


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