(path)
| 11 | |
| 12 | @contextlib.contextmanager |
| 13 | def write_file_if_changed(path): |
| 14 | with io.StringIO() as buffer: |
| 15 | yield buffer |
| 16 | new_contents = buffer.getvalue() |
| 17 | |
| 18 | try: |
| 19 | with open(path, 'r') as infile: |
| 20 | old_contents = infile.read() |
| 21 | except IOError: |
| 22 | old_contents = None |
| 23 | |
| 24 | if old_contents != new_contents: |
| 25 | with open(path, 'w') as outfile: |
| 26 | outfile.write(new_contents) |
| 27 | |
| 28 | |
| 29 | # directive argument helpers (supplementing docutils.parsers.rst.directives) |
no test coverage detected