1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-27 07:32:22 +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,6 +1,5 @@
from __future__ import print_function
import codecs
import os
import random
import string
@@ -9,7 +8,7 @@ import unicodedata
import voluptuous as vol
import esphome.config_validation as cv
from esphome.helpers import color, get_bool_env
from esphome.helpers import color, get_bool_env, write_file
# pylint: disable=anomalous-backslash-in-string
from esphome.pins import ESP32_BOARD_PINS, ESP8266_BOARD_PINS
from esphome.py_compat import safe_input, text_type
@@ -104,8 +103,7 @@ def wizard_write(path, **kwargs):
kwargs['platform'] = 'ESP8266' if board in ESP8266_BOARD_PINS else 'ESP32'
platform = kwargs['platform']
with codecs.open(path, 'w', 'utf-8') as f_handle:
f_handle.write(wizard_file(**kwargs))
write_file(path, wizard_file(**kwargs))
storage = StorageJSON.from_wizard(name, name + '.local', platform, board)
storage_path = ext_storage_path(os.path.dirname(path), os.path.basename(path))
storage.save(storage_path)