# Path: pypeman/conf.py
# NOT_FOUND = object()  # sentinel object
# class ConfigError(ImportError):
# class Settings():
#     def __init__(self, module_name=None):
#     def init_settings(self):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
# 
# Path: pypeman/channels.py
# class Dropped(Exception):
# class Rejected(Exception):
# class ChannelStopped(Exception):
# class BaseChannel:
# class SubChannel(BaseChannel):
# class ConditionSubChannel(BaseChannel):
# class Case():
# class FileWatcherChannel(BaseChannel):
#     STARTING, WAITING, PROCESSING, STOPPING, STOPPED = range(5)
#     STATE_NAMES = ['STARTING', 'WAITING', 'PROCESSING', 'STOPPING', 'STOPPED']
#     NEW, UNCHANGED, MODIFIED, DELETED = range(4)
#     def __init__(self, name=None, parent_channel=None, loop=None, message_store_factory=None):
#     def status_id_to_str(cls, state_id):
#     def status_str_to_id(cls, state):
#     def status(self):
#     def status(self, value):
#     def is_stopped(self):
#     async def start(self):
#     def init_node_graph(self):
#     async def stop(self):
#     def _reset_test(self):
#     def add(self, *args):
#     def _register_node(self, node):
#     def get_node(self, name):
#     def append(self, *args):
#     def fork(self, name=None, message_store_factory=None):
#     def when(self, condition, name=None, message_store_factory=None):
#     def case(self, *conditions, names=None, message_store_factory=None):
#     def handle_and_wait(self, msg):
#     async def handle(self, msg):
#     async def subhandle(self, msg):
#     async def process(self, msg):
#     async def replay(self, msg_id):
#     def to_dict(self):
#     def subchannels(self):
#     def graph(self, prefix='', dot=False):
#     def graph_dot(self, end=''):
#     def __str__(self):
#     def __repr__(self):
# def reset_pypeman_channels():
#     def callback(self, fut):
#     async def process(self, msg):
#     def __init__(self, condition=lambda x: True, **kwargs):
#     def test_condition(self, msg):
#     async def subhandle(self, msg):
#     def __init__(self, *args, names=None, parent_channel=None, message_store_factory=None, loop=None):
#     def _reset_test(self):
#     def test_condition(self, condition, msg):
#     async def handle(self, msg):
#     def __init__(self, *args, basedir='', regex='.*', interval=1, binary_file=False, path='', **kwargs):
#     async def start(self):
#     def file_status(self, filename):
#     def _handle_callback(self, future):
#     async def watch_for_file(self):
# 
# Path: pypeman/errors.py
# class PypemanError(Exception):
#     """ custom error """


import importlib
import sys
import time
import traceback
from pypeman.conf import settings
from pypeman import channels
from pypeman.errors import PypemanError
    from pypeman.plugin_mgr import manager as plugin_manager

def wait_for_loop(tmax=5.0):
    """
    wait until the loop variable of a pypeman graph
    has been initialized

    can be used from any thread that's not the main thread
    """
    # TODO: might factor out this function to a helper module
    loop = None
    steps = int(tmax / 0.1)
    for i in range(steps, -1, -1):
        try:
            channel = channels.all_channels[0]
            # print("channel =", channel)
            loop = channel.loop
            break
        except Exception:
            if i == 0:
                raise PypemanError("couldn't obtain graph's loop")
        time.sleep(0.1)
    return loop


def mk_ascii_graph(title=None):
    """ Show pypeman graph as ascii output.
        Better reuse for debugging or new code
    """
    if title:
        yield title

# Path: pypeman/conf.py
# NOT_FOUND = object()  # sentinel object
# class ConfigError(ImportError):
# class Settings():
#     def __init__(self, module_name=None):
#     def init_settings(self):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
# 
# Path: pypeman/channels.py
# class Dropped(Exception):
# class Rejected(Exception):
# class ChannelStopped(Exception):
# class BaseChannel:
# class SubChannel(BaseChannel):
# class ConditionSubChannel(BaseChannel):
# class Case():
# class FileWatcherChannel(BaseChannel):
#     STARTING, WAITING, PROCESSING, STOPPING, STOPPED = range(5)
#     STATE_NAMES = ['STARTING', 'WAITING', 'PROCESSING', 'STOPPING', 'STOPPED']
#     NEW, UNCHANGED, MODIFIED, DELETED = range(4)
#     def __init__(self, name=None, parent_channel=None, loop=None, message_store_factory=None):
#     def status_id_to_str(cls, state_id):
#     def status_str_to_id(cls, state):
#     def status(self):
#     def status(self, value):
#     def is_stopped(self):
#     async def start(self):
#     def init_node_graph(self):
#     async def stop(self):
#     def _reset_test(self):
#     def add(self, *args):
#     def _register_node(self, node):
#     def get_node(self, name):
#     def append(self, *args):
#     def fork(self, name=None, message_store_factory=None):
#     def when(self, condition, name=None, message_store_factory=None):
#     def case(self, *conditions, names=None, message_store_factory=None):
#     def handle_and_wait(self, msg):
#     async def handle(self, msg):
#     async def subhandle(self, msg):
#     async def process(self, msg):
#     async def replay(self, msg_id):
#     def to_dict(self):
#     def subchannels(self):
#     def graph(self, prefix='', dot=False):
#     def graph_dot(self, end=''):
#     def __str__(self):
#     def __repr__(self):
# def reset_pypeman_channels():
#     def callback(self, fut):
#     async def process(self, msg):
#     def __init__(self, condition=lambda x: True, **kwargs):
#     def test_condition(self, msg):
#     async def subhandle(self, msg):
#     def __init__(self, *args, names=None, parent_channel=None, message_store_factory=None, loop=None):
#     def _reset_test(self):
#     def test_condition(self, condition, msg):
#     async def handle(self, msg):
#     def __init__(self, *args, basedir='', regex='.*', interval=1, binary_file=False, path='', **kwargs):
#     async def start(self):
#     def file_status(self, filename):
#     def _handle_callback(self, future):
#     async def watch_for_file(self):
# 
# Path: pypeman/errors.py
# class PypemanError(Exception):
#     """ custom error """


# Path: pypeman/graph.py
import importlib
import sys
import time
import traceback
from pypeman.conf import settings
from pypeman import channels
from pypeman.errors import PypemanError
    from pypeman.plugin_mgr import manager as plugin_manager


def wait_for_loop(tmax=5.0):
    """
    wait until the loop variable of a pypeman graph
    has been initialized

    can be used from any thread that's not the main thread
    """
    # TODO: might factor out this function to a helper module
    loop = None
    steps = int(tmax / 0.1)
    for i in range(steps, -1, -1):
        try:
            channel = channels.all_channels[0]
            # print("channel =", channel)
            loop = channel.loop
            break
        except Exception:
            if i == 0:
                raise PypemanError("couldn't obtain graph's loop")
        time.sleep(0.1)
    return loop


def mk_ascii_graph(title=None):
    """ Show pypeman graph as ascii output.
        Better reuse for debugging or new code
    """
    if title:
        yield title

    for channel in channels.all_channels: