# Path: drift/utils.py
# def get_config(ts=None, tier_name=None, tenant_name=None):
#     """Wraps get_drift_config() by providing default values for tier, tenant and drift_app."""
#     # Hack: Must delay import this
#     # TODO: Stop using this function. Who is doing it anyways?
#     from drift.flaskfactory import load_flask_config
#     if current_app:
#         app_ts = current_app.extensions['driftconfig'].table_store
#         if ts is not app_ts:
#             log.warning("Mismatching table_store objects in get_config(): ts=%s, app ts=%s", ts, app_ts)
#         ts = app_ts
# 
#     conf = get_drift_config(
#         ts=ts,
#         tier_name=tier_name or get_tier_name(),
#         tenant_name=tenant_name or tenant_from_hostname,
#         drift_app=load_flask_config(),
#     )
#     return conf
# 
# def pretty(ob, lexer=None):
#     """
#     Return a pretty console text representation of 'ob'.
#     If 'ob' is something else than plain text, specify it in 'lexer'.
# 
#     If 'ob' is not string, Json lexer is assumed.
# 
#     If 'pretty.unicorns' are enabled, the world is a happier place.
# 
#     Command line switches can be used to control highlighting and style.
#     """
#     if lexer is None:
#         if isinstance(ob, six.string_types):
#             lexer = 'text'
#         else:
#             lexer = 'json'
# 
#     if lexer == 'json':
#         ob = json.dumps(ob, indent=4, sort_keys=True)
# 
#     if got_pygments:
#         lexerob = get_lexer_by_name(lexer)
#         formatter = get_formatter_by_name(PRETTY_FORMATTER, style=PRETTY_STYLE)
#         # from pygments.filters import *
#         # lexerob.add_filter(VisibleWhitespaceFilter(spaces=True, tabs=True, newlines=True))
#         ret = highlight(ob, lexerob, formatter)
#     else:
#         if pretty.unicorns:
#             pretty.unicorns = False
#             print(textwrap.dedent("""\
# 
# 
#                 Note! All this blurb would look much better with colors!.
#                 "Plese Run the following command for the sake of rainbows and unicorns:
#                 "pip install pygments
# 
#                 """))
# 
#         ret = ob
# 
#     return ret.rstrip()


import sys
import os
import os.path
import subprocess
import time
import shutil
import yaml
import json
import boto3
import click
from click import echo, secho
from jinja2 import Environment, FileSystemLoader
from driftconfig.config import get_redis_cache_backend
from drift.utils import get_config, pretty
    template_args = {
        'tier': {
            'tier_name': tier_name,
            'config_url': config_url,
            'aws_region': aws_region,
            'vpc_id': vpc_id,
            'security_groups': security_groups,
            'subnets': subnet_ids,
            's3_bucket': tier['resources']['drift.core.resources.awsdeploy']['s3_bucket'],
        },
        'deployable': {'deployable_name': conf.drift_app['name']},
        'apihandler': conf.drift_app.get('apihandler', 'drift.contrib.aws.lambdawsgi.handler'),
        'events': [],
        'log_forwarding_arn': log_forwarding_arn,
        'offline': offline,
    }

    if not template_args['apihandler'] and not template_args['events']:
        secho("Warning: Neither apihandler nor events defined. Nothing to do really.", fg='yellow')
        sys.exit(1)

    # Generate the serverless.yml configuration file
    secho("Generating serverless.yml")
    env = Environment(loader=FileSystemLoader(searchpath=os.path.dirname(__file__)))
    template = env.get_template('serverless.jinja.yml')
    serverless_yaml = template.render(**template_args)
    sls_config = yaml.load(serverless_yaml)

    if verbose:
        secho("\n-------- Template parameters: --------\n", bold=True)

# Path: drift/utils.py
# def get_config(ts=None, tier_name=None, tenant_name=None):
#     """Wraps get_drift_config() by providing default values for tier, tenant and drift_app."""
#     # Hack: Must delay import this
#     # TODO: Stop using this function. Who is doing it anyways?
#     from drift.flaskfactory import load_flask_config
#     if current_app:
#         app_ts = current_app.extensions['driftconfig'].table_store
#         if ts is not app_ts:
#             log.warning("Mismatching table_store objects in get_config(): ts=%s, app ts=%s", ts, app_ts)
#         ts = app_ts
# 
#     conf = get_drift_config(
#         ts=ts,
#         tier_name=tier_name or get_tier_name(),
#         tenant_name=tenant_name or tenant_from_hostname,
#         drift_app=load_flask_config(),
#     )
#     return conf
# 
# def pretty(ob, lexer=None):
#     """
#     Return a pretty console text representation of 'ob'.
#     If 'ob' is something else than plain text, specify it in 'lexer'.
# 
#     If 'ob' is not string, Json lexer is assumed.
# 
#     If 'pretty.unicorns' are enabled, the world is a happier place.
# 
#     Command line switches can be used to control highlighting and style.
#     """
#     if lexer is None:
#         if isinstance(ob, six.string_types):
#             lexer = 'text'
#         else:
#             lexer = 'json'
# 
#     if lexer == 'json':
#         ob = json.dumps(ob, indent=4, sort_keys=True)
# 
#     if got_pygments:
#         lexerob = get_lexer_by_name(lexer)
#         formatter = get_formatter_by_name(PRETTY_FORMATTER, style=PRETTY_STYLE)
#         # from pygments.filters import *
#         # lexerob.add_filter(VisibleWhitespaceFilter(spaces=True, tabs=True, newlines=True))
#         ret = highlight(ob, lexerob, formatter)
#     else:
#         if pretty.unicorns:
#             pretty.unicorns = False
#             print(textwrap.dedent("""\
# 
# 
#                 Note! All this blurb would look much better with colors!.
#                 "Plese Run the following command for the sake of rainbows and unicorns:
#                 "pip install pygments
# 
#                 """))
# 
#         ret = ob
# 
#     return ret.rstrip()


# Path: scripts/sls-deploy.py
import sys
import os
import os.path
import subprocess
import time
import shutil
import yaml
import json
import boto3
import click
from click import echo, secho
from jinja2 import Environment, FileSystemLoader
from driftconfig.config import get_redis_cache_backend
from drift.utils import get_config, pretty

    template_args = {
        'tier': {
            'tier_name': tier_name,
            'config_url': config_url,
            'aws_region': aws_region,
            'vpc_id': vpc_id,
            'security_groups': security_groups,
            'subnets': subnet_ids,
            's3_bucket': tier['resources']['drift.core.resources.awsdeploy']['s3_bucket'],
        },
        'deployable': {'deployable_name': conf.drift_app['name']},
        'apihandler': conf.drift_app.get('apihandler', 'drift.contrib.aws.lambdawsgi.handler'),
        'events': [],
        'log_forwarding_arn': log_forwarding_arn,
        'offline': offline,
    }

    if not template_args['apihandler'] and not template_args['events']:
        secho("Warning: Neither apihandler nor events defined. Nothing to do really.", fg='yellow')
        sys.exit(1)

    # Generate the serverless.yml configuration file
    secho("Generating serverless.yml")
    env = Environment(loader=FileSystemLoader(searchpath=os.path.dirname(__file__)))
    template = env.get_template('serverless.jinja.yml')
    serverless_yaml = template.render(**template_args)
    sls_config = yaml.load(serverless_yaml)

    if verbose:
        secho("\n-------- Template parameters: --------\n", bold=True)

        secho(pretty(template_args, 'json'))