diff options
author | Steven M. Gava <elguavas@python.net> | 2002-02-01 03:02:37 (GMT) |
---|---|---|
committer | Steven M. Gava <elguavas@python.net> | 2002-02-01 03:02:37 (GMT) |
commit | 7cff66d46972847b27f06831d7b0014b1ecdc2b2 (patch) | |
tree | 737acaa8fbc64e8311dee55f2c3e0d71b96827d8 /Lib | |
parent | a498af269c0974fddb81e8693051dbfb0ecc8f8b (diff) | |
download | cpython-7cff66d46972847b27f06831d7b0014b1ecdc2b2.zip cpython-7cff66d46972847b27f06831d7b0014b1ecdc2b2.tar.gz cpython-7cff66d46972847b27f06831d7b0014b1ecdc2b2.tar.bz2 |
improve user config dir handling
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/idlelib/configHandler.py | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/Lib/idlelib/configHandler.py b/Lib/idlelib/configHandler.py index 6984cd8..a3230cc 100644 --- a/Lib/idlelib/configHandler.py +++ b/Lib/idlelib/configHandler.py @@ -152,28 +152,46 @@ class IdleConf: """ #build idle install path if __name__ != '__main__': # we were imported - idledir=os.path.dirname(__file__) + idleDir=os.path.dirname(__file__) else: # we were exec'ed (for testing only) - idledir=os.path.abspath(sys.path[0]) - #print idledir - try: #build user home path - userdir = os.environ['HOME'] #real home directory - except KeyError: - userdir = os.getcwd() #hack for os'es without real homedirs - userdir=os.path.join(userdir,'.idlerc') - #print userdir - if not os.path.exists(userdir): - os.mkdir(userdir) + idleDir=os.path.abspath(sys.path[0]) + userDir=self.GetUserCfgDir() configTypes=('main','extensions','highlight','keys') defCfgFiles={} usrCfgFiles={} for cfgType in configTypes: #build config file names - defCfgFiles[cfgType]=os.path.join(idledir,'config-'+cfgType+'.def') - usrCfgFiles[cfgType]=os.path.join(userdir,'config-'+cfgType+'.cfg') + defCfgFiles[cfgType]=os.path.join(idleDir,'config-'+cfgType+'.def') + usrCfgFiles[cfgType]=os.path.join(userDir,'config-'+cfgType+'.cfg') for cfgType in configTypes: #create config parsers self.defaultCfg[cfgType]=IdleConfParser(defCfgFiles[cfgType]) self.userCfg[cfgType]=IdleUserConfParser(usrCfgFiles[cfgType]) + def GetUserCfgDir(self): + """ + Creates (if required) and returns a filesystem directory for storing + user config files. + """ + cfgDir='.idlerc' + userDir=os.path.expanduser('~') + if userDir != '~': #'HOME' exists as a key in os.environ + if not os.path.exists(userDir): + warn=('\n Warning: HOME environment variable points to\n '+ + userDir+'\n but the path does not exist.\n') + sys.stderr.write(warn) + userDir='~' + if userDir=='~': #we still don't have a home directory + #traditionally idle has defaulted to os.getcwd(), is this adeqate? + userDir = os.getcwd() #hack for no real homedir + userDir=os.path.join(userDir,cfgDir) + if not os.path.exists(userDir): + try: #make the config dir if it doesn't exist yet + os.mkdir(userDir) + except IOError: + warn=('\n Warning: unable to create user config directory\n '+ + userDir+'\n') + sys.stderr.write(warn) + return userDir + def GetOption(self, configType, section, option, default=None, type=None): """ Get an option value for given config type and given general |