From e2c8b211957d0516f3748ca27efc1cb2ee3f9697 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Sat, 2 Nov 2019 19:35:37 +0100 Subject: [PATCH] Fix wizard mkdir (#824) * Fix CLI wizard mkdir_p with empty path Fixes https://github.com/esphome/issues/issues/796 * Cleanup * Lint --- esphome/helpers.py | 3 +++ esphome/storage_json.py | 3 +-- esphome/writer.py | 5 +---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/esphome/helpers.py b/esphome/helpers.py index 6fd1fa2ad7..48607dbff5 100644 --- a/esphome/helpers.py +++ b/esphome/helpers.py @@ -80,6 +80,9 @@ def run_system_command(*args): def mkdir_p(path): + if not path: + # Empty path - means create current dir + return try: os.makedirs(path) except OSError as err: diff --git a/esphome/storage_json.py b/esphome/storage_json.py index 0305b59ef5..e1b4070d3b 100644 --- a/esphome/storage_json.py +++ b/esphome/storage_json.py @@ -7,7 +7,7 @@ import os from esphome import const from esphome.core import CORE -from esphome.helpers import mkdir_p, write_file_if_changed +from esphome.helpers import write_file_if_changed # pylint: disable=unused-import, wrong-import-order from esphome.core import CoreType # noqa @@ -88,7 +88,6 @@ class StorageJSON(object): return json.dumps(self.as_dict(), indent=2) + u'\n' def save(self, path): - mkdir_p(os.path.dirname(path)) write_file_if_changed(path, self.to_json()) @staticmethod diff --git a/esphome/writer.py b/esphome/writer.py index 4c2e03569f..1961af5a15 100644 --- a/esphome/writer.py +++ b/esphome/writer.py @@ -286,8 +286,6 @@ or use the custom_components folder. def copy_src_tree(): - import shutil - source_files = {} for _, component, _ in iter_components(CORE.config): source_files.update(component.source_files) @@ -326,8 +324,7 @@ def copy_src_tree(): # Now copy new files for target, src_path in source_files_copy.items(): dst_path = CORE.relative_src_path(*target.split('/')) - mkdir_p(os.path.dirname(dst_path)) - shutil.copy(src_path, dst_path) + copy_file_if_changed(src_path, dst_path) # Finally copy defines write_file_if_changed(CORE.relative_src_path('esphome', 'core', 'defines.h'),