示例#1
0
 def game_over(old_state, new_state, event):
     # This reaction function is mainly a intermediary delegation
     # function that analyzes the current memory and transitions to
     # the appropriate handler that will deal with the memory values,
     # it is *always* called before the final state is entered.
     if memory.failures:
         return FAILED
     with self._storage.lock.read_lock():
         leftover_atoms = iter_utils.count(
             # Avoid activating the deciders, since at this point
             # the engine is finishing and there will be no more further
             # work done anyway...
             iter_next_atoms(apply_deciders=False))
     if leftover_atoms:
         # Ok we didn't finish (either reverting or executing...) so
         # that means we must of been stopped at some point...
         LOG.trace(
             "Suspension determined to have been reacted to"
             " since (at least) %s atoms have been left in an"
             " unfinished state", leftover_atoms)
         return SUSPENDED
     elif self._runtime.is_success():
         return SUCCESS
     else:
         return REVERTED
示例#2
0
    def child_count(self, only_direct=True):
        """Returns how many children this node has.

        This can be either only the direct children of this node or inclusive
        of all children nodes of this node (children of children and so-on).

        NOTE(harlowja): it does not account for the current node in this count.
        """
        if not only_direct:
            return iter_utils.count(self.dfs_iter())
        return len(self._children)
示例#3
0
    def child_count(self, only_direct=True):
        """Returns how many children this node has.

        This can be either only the direct children of this node or inclusive
        of all children nodes of this node (children of children and so-on).

        NOTE(harlowja): it does not account for the current node in this count.
        """
        if not only_direct:
            return iter_utils.count(self.dfs_iter())
        return len(self._children)
 def test_count(self):
     self.assertEqual(0, iter_utils.count([]))
     self.assertEqual(1, iter_utils.count(['a']))
     self.assertEqual(10, iter_utils.count(compat_range(0, 10)))
     self.assertEqual(1000, iter_utils.count(compat_range(0, 1000)))
     self.assertEqual(0, iter_utils.count(compat_range(0)))
     self.assertEqual(0, iter_utils.count(compat_range(-1)))
 def test_count(self):
     self.assertEqual(0, iter_utils.count([]))
     self.assertEqual(1, iter_utils.count(['a']))
     self.assertEqual(10, iter_utils.count(compat_range(0, 10)))
     self.assertEqual(1000, iter_utils.count(compat_range(0, 1000)))
     self.assertEqual(0, iter_utils.count(compat_range(0)))
     self.assertEqual(0, iter_utils.count(compat_range(-1)))
示例#6
0
 def _post_compile(self, graph, node):
     """Called after the compilation of the root finishes successfully."""
     dup_names = misc.get_duplicate_keys(
         (node for node, node_attrs in graph.nodes_iter(data=True)
          if node_attrs['kind'] in ATOMS),
         key=lambda node: node.name)
     if dup_names:
         raise exc.Duplicate("Atoms with duplicate names found: %s" %
                             (sorted(dup_names)))
     atoms = iter_utils.count(
         node for node, node_attrs in graph.nodes_iter(data=True)
         if node_attrs['kind'] in ATOMS)
     if atoms == 0:
         raise exc.Empty("Root container '%s' (%s) is empty" %
                         (self._root, type(self._root)))
     self._history.clear()
示例#7
0
 def game_over(old_state, new_state, event):
     # This reaction function is mainly a intermediary delegation
     # function that analyzes the current memory and transitions to
     # the appropriate handler that will deal with the memory values,
     # it is *always* called before the final state is entered.
     if memory.failures:
         return FAILED
     leftover_nodes = iter_utils.count(
         # Avoid activating the deciders, since at this point
         # the engine is finishing and there will be no more further
         # work done anyway...
         iter_next_nodes(apply_deciders=False))
     if leftover_nodes:
         # Ok we didn't finish (either reverting or executing...) so
         # that means we must of been stopped at some point...
         LOG.blather("Suspension determined to have been reacted to"
                     " since (at least) %s nodes have been left in an"
                     " unfinished state", leftover_nodes)
         return SUSPENDED
     elif self._analyzer.is_success():
         return SUCCESS
     else:
         return REVERTED
示例#8
0
def _overlap_occurence_detector(to_graph, from_graph):
    """Returns how many nodes in 'from' graph are in 'to' graph (if any)."""
    return iter_utils.count(node for node in from_graph.nodes_iter()
                            if node in to_graph)
示例#9
0
 def _occurence_detector(to_graph, from_graph):
     return iter_utils.count(node for node in from_graph.nodes_iter()
                             if node in to_graph)