MCPcopy Create free account
hub / github.com/DFHack/dfhack / write_file_if_changed

Function write_file_if_changed

docs/sphinx_extensions/dfhack/util.py:13–26  ·  view source on GitHub ↗
(path)

Source from the content-addressed store, hash-verified

11
12@contextlib.contextmanager
13def 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)

Callers 2

write_tool_docsFunction · 0.90
print_changelogFunction · 0.90

Calls 2

readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected