Return a filesystem directory for storing user config files. Creates it if required.
(self)
| 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): |