# Path: armada/const.py
# DOCUMENT_CHART = 'armada/Chart/v1'
# DOCUMENT_GROUP = 'armada/ChartGroup/v1'
# DOCUMENT_MANIFEST = 'armada/Manifest/v1'
# KEYWORD_ARMADA = 'armada'
# KEYWORD_PREFIX = 'release_prefix'
# KEYWORD_GROUPS = 'chart_groups'
# KEYWORD_CHARTS = 'chart_group'
# KEYWORD_RELEASE = 'release'
# DEFAULT_CHART_TIMEOUT = 3600
# STATUS_DEPLOYED = 'DEPLOYED'
# STATUS_FAILED = 'FAILED'
# DEFAULT_K8S_TIMEOUT = 300
# CONFIG_PATH = '/etc/armada'
# 
# Path: armada/exceptions/override_exceptions.py
# class OverrideException(base_exception.ArmadaBaseException):
# class InvalidOverrideTypeException(OverrideException):
# class InvalidOverrideFileException(OverrideException):
# class InvalidOverrideValueException(OverrideException):
# class UnknownDocumentOverrideException(OverrideException):
#     def __init__(self, override_type):
#     def __init__(self, filename):
#     def __init__(self, override_command):
#     def __init__(self, doc_type, doc_name):
# 
# Path: armada/utils/validate.py
# LOG = logging.getLogger(__name__)
# SCHEMAS = {}
# def _get_schema_dir():
# def _load_schemas():
# def _validate_armada_manifest(manifest):
# def validate_armada_manifests(documents):
# def validate_armada_document(document):
# def validate_armada_documents(documents):
# def validate_manifest_url(value):
# def validate_manifest_filepath(value):


import collections
import json
import yaml
from armada import const
from armada.exceptions import override_exceptions
from armada.utils import validate
    def __init__(self, documents, overrides=None, values=None):
        self.documents = documents
        self.overrides = overrides
        self.values = values

    def _load_yaml_file(self, doc):
        '''
        Retrieve yaml file as a dictionary.
        '''
        try:
            with open(doc) as f:
                return list(yaml.safe_load_all(f.read()))
        except IOError:
            raise override_exceptions.InvalidOverrideFileException(doc)

    def update(self, d, u):
        for k, v in u.items():
            if isinstance(v, collections.Mapping):
                r = self.update(d.get(k, {}), v)
                d[k] = r
            elif isinstance(v, str) and isinstance(d.get(k), (list, tuple)):
                d[k] = [x.strip() for x in v.split(',')]
            else:
                d[k] = u[k]
        return d

    def find_document_type(self, alias):
        if alias == 'chart_group':
            return const.DOCUMENT_GROUP
        if alias == 'chart':

# Path: armada/const.py
# DOCUMENT_CHART = 'armada/Chart/v1'
# DOCUMENT_GROUP = 'armada/ChartGroup/v1'
# DOCUMENT_MANIFEST = 'armada/Manifest/v1'
# KEYWORD_ARMADA = 'armada'
# KEYWORD_PREFIX = 'release_prefix'
# KEYWORD_GROUPS = 'chart_groups'
# KEYWORD_CHARTS = 'chart_group'
# KEYWORD_RELEASE = 'release'
# DEFAULT_CHART_TIMEOUT = 3600
# STATUS_DEPLOYED = 'DEPLOYED'
# STATUS_FAILED = 'FAILED'
# DEFAULT_K8S_TIMEOUT = 300
# CONFIG_PATH = '/etc/armada'
# 
# Path: armada/exceptions/override_exceptions.py
# class OverrideException(base_exception.ArmadaBaseException):
# class InvalidOverrideTypeException(OverrideException):
# class InvalidOverrideFileException(OverrideException):
# class InvalidOverrideValueException(OverrideException):
# class UnknownDocumentOverrideException(OverrideException):
#     def __init__(self, override_type):
#     def __init__(self, filename):
#     def __init__(self, override_command):
#     def __init__(self, doc_type, doc_name):
# 
# Path: armada/utils/validate.py
# LOG = logging.getLogger(__name__)
# SCHEMAS = {}
# def _get_schema_dir():
# def _load_schemas():
# def _validate_armada_manifest(manifest):
# def validate_armada_manifests(documents):
# def validate_armada_document(document):
# def validate_armada_documents(documents):
# def validate_manifest_url(value):
# def validate_manifest_filepath(value):


# Path: armada/handlers/override.py
import collections
import json
import yaml
from armada import const
from armada.exceptions import override_exceptions
from armada.utils import validate

    def __init__(self, documents, overrides=None, values=None):
        self.documents = documents
        self.overrides = overrides
        self.values = values

    def _load_yaml_file(self, doc):
        '''
        Retrieve yaml file as a dictionary.
        '''
        try:
            with open(doc) as f:
                return list(yaml.safe_load_all(f.read()))
        except IOError:
            raise override_exceptions.InvalidOverrideFileException(doc)

    def update(self, d, u):
        for k, v in u.items():
            if isinstance(v, collections.Mapping):
                r = self.update(d.get(k, {}), v)
                d[k] = r
            elif isinstance(v, str) and isinstance(d.get(k), (list, tuple)):
                d[k] = [x.strip() for x in v.split(',')]
            else:
                d[k] = u[k]
        return d

    def find_document_type(self, alias):
        if alias == 'chart_group':
            return const.DOCUMENT_GROUP
        if alias == 'chart':

            return const.DOCUMENT_CHART