# Path: pubs/config/spec.py



import os
import platform
import configobj
import validate
from .spec import configspec
            from .. import uis


def get_confpath(verify=True):
    """Return the configuration filepath
    If verify is True, verify that the file exists and exit with an error if not.
    """
    confpath = DFT_CONFIG_PATH
    if 'PUBSCONF' in os.environ:
        confpath = os.path.abspath(os.path.expanduser(os.environ['PUBSCONF']))
    if verify:
        if not os.path.isfile(confpath):
            ui = uis.get_ui()
            ui.error('configuration file not found at `{}`'.format(confpath))
            ui.exit(error_code=1)
    return confpath


def check_conf(conf):
    """Type check a configuration"""
    validator = validate.Validator()
    results = conf.validate(validator, copy=True)
    assert (results is True), '{}'.format(results)  # TODO: precise error dialog when parsing error


def load_conf(path=None):
    """Load the configuration"""
    if path is None:
        path = get_confpath(verify=True)
    if not os.path.exists(path):
        raise ConfigurationNotFound(path)

# Path: pubs/config/spec.py



# Path: pubs/config/conf.py
import os
import platform
import configobj
import validate
from .spec import configspec
            from .. import uis



def get_confpath(verify=True):
    """Return the configuration filepath
    If verify is True, verify that the file exists and exit with an error if not.
    """
    confpath = DFT_CONFIG_PATH
    if 'PUBSCONF' in os.environ:
        confpath = os.path.abspath(os.path.expanduser(os.environ['PUBSCONF']))
    if verify:
        if not os.path.isfile(confpath):
            ui = uis.get_ui()
            ui.error('configuration file not found at `{}`'.format(confpath))
            ui.exit(error_code=1)
    return confpath


def check_conf(conf):
    """Type check a configuration"""
    validator = validate.Validator()
    results = conf.validate(validator, copy=True)
    assert (results is True), '{}'.format(results)  # TODO: precise error dialog when parsing error


def load_conf(path=None):
    """Load the configuration"""
    if path is None:
        path = get_confpath(verify=True)
    if not os.path.exists(path):
        raise ConfigurationNotFound(path)

    conf = configobj.ConfigObj(path, configspec=configspec)