'Creates (if required) and returns a filesystem directory for storing
user config files.'

def GetUserCfgDir(self):

    cfgDir = '.idlerc'
    userDir = os.path.expanduser('~')
    if (userDir != '~'):
        if (not os.path.exists(userDir)):
            warn = (('\n    Warning:    os.path.expanduser("~")    points    to\n    ' + userDir) + ',\n    but    the    path    does    not    exist.\n')
            try:
                sys.stderr.write(warn)
            except IOError:
                pass
            userDir = '~'
    if (userDir == '~'):
        userDir = os.getcwd()
    userDir = os.path.join(userDir, cfgDir)
    if (not os.path.exists(userDir)):
        try:
            os.mkdir(userDir)
        except (OSError, IOError):
            warn = (('\n    Warning:    unable    to    create    user    config    directory\n' + userDir) + '\n    Check    path    and    permissions.\n    Exiting!\n\n')
            sys.stderr.write(warn)
            raise SystemExit
    return userDir
