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:
@@ -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)
|
||||
|
Reference in New Issue
Block a user