ยปCore Development>Code coverage>Tools/freeze/bkfile.py

Python code coverage for Tools/freeze/bkfile.py

#countcontent
1n/afrom builtins import open as _orig_open
2n/a
3n/adef open(file, mode='r', bufsize=-1):
4n/a if 'w' not in mode:
5n/a return _orig_open(file, mode, bufsize)
6n/a import os
7n/a backup = file + '~'
8n/a try:
9n/a os.unlink(backup)
10n/a except OSError:
11n/a pass
12n/a try:
13n/a os.rename(file, backup)
14n/a except OSError:
15n/a return _orig_open(file, mode, bufsize)
16n/a f = _orig_open(file, mode, bufsize)
17n/a _orig_close = f.close
18n/a def close():
19n/a _orig_close()
20n/a import filecmp
21n/a if filecmp.cmp(backup, file, shallow=False):
22n/a import os
23n/a os.unlink(file)
24n/a os.rename(backup, file)
25n/a f.close = close
26n/a return f