diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-07-16 14:19:10 -0700 |
|---|---|---|
| committer | Terry Jan Reedy <tjreedy@udel.edu> | 2019-07-16 17:19:10 -0400 |
| commit | 178f09f8b7d25348d46751a774666dd4ec32f3e6 (patch) | |
| tree | a494eb7a951f603ab06843d3748840ac01fb8afe /Lib/idlelib/config.py | |
| parent | 6a2aec0ff587032beb8aac8cbebb09e7a52f6694 (diff) | |
| download | cpython-git-178f09f8b7d25348d46751a774666dd4ec32f3e6.tar.gz | |
bpo-27452: IDLE: Cleanup config.py code (GH-14577) (GH-14802)
(cherry picked from commit f8d4cc7dbbf54b9c5435c3080582a4aa421a067d)
Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
Diffstat (limited to 'Lib/idlelib/config.py')
| -rw-r--r-- | Lib/idlelib/config.py | 35 |
1 files changed, 9 insertions, 26 deletions
diff --git a/Lib/idlelib/config.py b/Lib/idlelib/config.py index 2233dacd66..0c55c9a7d7 100644 --- a/Lib/idlelib/config.py +++ b/Lib/idlelib/config.py @@ -123,17 +123,11 @@ class IdleUserConfParser(IdleConfParser): self.RemoveEmptySections() return not self.sections() - 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. If self not empty after removing empty sections, write the file to disk. Otherwise, remove the file from disk if it exists. - """ fname = self.file if fname: @@ -145,8 +139,8 @@ class IdleUserConfParser(IdleConfParser): 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. @@ -171,24 +165,13 @@ class IdleConf: 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]) - self.userdir = 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__) + self.userdir = userdir = self.GetUserCfgDir() + for cfg_type in self.config_types: + self.defaultCfg[cfg_type] = IdleConfParser( + os.path.join(idledir, f'config-{cfg_type}.def')) + self.userCfg[cfg_type] = IdleUserConfParser( + os.path.join(userdir, f'config-{cfg_type}.cfg')) def GetUserCfgDir(self): """Return a filesystem directory for storing user config files. |
