[Qa-jenkins-scm] [jenkins.debian.net] 01/01: reproducible: write json to tempfile first, so that updates are atomic
Holger Levsen
holger at moszumanska.debian.org
Fri Mar 13 17:31:41 UTC 2015
This is an automated email from the git hooks/post-receive script.
holger pushed a commit to branch master
in repository jenkins.debian.net.
commit 9e142f8c980a64d13df65789232807d417234c58
Author: Holger Levsen <holger at layer-acht.org>
Date: Fri Mar 13 18:29:39 2015 +0100
reproducible: write json to tempfile first, so that updates are atomic
---
bin/reproducible_json.py | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/bin/reproducible_json.py b/bin/reproducible_json.py
index 3d63a03..d00d509 100755
--- a/bin/reproducible_json.py
+++ b/bin/reproducible_json.py
@@ -12,6 +12,9 @@
from reproducible_common import *
import json
+import os
+import tempfile
+
output = []
@@ -29,8 +32,12 @@ for row in result:
log.debug(pkg)
output.append(pkg)
-with open(REPRODUCIBLE_JSON, 'w') as fd:
+tmpfile = tempfile.NamedTemporaryFile(dir=os.path.dirname(REPRODUCIBLE_JSON))
+
+with open(tmpfile.name, 'w') as fd:
json.dump(output, fd, indent=4, sort_keys=True)
+os.rename(tmpfile.name, REPRODUCIBLE_JSON)
+
log.info(REPRODUCIBLE_URL + '/reproducible.json has been updated.')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/qa/jenkins.debian.net.git
More information about the Qa-jenkins-scm
mailing list