import yaml


def get_includes_from_file(file_path, package=''):
    """
    Retrieve a list of file to sync from and includes-file

    :param file_path: Path of the includes-file
    :type file_path: str
    :param package: Limit to file from this package
    :type package: str
    :returns: (a list of included files, a list of excluded files)
    :rtype: tuple[list, list]
    """
    includes = list()
    with open(file_path) as file:
        data = yaml.safe_load(file)
        for entry in data['exclude']:
            # --include is right here. No worries.
            includes.append('--include=- {}'.format(entry))
        for entry in data['include']:
            if isinstance(entry, dict):
                for folder, subfolders in entry.items():
                    if package == '':
                        includes.append('--include=+ {}'.format(folder))
                        for subfolder in subfolders:
                            includes.append('--include=+ {}/{}'.format(folder, subfolder))
                            includes.append('--include=+ {}/{}/**'.format(folder, subfolder))
                    elif package in subfolders:
                        includes.append('--include=+ {}'.format(folder))
                        includes.append('--include=+ {}/{}'.format(folder, package))
                        includes.append('--include=+ {}/{}/**'.format(folder, package))
            elif isinstance(entry, str):
                if package == '' or package == entry:
                    includes.append('--include=+ {}'.format(entry))
                    includes.append('--include=+ {}/**'.format(entry))
    includes.append('--include=- *')
    return includes