# Path: distgen/config.py
# def merge_yaml(origin, override):
#     old = copy.deepcopy(origin)
#     new = copy.deepcopy(override)
#     return _merge_yaml(old, new)
# 
# Path: distgen/pathmanager.py
# class PathManager(object):
#     envvar = None
# 
#     def __init__(self, path, envvar=None, file_suffix=None):
#         self.path = path
#         self.envvar = envvar
#         self.suffix = file_suffix
# 
#     def get_file(self, filename, prefered_path=None, fail=False,
#                  file_desc="file"):
# 
#         if filename.startswith('/'):
#             if os.path.isfile(filename):
#                 return filename
#             else:
#                 return None
# 
#         path = self.get_path()
#         if prefered_path:
#             path = prefered_path + path
# 
#         for i in path:
#             config_files = [os.path.join(i, filename)]
#             if self.suffix:
#                 config_files.append(config_files[0] + self.suffix)
#             for cf in config_files:
#                 if os.path.isfile(cf):
#                     return cf
# 
#         if fail:
#             fatal("can't find {0} '{1}'".format(file_desc, filename))
# 
#         return None
# 
#     def open_file(self, relative, prefered_path=None,
#                   fail=False, file_desc="file"):
# 
#         filename = self.get_file(relative, prefered_path, fail=fail,
#                                  file_desc=file_desc)
#         if not filename:
#             return None
# 
#         try:
#             fd = open(filename)
#         except IOError:
#             if fail:
#                 fatal("can't open file {0}".format(relative))
#             return None
# 
#         return fd
# 
#     def get_path(self):
#         path = self.path
#         if self.envvar and self.envvar in os.environ:
#             env_path = os.environ[self.envvar].split(':')
#             path = env_path + path
# 
#         return [os.getcwd()] + path


import copy
import itertools
import os
import yaml
from distgen.config import merge_yaml
from distgen.pathmanager import PathManager

        # second, verify that these selector values are not excluded by matrix
        if any([v for v in self.check_matrix_combinations('exclude',
                                                          distro,
                                                          parsed_selectors)]):
            return False, 'This combination is excluded in matrix section'

        # third, make sure we have a distroinfo section that contains
        # passed distro
        if not self.get_distroinfos_by_distro(distro):
            msg = (
                '"{0}" distro not found in any '
                'specs.distroinfo.*.distros section'.format(distro)
            )
            return (False, msg)

        return True, ''

    def select_data(self, selectors, distrofile):
        distro = self.distrofile2name(distrofile)
        allowed, reason = self.verify_selectors(selectors, distro)
        if not allowed:
            raise MultispecError(reason)

        parsed_selectors = self.parse_selectors(selectors)
        selected_data = {}

        for selector_name, selector_val in parsed_selectors.items():
            spec_content = self.get_spec_group_item(
                selector_name, selector_val)

# Path: distgen/config.py
# def merge_yaml(origin, override):
#     old = copy.deepcopy(origin)
#     new = copy.deepcopy(override)
#     return _merge_yaml(old, new)
# 
# Path: distgen/pathmanager.py
# class PathManager(object):
#     envvar = None
# 
#     def __init__(self, path, envvar=None, file_suffix=None):
#         self.path = path
#         self.envvar = envvar
#         self.suffix = file_suffix
# 
#     def get_file(self, filename, prefered_path=None, fail=False,
#                  file_desc="file"):
# 
#         if filename.startswith('/'):
#             if os.path.isfile(filename):
#                 return filename
#             else:
#                 return None
# 
#         path = self.get_path()
#         if prefered_path:
#             path = prefered_path + path
# 
#         for i in path:
#             config_files = [os.path.join(i, filename)]
#             if self.suffix:
#                 config_files.append(config_files[0] + self.suffix)
#             for cf in config_files:
#                 if os.path.isfile(cf):
#                     return cf
# 
#         if fail:
#             fatal("can't find {0} '{1}'".format(file_desc, filename))
# 
#         return None
# 
#     def open_file(self, relative, prefered_path=None,
#                   fail=False, file_desc="file"):
# 
#         filename = self.get_file(relative, prefered_path, fail=fail,
#                                  file_desc=file_desc)
#         if not filename:
#             return None
# 
#         try:
#             fd = open(filename)
#         except IOError:
#             if fail:
#                 fatal("can't open file {0}".format(relative))
#             return None
# 
#         return fd
# 
#     def get_path(self):
#         path = self.path
#         if self.envvar and self.envvar in os.environ:
#             env_path = os.environ[self.envvar].split(':')
#             path = env_path + path
# 
#         return [os.getcwd()] + path


# Path: distgen/multispec.py
import copy
import itertools
import os
import yaml
from distgen.config import merge_yaml
from distgen.pathmanager import PathManager


        # second, verify that these selector values are not excluded by matrix
        if any([v for v in self.check_matrix_combinations('exclude',
                                                          distro,
                                                          parsed_selectors)]):
            return False, 'This combination is excluded in matrix section'

        # third, make sure we have a distroinfo section that contains
        # passed distro
        if not self.get_distroinfos_by_distro(distro):
            msg = (
                '"{0}" distro not found in any '
                'specs.distroinfo.*.distros section'.format(distro)
            )
            return (False, msg)

        return True, ''

    def select_data(self, selectors, distrofile):
        distro = self.distrofile2name(distrofile)
        allowed, reason = self.verify_selectors(selectors, distro)
        if not allowed:
            raise MultispecError(reason)

        parsed_selectors = self.parse_selectors(selectors)
        selected_data = {}

        for selector_name, selector_val in parsed_selectors.items():
            spec_content = self.get_spec_group_item(
                selector_name, selector_val)

            selected_data = merge_yaml(selected_data, spec_content)