mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Improve error handling when .idlerc can't be created.
This commit is contained in:
parent
d4f5b07e5d
commit
1b6f398c98
1 changed files with 16 additions and 14 deletions
|
@ -193,26 +193,28 @@ class IdleConf:
|
||||||
"""
|
"""
|
||||||
Creates (if required) and returns a filesystem directory for storing
|
Creates (if required) and returns a filesystem directory for storing
|
||||||
user config files.
|
user config files.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
cfgDir='.idlerc'
|
cfgDir = '.idlerc'
|
||||||
userDir=os.path.expanduser('~')
|
userDir = os.path.expanduser('~')
|
||||||
if userDir != '~': #'HOME' exists as a key in os.environ
|
if userDir != '~': # expanduser() found user home dir
|
||||||
if not os.path.exists(userDir):
|
if not os.path.exists(userDir):
|
||||||
warn=('\n Warning: HOME environment variable points to\n '+
|
warn = ('\n Warning: os.path.expanduser("~") points to\n '+
|
||||||
userDir+'\n but the path does not exist.\n')
|
userDir+',\n but the path does not exist.\n')
|
||||||
sys.stderr.write(warn)
|
sys.stderr.write(warn)
|
||||||
userDir='~'
|
userDir = '~'
|
||||||
if userDir=='~': #we still don't have a home directory
|
if userDir == "~": # still no path to home!
|
||||||
#traditionally idle has defaulted to os.getcwd(), is this adeqate?
|
# traditionally IDLE has defaulted to os.getcwd(), is this adequate?
|
||||||
userDir = os.getcwd() #hack for no real homedir
|
userDir = os.getcwd()
|
||||||
userDir=os.path.join(userDir,cfgDir)
|
userDir = os.path.join(userDir, cfgDir)
|
||||||
if not os.path.exists(userDir):
|
if not os.path.exists(userDir):
|
||||||
try: #make the config dir if it doesn't exist yet
|
try:
|
||||||
os.mkdir(userDir)
|
os.mkdir(userDir)
|
||||||
except IOError:
|
except (OSError, IOError):
|
||||||
warn=('\n Warning: unable to create user config directory\n '+
|
warn = ('\n Warning: unable to create user config directory\n'+
|
||||||
userDir+'\n')
|
userDir+'\n Check path and permissions.\n Exiting!\n\n')
|
||||||
sys.stderr.write(warn)
|
sys.stderr.write(warn)
|
||||||
|
raise SystemExit
|
||||||
return userDir
|
return userDir
|
||||||
|
|
||||||
def GetOption(self, configType, section, option, default=None, type=None,
|
def GetOption(self, configType, section, option, default=None, type=None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue