import configparser
import os


# name of user specific config file
CONFIGFILE = "solthermpi.ini"


def init_config():
    """
    Returns ConfigParser object
    """
    home = os.path.expanduser("~")

    configfile = os.path.join(home, CONFIGFILE)
    here = os.path.dirname(os.path.realpath(__file__))
    configfile_defaults = os.path.join(here, "defaultconfig.ini")

    config = configparser.ConfigParser()
    # set HOME dynamically
    config["GENERAL"] = {
        "HOME": home,
    }
    # read config file with defaults
    with open(configfile_defaults, "r") as f:
        config.read_file(f)
    # overwrite them with custom config file (if any)
    config.read(configfile)

    return config


config = init_config()
