# Path: datapackage_pipelines/status/status_manager.py
# def status_mgr(root_dir='.') -> StatusManager:
#     global _status
#     global _root_dir
# 
#     if _status is not None and _root_dir == root_dir:
#         return _status
#     _root_dir = root_dir
#     _status = StatusManager(host=os.environ.get('DPP_REDIS_HOST'), root_dir=root_dir)
#     return _status
# 
# Path: datapackage_pipelines/utilities/stat_utils.py
# def user_facing_stats(stats):
#     if stats is not None and isinstance(stats, dict):
#         return dict((k, v) for k, v in stats.items() if k != STATS_DPP_KEY)
#     return None


import datetime
import os
import logging
import slugify
import yaml
import mistune
import requests
from io import BytesIO
from functools import wraps
from copy import deepcopy
from collections import Counter
from flask import \
    Blueprint, Flask, render_template, abort, send_file, make_response
from flask_cors import CORS
from flask_jsonpify import jsonify
from flask_basicauth import BasicAuth
from datapackage_pipelines.status import status_mgr
from datapackage_pipelines.utilities.stat_utils import user_facing_stats
                return basic_auth.challenge()
        else:
            return view_func(*args, **kwargs)
    return wrapper


blueprint = Blueprint('dpp', 'dpp')


@blueprint.route("")
@blueprint.route("<path:pipeline_path>")
@basic_auth_required
def main(pipeline_path=None):
    pipeline_ids = sorted(status.all_pipeline_ids())

    # If we have a pipeline_path, filter the pipeline ids.
    if pipeline_path is not None:
        if not pipeline_path.startswith('./'):
            pipeline_path = './' + pipeline_path

        pipeline_ids = [p for p in pipeline_ids if p.startswith(pipeline_path)]

    statuses = []
    for pipeline_id in pipeline_ids:
        pipeline_status = status.get(pipeline_id)
        ex = pipeline_status.get_last_execution()
        success_ex = pipeline_status.get_last_successful_execution()
        pipeline_obj = {
            'id': pipeline_id.lstrip('./'),
            'title': pipeline_status.pipeline_details.get('title'),

# Path: datapackage_pipelines/status/status_manager.py
# def status_mgr(root_dir='.') -> StatusManager:
#     global _status
#     global _root_dir
# 
#     if _status is not None and _root_dir == root_dir:
#         return _status
#     _root_dir = root_dir
#     _status = StatusManager(host=os.environ.get('DPP_REDIS_HOST'), root_dir=root_dir)
#     return _status
# 
# Path: datapackage_pipelines/utilities/stat_utils.py
# def user_facing_stats(stats):
#     if stats is not None and isinstance(stats, dict):
#         return dict((k, v) for k, v in stats.items() if k != STATS_DPP_KEY)
#     return None


# Path: datapackage_pipelines/web/server.py
import datetime
import os
import logging
import slugify
import yaml
import mistune
import requests
from io import BytesIO
from functools import wraps
from copy import deepcopy
from collections import Counter
from flask import \
    Blueprint, Flask, render_template, abort, send_file, make_response
from flask_cors import CORS
from flask_jsonpify import jsonify
from flask_basicauth import BasicAuth
from datapackage_pipelines.status import status_mgr
from datapackage_pipelines.utilities.stat_utils import user_facing_stats

                return basic_auth.challenge()
        else:
            return view_func(*args, **kwargs)
    return wrapper


blueprint = Blueprint('dpp', 'dpp')


@blueprint.route("")
@blueprint.route("<path:pipeline_path>")
@basic_auth_required
def main(pipeline_path=None):
    pipeline_ids = sorted(status.all_pipeline_ids())

    # If we have a pipeline_path, filter the pipeline ids.
    if pipeline_path is not None:
        if not pipeline_path.startswith('./'):
            pipeline_path = './' + pipeline_path

        pipeline_ids = [p for p in pipeline_ids if p.startswith(pipeline_path)]

    statuses = []
    for pipeline_id in pipeline_ids:
        pipeline_status = status.get(pipeline_id)
        ex = pipeline_status.get_last_execution()
        success_ex = pipeline_status.get_last_successful_execution()
        pipeline_obj = {
            'id': pipeline_id.lstrip('./'),
            'title': pipeline_status.pipeline_details.get('title'),

            'stats': user_facing_stats(ex.stats) if ex else None,