MCPcopy Index your code
hub / github.com/python/cpython / GetUserCfgDir

Method GetUserCfgDir

Lib/idlelib/config.py:179–213  ·  view source on GitHub ↗

Return a filesystem directory for storing user config files. Creates it if required.

(self)

Source from the content-addressed store, hash-verified

177 os.path.join(userdir or '#', f'config-{cfg_type}.cfg'))
178
179 def GetUserCfgDir(self):
180 """Return a filesystem directory for storing user config files.
181
182 Creates it if required.
183 """
184 cfgDir = '.idlerc'
185 userDir = os.path.expanduser('~')
186 if userDir != '~': # expanduser() found user home dir
187 if not os.path.exists(userDir):
188 if not idlelib.testing:
189 warn = ('\n Warning: os.path.expanduser("~") points to\n ' +
190 userDir + ',\n but the path does not exist.')
191 try:
192 print(warn, file=sys.stderr)
193 except OSError:
194 pass
195 userDir = '~'
196 if userDir == "~": # still no path to home!
197 # traditionally IDLE has defaulted to os.getcwd(), is this adequate?
198 userDir = os.getcwd()
199 userDir = os.path.join(userDir, cfgDir)
200 if not os.path.exists(userDir):
201 try:
202 os.mkdir(userDir)
203 except OSError:
204 if not idlelib.testing:
205 warn = ('\n Warning: unable to create user config directory\n' +
206 userDir + '\n Check path and permissions.\n Exiting!\n')
207 try:
208 print(warn, file=sys.stderr)
209 except OSError:
210 pass
211 raise SystemExit
212 # TODO continue without userDIr instead of exit
213 return userDir
214
215 def GetOption(self, configType, section, option, default=None, type=None,
216 warn_on_default=True, raw=False):

Callers 3

CreateConfigHandlersMethod · 0.95

Calls 4

expanduserMethod · 0.80
existsMethod · 0.45
joinMethod · 0.45
mkdirMethod · 0.45

Tested by 2