'Get the path to the user configuration directory. The
directory is guaranteed to exist as a postcondition (one may be
created if none exist).
If the application\'s ``...DIR`` environment variable is set, it
is used as the configuration directory. Otherwise,
platform-specific standard configuration locations are searched
for a ``config.yaml`` file. If no configuration file is found, a
fallback path is used.'

def config_dir(self):

    if (self._env_var in os.environ):
        appdir = os.environ[self._env_var]
        appdir = os.path.abspath(os.path.expanduser(appdir))
        if os.path.isfile(appdir):
            raise ConfigError(u'{0}    must    be    a    directory'.format(self._env_var))
    else:
        for confdir in config_dirs():
            appdir = os.path.join(confdir, self.appname)
            if os.path.isfile(os.path.join(appdir, CONFIG_FILENAME)):
                break
    if (not os.path.isdir(appdir)):
        os.makedirs(appdir)
    return appdir
