# 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




YAML_DUMPER = yaml.CDumper if 'CDumper' in yaml.__dict__ else yaml.Dumper


def datestr(x):
    if x is None:
        return ''
    return str(datetime.datetime.fromtimestamp(x))


def yamlize(x):
    ret = yaml.dump(x, default_flow_style=False, Dumper=YAML_DUMPER)
    return ret


markdown = mistune.Markdown(hard_wrap=True)

# 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





YAML_DUMPER = yaml.CDumper if 'CDumper' in yaml.__dict__ else yaml.Dumper


def datestr(x):
    if x is None:
        return ''
    return str(datetime.datetime.fromtimestamp(x))


def yamlize(x):
    ret = yaml.dump(x, default_flow_style=False, Dumper=YAML_DUMPER)
    return ret


markdown = mistune.Markdown(hard_wrap=True)

status = status_mgr()