mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 01:52:56 +01:00
jwutils.misc: Add commit_tmpfile()
commit_tmpfile() is a better os.rename which doesn't do anything if source and target files are equal, and logs if does something. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
33d3b7a7b3
commit
47f4de938f
1 changed files with 9 additions and 0 deletions
|
|
@ -62,4 +62,13 @@ def get_derived_classes(mod, base): # export
|
||||||
r.append(c)
|
r.append(c)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
def commit_tmpfile(tmp, path): # export
|
||||||
|
caller = log.get_caller_pos()
|
||||||
|
if os.path.isfile(path) and filecmp.cmp(tmp, path):
|
||||||
|
log.slog(log.INFO, "{} is up to date".format(path), caller=caller)
|
||||||
|
os.unlink(tmp)
|
||||||
|
else:
|
||||||
|
log.slog(log.NOTICE, "saving {}".format(path), caller=caller)
|
||||||
|
os.rename(path + '.tmp', path)
|
||||||
|
|
||||||
atexit.register(_cleanup)
|
atexit.register(_cleanup)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue