Loads config file into a dictionary object. Args: filepath (Text): path of config file to load. Expects UTF-8 encoding. Returns: dict containing configuration information loaded from file.
(self, filepath, initialize=True)
| 354 | return self._ast_cache[source] |
| 355 | |
| 356 | def load(self, filepath, initialize=True): |
| 357 | """Loads config file into a dictionary object. |
| 358 | |
| 359 | Args: |
| 360 | filepath (Text): path of config file to load. Expects UTF-8 |
| 361 | encoding. |
| 362 | |
| 363 | Returns: |
| 364 | dict containing configuration information loaded from file. |
| 365 | """ |
| 366 | if initialize: |
| 367 | self._stack = [] |
| 368 | self._includes = set() |
| 369 | self._ast_cache = {} |
| 370 | |
| 371 | try: |
| 372 | pre_open = self._options['plug']['pre_open'] |
| 373 | |
| 374 | filename, basedir = os.path.basename( |
| 375 | filepath), os.path.dirname(filepath) |
| 376 | |
| 377 | process, filename, basedir = pre_open(filename, basedir) |
| 378 | |
| 379 | filepath = os.path.join( |
| 380 | basedir, filename) if basedir else filename |
| 381 | |
| 382 | if not process: |
| 383 | return {} |
| 384 | |
| 385 | except KeyError: |
| 386 | pass |
| 387 | |
| 388 | if filepath in self._includes and not self._options.get( |
| 389 | 'includeagain'): |
| 390 | return {} |
| 391 | |
| 392 | self._includes.add(filepath) |
| 393 | |
| 394 | if filepath in self._ast_cache: |
| 395 | return self._ast_cache[filepath] |
| 396 | |
| 397 | try: |
| 398 | with self._reader.open(filepath) as f: |
| 399 | return self.loads(f.read(), source=filepath) |
| 400 | |
| 401 | except IOError as ex: |
| 402 | raise error.ConfigFileReadError('File %s can\'t be open: %s' |
| 403 | % (filepath, ex)) |
| 404 | |
| 405 | finally: |
| 406 | if initialize: |
| 407 | self._ast_cache = {} |
| 408 | |
| 409 | def _dumpdict(self, obj, indent=0, continue_tag=False): |
| 410 | if not isinstance(obj, dict): |