import logging
import yaml


def Export(omnicache, exportPath):
    """Exports omnicache configuration to YAML"""
    logging.info("Exporting omnicache config for {0} to {1}".format(omnicache.path, exportPath))
    content = []
    for (name, data) in omnicache.GetRemoteData().items():
        remoteToWrite = {"url": data["url"]}
        if ("displayname" in data):
            remoteToWrite["name"] = data["displayname"]
        else:
            remoteToWrite["name"] = name
        content.append(remoteToWrite)

    with open(exportPath, "w") as ocf:
        yaml.dump({"remotes": content}, ocf)

    return 0