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

Class IdleConf

Lib/idlelib/config.py:145–766  ·  view source on GitHub ↗

Hold config parsers for all idle config files in singleton instance. Default config files, self.defaultCfg -- for config_type in self.config_types: (idle install dir)/config-{config-type}.def User config files, self.userCfg -- for config_type in self.config_type

Source from the content-addressed store, hash-verified

143 os.remove(self.file)
144
145class IdleConf:
146 """Hold config parsers for all idle config files in singleton instance.
147
148 Default config files, self.defaultCfg --
149 for config_type in self.config_types:
150 (idle install dir)/config-{config-type}.def
151
152 User config files, self.userCfg --
153 for config_type in self.config_types:
154 (user home dir)/.idlerc/config-{config-type}.cfg
155 """
156 def __init__(self, _utest=False):
157 self.config_types = ('main', 'highlight', 'keys', 'extensions')
158 self.defaultCfg = {}
159 self.userCfg = {}
160 self.cfg = {} # TODO use to select userCfg vs defaultCfg
161
162 # See https://bugs.python.org/issue4630#msg356516 for following.
163 # self.blink_off_time = <first editor text>['insertofftime']
164
165 if not _utest:
166 self.CreateConfigHandlers()
167 self.LoadCfgFiles()
168
169 def CreateConfigHandlers(self):
170 "Populate default and user config parser dictionaries."
171 idledir = os.path.dirname(__file__)
172 self.userdir = userdir = '' if idlelib.testing else self.GetUserCfgDir()
173 for cfg_type in self.config_types:
174 self.defaultCfg[cfg_type] = IdleConfParser(
175 os.path.join(idledir, f'config-{cfg_type}.def'))
176 self.userCfg[cfg_type] = IdleUserConfParser(
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)

Callers 1

config.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…