Пример #1
0
def get_node_info(cls):
    """Get node info attribute of a node - transient function during
    depreciation"""

    if hasattr(cls, "__node_info__") and cls not in _node_info_warnings:

        get_logger().warn(
            "depreciated __node_info__ present in %s, rename to node_info"
            " (this warning will be shown only once)" % str(cls)
        )
        _node_info_warnings.add(cls)

        return cls.__node_info__
    else:
        return cls.node_info
Пример #2
0
    def __init__(self, nodes=None, connections=None):
        """Creates a node graph with connections.

        :Parameters:
            * `nodes` - dictionary with keys as node names and values as nodes
            * `connections` - list of two-item tuples. Each tuple contains source and target node
              or source and target node name.
        """

        super(Graph, self).__init__()
        self.nodes = OrderedDict()
        self.connections = set()

        self.logger = get_logger()

        self._name_sequence = 1

        if nodes:
            try:
                for name, node in nodes.items():
                    self.add(node, name)
            except:
                raise ValueError("Nodes should be a dictionary, is %s" % type(nodes))

        if connections:
            for connection in connections:
                self.connect(connection[0], connection[1])
Пример #3
0
    def identifier(cls):
        """Returns an identifier name of the node class. Identifier is used
        for construction of streams from dictionaries or for any other
        out-of-program constructions.

        Node identifier is specified in the `node_info` dictioanry as
        ``name``. If no explicit identifier is specified, then decamelized
        class name will be used with `node` suffix removed. For example:
        ``CSVSourceNode`` will be ``csv_source``.
        """

        logger = get_logger()

        # FIXME: this is temporary warning
        info = get_node_info(cls)
        ident = None

        if info:
            ident = info.get("name")

        if not ident:
            ident = to_identifier(decamelize(cls.__name__))
            if ident.endswith("_node"):
                ident = ident[:-5]

        return ident
Пример #4
0
    def __init__(self, nodes=None, connections=None):
        """Creates a data stream.

        :Parameters:
            * `nodes` - dictionary with keys as node names and values as nodes
            * `connections` - list of two-item tuples. Each tuple contains source and target node
              or source and target node name.
            * `stream` - another stream or
        """
        super(Stream, self).__init__(nodes, connections)
        self.logger = get_logger()

        self.exceptions = []
Пример #5
0
    def __init__(self, node):
        """Creates a stream node thread.

        :Attributes:
            * `node`: a Node object
            * `exception`: attribute will contain exception if one occurs during run()
            * `traceback`: will contain traceback if exception occurs

        """
        super(_StreamNodeThread, self).__init__()
        self.node = node
        self.exception = None
        self.traceback = None
        self.logger = get_logger()