Commit 3221c66f authored by Sandro Knauß's avatar Sandro Knauß

[Weblate] save-suggestions: only safe files, if they were changed.

ikiwiki checks if a file has chend by timestamps. In order to reduce the
changed files, we now only touch files that have changed, by use a
atomic write via a rename of a tempoary file.
parent 074f6597
......@@ -15,6 +15,7 @@ import os
import pathlib
import subprocess
import sys
import tempfile
sys.path.insert(0, "/usr/local/share/weblate")
os.environ["DJANGO_SETTINGS_MODULE"] = "weblate.settings"
......@@ -117,8 +118,23 @@ def commandline():
# save with suggestions
if changed:
with (repopath/translation.filename).open("wb") as f:
filepath = repopath/translation.filename
with tempfile.NamedTemporaryFile() as f:
subprocess.check_output(['diff', "-q", str(filepath),], stderr=subprocess.STDOUT)
logger.debug("don't update {}, because no diff was found".format(translation.filename))
# The file is still the same, so no need to touch the original file
except subprocess.CalledProcessError:
stat = filepath.stat()
os.fchmod(f.fileno(), stat.st_mode)
os.fchown(f.fileno(), stat.st_uid, stat.st_gid)
f.delete = False
# There is a bug in stdlib, that the delete flag is not forward to the real object
f._closer.delete = False
os.rename(, str(filepath))
logger.exception("-- Got an exception for %s(%i) --",, i)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment