1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-05 21:02:20 +01:00

Make file generation saving atomic (#792)

* Make file generation saving atomic

* Lint

* Python 2 Compat

* Fix

* Handle file not found error
This commit is contained in:
Otto Winter
2019-10-24 21:53:42 +02:00
committed by GitHub
parent d62ef35860
commit bb2582717f
6 changed files with 123 additions and 77 deletions

View File

@@ -1,10 +1,10 @@
from __future__ import print_function
import codecs
import json
import os
from esphome.core import CORE, EsphomeError
from esphome.core import CORE
from esphome.helpers import read_file
from esphome.py_compat import safe_input
@@ -20,10 +20,4 @@ def read_config_file(path):
assert data['type'] == 'file_response'
return data['content']
try:
with codecs.open(path, encoding='utf-8') as handle:
return handle.read()
except IOError as exc:
raise EsphomeError(u"Error accessing file {}: {}".format(path, exc))
except UnicodeDecodeError as exc:
raise EsphomeError(u"Unable to read file {}: {}".format(path, exc))
return read_file(path)