@@ -123,17 +123,11 @@ def IsEmpty(self):
123
123
self .RemoveEmptySections ()
124
124
return not self .sections ()
125
125
126
- def RemoveFile (self ):
127
- "Remove user config file self.file from disk if it exists."
128
- if os .path .exists (self .file ):
129
- os .remove (self .file )
130
-
131
126
def Save (self ):
132
127
"""Update user configuration file.
133
128
134
129
If self not empty after removing empty sections, write the file
135
130
to disk. Otherwise, remove the file from disk if it exists.
136
-
137
131
"""
138
132
fname = self .file
139
133
if fname :
@@ -145,8 +139,8 @@ def Save(self):
145
139
cfgFile = open (fname , 'w' )
146
140
with cfgFile :
147
141
self .write (cfgFile )
148
- else :
149
- self . RemoveFile ( )
142
+ elif os . path . exists ( self . file ) :
143
+ os . remove ( self . file )
150
144
151
145
class IdleConf :
152
146
"""Hold config parsers for all idle config files in singleton instance.
@@ -171,24 +165,13 @@ def __init__(self, _utest=False):
171
165
172
166
def CreateConfigHandlers (self ):
173
167
"Populate default and user config parser dictionaries."
174
- #build idle install path
175
- if __name__ != '__main__' : # we were imported
176
- idleDir = os .path .dirname (__file__ )
177
- else : # we were exec'ed (for testing only)
178
- idleDir = os .path .abspath (sys .path [0 ])
179
- self .userdir = userDir = self .GetUserCfgDir ()
180
-
181
- defCfgFiles = {}
182
- usrCfgFiles = {}
183
- # TODO eliminate these temporaries by combining loops
184
- for cfgType in self .config_types : #build config file names
185
- defCfgFiles [cfgType ] = os .path .join (
186
- idleDir , 'config-' + cfgType + '.def' )
187
- usrCfgFiles [cfgType ] = os .path .join (
188
- userDir , 'config-' + cfgType + '.cfg' )
189
- for cfgType in self .config_types : #create config parsers
190
- self .defaultCfg [cfgType ] = IdleConfParser (defCfgFiles [cfgType ])
191
- self .userCfg [cfgType ] = IdleUserConfParser (usrCfgFiles [cfgType ])
168
+ idledir = os .path .dirname (__file__ )
169
+ self .userdir = userdir = self .GetUserCfgDir ()
170
+ for cfg_type in self .config_types :
171
+ self .defaultCfg [cfg_type ] = IdleConfParser (
172
+ os .path .join (idledir , f'config-{ cfg_type } .def' ))
173
+ self .userCfg [cfg_type ] = IdleUserConfParser (
174
+ os .path .join (userdir , f'config-{ cfg_type } .cfg' ))
192
175
193
176
def GetUserCfgDir (self ):
194
177
"""Return a filesystem directory for storing user config files.
0 commit comments