Use a with block to create index.html.

Also, updates our IO so we write to a .tmp file and
rename it only after the file IO is completed. This
wards off a potential race where a user could load
a page that hadn't been fully flushed to disk.

Change-Id: I04bfb7def801f11e3fcae83272879f660a8d1825
This commit is contained in:
Dan Prince 2014-02-12 10:58:04 -05:00
parent 80b63eced6
commit a409123c9b
1 changed files with 3 additions and 3 deletions

View File

@ -44,8 +44,8 @@ def create_report(out_dir, name_space={}):
prep_out_dir(out_dir)
out_file = open(os.path.join(out_dir, 'index.html'), "w")
out_file.write(str(t))
out_file.close()
with open(os.path.join(out_dir, 'index.html.tmp'), "w") as f:
f.write(str(t))
os.rename(f.name, os.path.join(out_dir, 'index.html'))
_create_json(out_dir, name_space=name_space)