# Path: staticsites/conf_dict.py
# class DeployTypes(BaseDict):
#     """
#     Use this dictionary for discriminate config by deploy_type
#     """
#     pass
# 
# Path: staticsites/utilities.py
# def invalidate_paths(deploy_type, paths, *args, **kwargs):
#     """
#     Helper function, create an invalidation request for CloudFront distribution
#     :param deploy_type: The deploy type
#     :param paths: The paths array
#     """
#     from boto.cloudfront import CloudFrontConnection
#     
#     # TODO chunking invalidation to prevent error
#     distributions = get_conf('AWS_DISTRIBUTION_ID', deploy_type=deploy_type)
# 
#     if isinstance(distributions, list):
#         distributions = distributions
#     else:
#         distributions = [distributions]
# 
#     for distribution in distributions:
#         conn_cf = CloudFrontConnection(get_conf('AWS_ACCESS_KEY_ID',  deploy_type=deploy_type),
#                                        get_conf('AWS_SECRET_ACCESS_KEY',  deploy_type=deploy_type))
#         conn_cf.create_invalidation_request(distribution, paths)


import os
import environ
from staticsites.conf_dict import DeployTypes
from django.core.files.storage import FileSystemStorage
from storages.backends.s3boto import S3BotoStorage
from staticsites.utilities import invalidate_paths
USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/

STATIC_URL = '/static/'

# S3BotoStorage configuration
AWS_ACCESS_KEY_ID = env('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = env('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = env('AWS_STORAGE_BUCKET_NAME')

# Sample configuration

STATICSITE_DEPLOY_ROOT = DeployTypes({
    'dev': 'deploy/%(deploy_type)s',
    '': 'deploy/%(deploy_type)s/%(asctime)s',
    'test': '/',
    'prod': '/',
})

STATICSITE_DEFAULT_FILE_STORAGE = DeployTypes({
    '': FileSystemStorage,
    'test': (S3BotoStorage, {'bucket': env('AWS_CLOUDFRONT_TEST_DISTRIBUTION_ID'), 'headers': {'Content-Encoding': 'gzip'}}),
    'prod': (S3BotoStorage, {'bucket': env('AWS_CLOUDFRONT_PROD_DISTRIBUTION_ID'), 'headers': {'Content-Encoding': 'gzip'}}),
})


# Path: staticsites/conf_dict.py
# class DeployTypes(BaseDict):
#     """
#     Use this dictionary for discriminate config by deploy_type
#     """
#     pass
# 
# Path: staticsites/utilities.py
# def invalidate_paths(deploy_type, paths, *args, **kwargs):
#     """
#     Helper function, create an invalidation request for CloudFront distribution
#     :param deploy_type: The deploy type
#     :param paths: The paths array
#     """
#     from boto.cloudfront import CloudFrontConnection
#     
#     # TODO chunking invalidation to prevent error
#     distributions = get_conf('AWS_DISTRIBUTION_ID', deploy_type=deploy_type)
# 
#     if isinstance(distributions, list):
#         distributions = distributions
#     else:
#         distributions = [distributions]
# 
#     for distribution in distributions:
#         conn_cf = CloudFrontConnection(get_conf('AWS_ACCESS_KEY_ID',  deploy_type=deploy_type),
#                                        get_conf('AWS_SECRET_ACCESS_KEY',  deploy_type=deploy_type))
#         conn_cf.create_invalidation_request(distribution, paths)


# Path: staticsites/tests/samples/04_aws_multiple_deploy_type/settings.py
import os
import environ
from staticsites.conf_dict import DeployTypes
from django.core.files.storage import FileSystemStorage
from storages.backends.s3boto import S3BotoStorage
from staticsites.utilities import invalidate_paths

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/

STATIC_URL = '/static/'

# S3BotoStorage configuration
AWS_ACCESS_KEY_ID = env('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = env('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = env('AWS_STORAGE_BUCKET_NAME')

# Sample configuration

STATICSITE_DEPLOY_ROOT = DeployTypes({
    'dev': 'deploy/%(deploy_type)s',
    '': 'deploy/%(deploy_type)s/%(asctime)s',
    'test': '/',
    'prod': '/',
})

STATICSITE_DEFAULT_FILE_STORAGE = DeployTypes({
    '': FileSystemStorage,
    'test': (S3BotoStorage, {'bucket': env('AWS_CLOUDFRONT_TEST_DISTRIBUTION_ID'), 'headers': {'Content-Encoding': 'gzip'}}),
    'prod': (S3BotoStorage, {'bucket': env('AWS_CLOUDFRONT_PROD_DISTRIBUTION_ID'), 'headers': {'Content-Encoding': 'gzip'}}),
})


STATICSITE_AFTER_DEPLOY = DeployTypes({'': None, 'test': invalidate_paths, 'prod': invalidate_paths})