diff -r 8e42f11bd5ee Lib/idlelib/configHandler.py --- a/Lib/idlelib/configHandler.py Tue Oct 27 03:38:02 2015 -0400 +++ b/Lib/idlelib/configHandler.py Wed Oct 28 02:21:26 2015 -0400 @@ -20,11 +20,28 @@ import os import sys +import shutil # shutil, tempfile, weakref for TempDir +import tempfile +import weakref from configparser import ConfigParser from tkinter import TkVersion from tkinter.font import Font, nametofont +class TempDir(): + """Reduce tempfile.TemporaryDirectory to exit cleanup. + + t.TK is not in 2.7, don't need args, context manager, or warning. + A reference must be kept to the instance, not just its name. + """ + def __init__(self): + self.name = tempfile.mkdtemp() + self._finalizer = weakref.finalize( + self, self._cleanup, self.name) + @classmethod + def _cleanup(cls, name): + shutil.rmtree(name) + class InvalidConfigType(Exception): pass class InvalidConfigSet(Exception): pass class InvalidFgBg(Exception): pass @@ -205,11 +222,18 @@ try: os.mkdir(userDir) except OSError: - warn = ('\n Warning: unable to create user config directory\n' + - userDir + '\n Check path and permissions.\n Exiting!\n') - print(warn, file=sys.stderr) - raise SystemExit - # TODO continue without userDIr instead of exit + baddir = userDir + t = self._temp_userdir = TempDir() + userDir = os.path.join(t.name, cfgDir) + warn = ("\n Warning: cannot create user config directory\n" + "%s\Trying temporary directory\n%s\n" + "This will be deleted when IDLE exits." + % (baddir, userDir)) + try: + print(warn, file=sys.stderr) + except OSError: + pass + os.mkdir(userDir) return userDir def GetOption(self, configType, section, option, default=None, type=None,