diff -r 78a3d3700233 Lib/idlelib/config.py --- a/Lib/idlelib/config.py Sun Jul 03 19:11:13 2016 -0400 +++ b/Lib/idlelib/config.py Mon Jul 04 16:03:24 2016 -0400 @@ -115,17 +115,11 @@ self.set(section, option, value) return True - def RemoveFile(self): - "Remove user config file self.file from disk if it exists." - if os.path.exists(self.file): - os.remove(self.file) - def Save(self): """Update user configuration file. Remove empty sections. If resulting config isn't empty, write the file to disk. If config is empty, remove the file from disk if it exists. - """ if not self.IsEmpty(): fname = self.file @@ -136,8 +130,9 @@ cfgFile = open(fname, 'w') with cfgFile: self.write(cfgFile) - else: - self.RemoveFile() + elif os.path.exists(self.file): + os.remove(self.file) + class IdleConf: """Hold config parsers for all idle config files in singleton instance. @@ -161,24 +156,13 @@ def CreateConfigHandlers(self): "Populate default and user config parser dictionaries." - #build idle install path - if __name__ != '__main__': # we were imported - idleDir=os.path.dirname(__file__) - else: # we were exec'ed (for testing only) - idleDir=os.path.abspath(sys.path[0]) - userDir=self.GetUserCfgDir() - - defCfgFiles = {} - usrCfgFiles = {} - # TODO eliminate these temporaries by combining loops - for cfgType in self.config_types: #build config file names - defCfgFiles[cfgType] = os.path.join( - idleDir, 'config-' + cfgType + '.def') - usrCfgFiles[cfgType] = os.path.join( - userDir, 'config-' + cfgType + '.cfg') - for cfgType in self.config_types: #create config parsers - self.defaultCfg[cfgType] = IdleConfParser(defCfgFiles[cfgType]) - self.userCfg[cfgType] = IdleUserConfParser(usrCfgFiles[cfgType]) + idledir = os.path.dirname(__file__) + userdir = self.GetUserCfgDir() + for cfg_type in self.config_types: + self.defaultCfg[cfg_type] = IdleConfParser( + os.path.join(idledir, 'config-' + cfg_type + '.def')) + self.userCfg[cfg_type] = IdleUserConfParser( + os.path.join(userdir, 'config-' + cfg_type + '.cfg')) def GetUserCfgDir(self): """Return a filesystem directory for storing user config files. @@ -752,5 +736,5 @@ print(option, '=', cfg[key].Get(section, option)) dumpCfg(idleConf.defaultCfg) dumpCfg(idleConf.userCfg) - print(idleConf.userCfg['main'].Get('Theme', 'name')) + #print(idleConf.userCfg['main'].Get('Theme', 'name')) #print idleConf.userCfg['highlight'].GetDefHighlight('Foo','normal')