Dumps the configuration in `dct` to a file. Args: filepath (Text): Filepath to write config to, in UTF-8 encoding. dct (dict): Configuration represented as a dictionary.
(self, filepath, dct)
| 470 | return self._dumpdict(dct) |
| 471 | |
| 472 | def dump(self, filepath, dct): |
| 473 | """Dumps the configuration in `dct` to a file. |
| 474 | |
| 475 | Args: |
| 476 | filepath (Text): Filepath to write config to, in UTF-8 encoding. |
| 477 | dct (dict): Configuration represented as a dictionary. |
| 478 | """ |
| 479 | tmpf = tempfile.NamedTemporaryFile(dir=os.path.dirname(filepath), |
| 480 | delete=False) |
| 481 | |
| 482 | try: |
| 483 | with io.open(tmpf.name, mode='w', encoding='utf-8') as f: |
| 484 | f.write(self.dumps(dct)) |
| 485 | |
| 486 | os.rename(tmpf.name, filepath) |
| 487 | |
| 488 | except IOError as ex: |
| 489 | try: |
| 490 | os.unlink(tmpf.name) |
| 491 | |
| 492 | except Exception: |
| 493 | pass |
| 494 | |
| 495 | raise error.ApacheConfigError('File %s can\'t be written: %s' |
| 496 | % (filepath, ex)) |