Bubble: command line tool for bubbling information between services

    .oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.\n
    Making single point to point API connections:\n
    _________________>>>>>>>>>pump>>>>>>>>>>>>>_____________________\n
    (source-service)->pull->(transform)->push->(target-service)\n
    _________________>>>>>>>>>pump>>>>>>>>>>>>>_____________________\n
    bubble can:\n
    * pull data from the source client\n
    * transform the data with flexible mapping and filtering rules\n
    * rules can use (custom) rule functions\n
    * push the result to  the target client\n

    A Bubble can process a list of basic python dicts(LOD),
    which are persisted in files or a database,
    for each step and stage that produced it.

    The only requirement for the service clients is that they have a:\n
    * source sevice: pull method which provides a LOD\n
    * target sevice: push method which accepts a dict\n


    A Bubble tries hard not to forget any step that has taken place,
    the results of any completed step is stored in a file,
    in the remember directory inside the Bubble.

    Without rules and bubble will "just" copy.\n

    Commands marked with (experimental) might work,
    but have not fully "behave" tested yet.

    For help on a specific command you can use:
        bubble <cmd> --help

    Create a bubble, make the information flow and start bubbling.\n
    .oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.\n

def cli(ctx, bubble_home, config, verbose, barverbose, profile):
    """Bubble: command line tool for bubbling information between services

    .oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.\n
    Making single point to point API connections:\n
    _________________>>>>>>>>>pump>>>>>>>>>>>>>_____________________\n
    (source-service)->pull->(transform)->push->(target-service)\n
    _________________>>>>>>>>>pump>>>>>>>>>>>>>_____________________\n
    bubble can:\n
    * pull data from the source client\n
    * transform the data with flexible mapping and filtering rules\n
    * rules can use (custom) rule functions\n
    * push the result to  the target client\n

    A Bubble can process a list of basic python dicts(LOD),
    which are persisted in files or a database,
    for each step and stage that produced it.

    The only requirement for the service clients is that they have a:\n
    * source sevice: pull method which provides a LOD\n
    * target sevice: push method which accepts a dict\n


    A Bubble tries hard not to forget any step that has taken place,
    the results of any completed step is stored in a file,
    in the remember directory inside the Bubble.

    Without rules and bubble will "just" copy.\n

    Commands marked with (experimental) might work,
    but have not fully "behave" tested yet.

    For help on a specific command you can use:
        bubble <cmd> --help

    Create a bubble, make the information flow and start bubbling.\n
    .oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.\n
    """

    # Create a bubble object and remember it as the context object.
    # From this point onwards other commands can refer to it by using the
    # @pass_bubble decorator.

    cis = ctx.invoked_subcommand
    initing = False

    if cis == 'stats':
        nagios = False
        try:
            monitor = ctx.args[ctx.args.index('--monitor') + 1]
            if monitor == 'nagios':
                nagios = True
        except (ValueError, IndexError):
            pass
        if nagios:
            verbose = 0

    BUBBLE_CLI_GLOBALS['profiling'] = profile
    if profile:
        start_profile()

    global VERBOSE
    VERBOSE = verbose

    global VERBOSE_BAR
    VERBOSE_BAR = barverbose

    if bubble_home != '.':
        bubble_home_abs = os.path.abspath(bubble_home)
    else:
        bubble_home_abs = os.path.abspath(os.getcwd())

    if cis == 'init':
        initing = True
    if initing:
        if not os.path.exists(bubble_home_abs):
            os.makedirs(bubble_home_abs)

    if os.path.exists(bubble_home_abs):
        os.chdir(bubble_home_abs)
        ctx.obj = BubbleCli(home=bubble_home_abs,
                            verbose=verbose,
                            verbose_bar=barverbose)
    else:
        click.echo('Bubble home path does not exist: ' + bubble_home_abs)
        raise click.Abort()

    BUBBLE_CLI_GLOBALS['full_command'] = ' '.join(sys.argv)

    for key, value in config:
        ctx.obj.set_config(key, value)
    if not ctx.obj.bubble and not initing:
        ctx.obj.say_yellow('There is no bubble in %s' %
                           bubble_home_abs, verbosity=10)
        ctx.obj.say('You can start one with: bubble init', verbosity=10)