# Path: statik/errors.py
# class ProjectConfigurationError(StatikError):
#     """For generic project configuration-related errors."""
#     error_kind = "Project configuration error"
#     exit_code = 2
# 
# class DeploymentError(StatikError):
#     """For errors relating to deployment of built projects."""
#     error_kind = "Deployment-related error"
#     exit_code = 9
# 
# Path: statik/deploy/base.py
# class DeploymentMethod(object):
#     """An abstract method for handling deployment."""
# 
#     def __init__(self, config, error_context=None):
#         """Must validate the given configuration for this deployment method and raise an exception
#         if it's invalid."""
#         raise NotImplementedError
# 
#     def execute(self, source_path):
#         """Must actually execute the implemented deployment method."""
#         raise NotImplementedError


import os
import os.path
import requests
import hashlib
import time
import json
import logging
from collections import OrderedDict, namedtuple
from datetime import datetime
from dateutil.parser import parse as dateutil_parse
from urllib.parse import quote as urllib_quote
from ..errors import ProjectConfigurationError, DeploymentError
from .base import DeploymentMethod


logger = logging.getLogger(__name__)


ENVVAR_NETLIFY_SITE_ID = 'NETLIFY_SITE_ID'
ENVVAR_NETLIFY_AUTH_TOKEN = 'NETLIFY_AUTH_TOKEN'
NETLIFY_API_ROOT = 'https://api.netlify.com/api/v1'


DeploymentFile = namedtuple('DeploymentFile', ['path', 'url', 'sha1sum'])


class Netlify(DeploymentMethod):

    def __init__(self, config, error_context=None):
        if not isinstance(config, dict):
            raise ProjectConfigurationError(
                message="Netlify deployment configuration must be a key/value pair mapping",
                context=error_context,
            )

        if 'site_id' not in config and ENVVAR_NETLIFY_SITE_ID not in os.environ:
            raise ProjectConfigurationError(
                message="Netlify deployment requires \"site_id\" parameter to be specified in project " +
                    "configuration or \"%s\" environment variable to be set" % ENVVAR_NETLIFY_SITE_ID,
                context=error_context,
            )

        if 'auth_token' not in config and ENVVAR_NETLIFY_AUTH_TOKEN not in os.environ:

# Path: statik/errors.py
# class ProjectConfigurationError(StatikError):
#     """For generic project configuration-related errors."""
#     error_kind = "Project configuration error"
#     exit_code = 2
# 
# class DeploymentError(StatikError):
#     """For errors relating to deployment of built projects."""
#     error_kind = "Deployment-related error"
#     exit_code = 9
# 
# Path: statik/deploy/base.py
# class DeploymentMethod(object):
#     """An abstract method for handling deployment."""
# 
#     def __init__(self, config, error_context=None):
#         """Must validate the given configuration for this deployment method and raise an exception
#         if it's invalid."""
#         raise NotImplementedError
# 
#     def execute(self, source_path):
#         """Must actually execute the implemented deployment method."""
#         raise NotImplementedError


# Path: statik/deploy/netlify.py
import os
import os.path
import requests
import hashlib
import time
import json
import logging
from collections import OrderedDict, namedtuple
from datetime import datetime
from dateutil.parser import parse as dateutil_parse
from urllib.parse import quote as urllib_quote
from ..errors import ProjectConfigurationError, DeploymentError
from .base import DeploymentMethod



logger = logging.getLogger(__name__)


ENVVAR_NETLIFY_SITE_ID = 'NETLIFY_SITE_ID'
ENVVAR_NETLIFY_AUTH_TOKEN = 'NETLIFY_AUTH_TOKEN'
NETLIFY_API_ROOT = 'https://api.netlify.com/api/v1'


DeploymentFile = namedtuple('DeploymentFile', ['path', 'url', 'sha1sum'])


class Netlify(DeploymentMethod):

    def __init__(self, config, error_context=None):
        if not isinstance(config, dict):
            raise ProjectConfigurationError(
                message="Netlify deployment configuration must be a key/value pair mapping",
                context=error_context,
            )

        if 'site_id' not in config and ENVVAR_NETLIFY_SITE_ID not in os.environ:
            raise ProjectConfigurationError(
                message="Netlify deployment requires \"site_id\" parameter to be specified in project " +
                    "configuration or \"%s\" environment variable to be set" % ENVVAR_NETLIFY_SITE_ID,
                context=error_context,
            )

        if 'auth_token' not in config and ENVVAR_NETLIFY_AUTH_TOKEN not in os.environ:

            raise ProjectConfigurationError(