summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xhtml/generate.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/html/generate.py b/html/generate.py
index 8eb7622..8d79cbe 100755
--- a/html/generate.py
+++ b/html/generate.py
@@ -15,6 +15,8 @@
import datetime
import socket
+import os
+import tempfile
import urllib.request, json
import xml.etree.ElementTree as ET
import jinja2
@@ -81,8 +83,12 @@ def renderStatsTemplate(templateEnv, page):
# read the cache
-with open(cache_path) as json_file:
- cache_data = json.load(json_file)
+if os.path.exists(cache_path):
+ with open(cache_path, mode='rt') as json_file:
+ try:
+ cache_data = json.load(json_file)
+ except:
+ pass
#
# The all mirrors that are present in the given list
@@ -169,8 +175,10 @@ template.stream(lastUpdate=lastUpdate).dump(html_folder + "help.html")
#
# write the cache
#
-with open(cache_path, 'w') as fp:
- json.dump(cache_data, fp)
+with tempfile.NamedTemporaryFile(dir=os.path.dirname(cache_path), delete=False, mode='wt') as fout:
+ json.dump(cache_data, fout)
+ os.chmod(fout.name, '0644')
+ os.replace(fout.name, cache_path)
#