# Path: pacman_mirrors/functions/defaultFn.py
# def load_config_mirror_pool(self):
# def load_default_mirror_pool(self):
# def seed_mirrors(self, file, status=False):
# def sort_mirror_countries(self):
# 
# Path: pacman_mirrors/functions/fileFn.py
# def check_existance_of(filename, folder=False):
# def create_dir(foldername):
# def delete_file(filename):
# def return_mirror_filename(config):
# def write_mirror_list(config, servers, custom=False,
#                       quiet=False, interactive=False):
# def read_mirror_file(filename):
# def write_mirrorlist_header(handle, custom=False):
# def write_mirrorlist_entry(handle, mirror):
# 
# Path: pacman_mirrors/functions/jsonFn.py
# def json_dump_file(data, filename):
# def read_json_file(filename, dictionary=True):
# def write_json_file(data, filename, dictionary=False):
# 
# Path: pacman_mirrors/functions/validFn.py
# def custom_config_is_valid():
# def country_list_is_valid(onlycountry, countrylist):


from pacman_mirrors.functions import defaultFn
from pacman_mirrors.functions import fileFn
from pacman_mirrors.functions import jsonFn
from pacman_mirrors.functions import validFn
"""Pacman-Mirrors Custom Pool/Mirror Functions"""



def apply_status_to_custom_mirror_pool(config, custom_pool):
    """
    Apply the current mirror status to the custom mirror file
    :param config: config dictionary
    :param custom_pool: the custom mirror pool
    :return: custom mirror pool with status applied
    """
    status_list = tuple(jsonFn.read_json_file(config["status_file"], dictionary=False))
    custom_list = tuple(custom_pool)
    try:
        _ = status_list[0]
        for custom in custom_list:
            for status in status_list:
                if custom["url"] in status["url"]:
                    custom["last_sync"] = status["last_sync"]
                    custom["branches"] = status["branches"]
        return list(custom_list)
    except (IndexError, KeyError):
        return custom_pool


def check_custom_mirror_pool(self):
    """
    Custom mirror pool or countries from CLI
    :return: True/False
    """

# Path: pacman_mirrors/functions/defaultFn.py
# def load_config_mirror_pool(self):
# def load_default_mirror_pool(self):
# def seed_mirrors(self, file, status=False):
# def sort_mirror_countries(self):
# 
# Path: pacman_mirrors/functions/fileFn.py
# def check_existance_of(filename, folder=False):
# def create_dir(foldername):
# def delete_file(filename):
# def return_mirror_filename(config):
# def write_mirror_list(config, servers, custom=False,
#                       quiet=False, interactive=False):
# def read_mirror_file(filename):
# def write_mirrorlist_header(handle, custom=False):
# def write_mirrorlist_entry(handle, mirror):
# 
# Path: pacman_mirrors/functions/jsonFn.py
# def json_dump_file(data, filename):
# def read_json_file(filename, dictionary=True):
# def write_json_file(data, filename, dictionary=False):
# 
# Path: pacman_mirrors/functions/validFn.py
# def custom_config_is_valid():
# def country_list_is_valid(onlycountry, countrylist):


# Path: pacman_mirrors/functions/customFn.py
from pacman_mirrors.functions import defaultFn
from pacman_mirrors.functions import fileFn
from pacman_mirrors.functions import jsonFn
from pacman_mirrors.functions import validFn

"""Pacman-Mirrors Custom Pool/Mirror Functions"""



def apply_status_to_custom_mirror_pool(config, custom_pool):
    """
    Apply the current mirror status to the custom mirror file
    :param config: config dictionary
    :param custom_pool: the custom mirror pool
    :return: custom mirror pool with status applied
    """
    status_list = tuple(jsonFn.read_json_file(config["status_file"], dictionary=False))
    custom_list = tuple(custom_pool)
    try:
        _ = status_list[0]
        for custom in custom_list:
            for status in status_list:
                if custom["url"] in status["url"]:
                    custom["last_sync"] = status["last_sync"]
                    custom["branches"] = status["branches"]
        return list(custom_list)
    except (IndexError, KeyError):
        return custom_pool


def check_custom_mirror_pool(self):
    """
    Custom mirror pool or countries from CLI
    :return: True/False
    """

    if validFn.custom_config_is_valid():