2018-10-14 18:52:21 +02:00
|
|
|
import logging
|
2018-04-07 01:23:03 +02:00
|
|
|
import os
|
2018-12-05 21:22:06 +01:00
|
|
|
import re
|
2021-05-07 20:02:17 +02:00
|
|
|
from pathlib import Path
|
2022-10-05 09:09:27 +02:00
|
|
|
from typing import Union
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2019-02-13 16:54:02 +01:00
|
|
|
from esphome.config import iter_components
|
2021-03-07 20:03:16 +01:00
|
|
|
from esphome.const import (
|
|
|
|
HEADER_FILE_EXTENSIONS,
|
|
|
|
SOURCE_FILE_EXTENSIONS,
|
|
|
|
__version__,
|
|
|
|
ENV_NOGITIGNORE,
|
|
|
|
)
|
2019-02-13 16:54:02 +01:00
|
|
|
from esphome.core import CORE, EsphomeError
|
2021-03-07 20:03:16 +01:00
|
|
|
from esphome.helpers import (
|
|
|
|
mkdir_p,
|
|
|
|
read_file,
|
|
|
|
write_file_if_changed,
|
|
|
|
walk_files,
|
|
|
|
copy_file_if_changed,
|
|
|
|
get_bool_env,
|
|
|
|
)
|
2019-02-13 16:54:02 +01:00
|
|
|
from esphome.storage_json import StorageJSON, storage_path
|
2021-05-07 20:02:17 +02:00
|
|
|
from esphome import loader
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2018-10-14 18:52:21 +02:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
CPP_AUTO_GENERATE_BEGIN = "// ========== AUTO GENERATED CODE BEGIN ==========="
|
|
|
|
CPP_AUTO_GENERATE_END = "// =========== AUTO GENERATED CODE END ============"
|
|
|
|
CPP_INCLUDE_BEGIN = "// ========== AUTO GENERATED INCLUDE BLOCK BEGIN ==========="
|
|
|
|
CPP_INCLUDE_END = "// ========== AUTO GENERATED INCLUDE BLOCK END ==========="
|
|
|
|
INI_AUTO_GENERATE_BEGIN = "; ========== AUTO GENERATED CODE BEGIN ==========="
|
|
|
|
INI_AUTO_GENERATE_END = "; =========== AUTO GENERATED CODE END ============"
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
CPP_BASE_FORMAT = (
|
|
|
|
"""// Auto generated code by esphome
|
|
|
|
""",
|
|
|
|
""""
|
2018-04-07 01:23:03 +02:00
|
|
|
|
|
|
|
void setup() {
|
2021-03-07 20:03:16 +01:00
|
|
|
""",
|
|
|
|
"""
|
2018-04-07 01:23:03 +02:00
|
|
|
App.setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
App.loop();
|
|
|
|
}
|
2021-03-07 20:03:16 +01:00
|
|
|
""",
|
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
INI_BASE_FORMAT = (
|
|
|
|
"""; Auto generated code by esphome
|
2018-04-07 01:23:03 +02:00
|
|
|
|
|
|
|
[common]
|
2018-04-10 17:17:46 +02:00
|
|
|
lib_deps =
|
|
|
|
build_flags =
|
|
|
|
upload_flags =
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
""",
|
|
|
|
"""
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
""",
|
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2021-09-20 11:47:51 +02:00
|
|
|
UPLOAD_SPEED_OVERRIDE = {
|
|
|
|
"esp210": 57600,
|
|
|
|
}
|
2018-09-25 18:27:47 +02:00
|
|
|
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2019-04-17 12:06:00 +02:00
|
|
|
def get_flags(key):
|
|
|
|
flags = set()
|
2018-12-05 21:22:06 +01:00
|
|
|
for _, component, conf in iter_components(CORE.config):
|
2019-04-17 12:06:00 +02:00
|
|
|
flags |= getattr(component, key)(conf)
|
|
|
|
return flags
|
2018-04-18 18:43:13 +02:00
|
|
|
|
|
|
|
|
2018-12-05 21:22:06 +01:00
|
|
|
def get_include_text():
|
2021-03-07 20:03:16 +01:00
|
|
|
include_text = '#include "esphome.h"\nusing namespace esphome;\n'
|
2018-12-05 21:22:06 +01:00
|
|
|
for _, component, conf in iter_components(CORE.config):
|
2021-03-07 20:03:16 +01:00
|
|
|
if not hasattr(component, "includes"):
|
2018-12-05 21:22:06 +01:00
|
|
|
continue
|
|
|
|
includes = component.includes
|
|
|
|
if callable(includes):
|
|
|
|
includes = includes(conf)
|
|
|
|
if includes is None:
|
|
|
|
continue
|
|
|
|
if isinstance(includes, list):
|
2021-03-07 20:03:16 +01:00
|
|
|
includes = "\n".join(includes)
|
2018-12-05 21:22:06 +01:00
|
|
|
if not includes:
|
|
|
|
continue
|
2021-09-19 19:22:28 +02:00
|
|
|
include_text += f"{includes}\n"
|
2018-12-05 21:22:06 +01:00
|
|
|
return include_text
|
2018-04-18 18:43:13 +02:00
|
|
|
|
2018-05-06 15:56:12 +02:00
|
|
|
|
2018-12-05 21:22:06 +01:00
|
|
|
def replace_file_content(text, pattern, repl):
|
|
|
|
content_new, count = re.subn(pattern, repl, text, flags=re.M)
|
|
|
|
return content_new, count
|
|
|
|
|
|
|
|
|
2022-10-05 09:09:27 +02:00
|
|
|
def storage_should_clean(old: StorageJSON, new: StorageJSON) -> bool:
|
2018-12-05 21:22:06 +01:00
|
|
|
if old is None:
|
|
|
|
return True
|
|
|
|
|
|
|
|
if old.src_version != new.src_version:
|
|
|
|
return True
|
|
|
|
if old.build_path != new.build_path:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def update_storage_json():
|
|
|
|
path = storage_path()
|
|
|
|
old = StorageJSON.load(path)
|
2019-02-13 16:54:02 +01:00
|
|
|
new = StorageJSON.from_esphome_core(CORE, old)
|
2018-12-05 21:22:06 +01:00
|
|
|
if old == new:
|
|
|
|
return
|
|
|
|
|
|
|
|
if storage_should_clean(old, new):
|
|
|
|
_LOGGER.info("Core config or version changed, cleaning build files...")
|
|
|
|
clean_build()
|
|
|
|
|
|
|
|
new.save(path)
|
|
|
|
|
|
|
|
|
2022-10-05 09:09:27 +02:00
|
|
|
def format_ini(data: dict[str, Union[str, list[str]]]) -> str:
|
2021-03-07 20:03:16 +01:00
|
|
|
content = ""
|
2019-01-02 12:29:15 +01:00
|
|
|
for key, value in sorted(data.items()):
|
2021-09-20 11:47:51 +02:00
|
|
|
if isinstance(value, list):
|
2021-03-07 20:03:16 +01:00
|
|
|
content += f"{key} =\n"
|
2019-01-02 12:29:15 +01:00
|
|
|
for x in value:
|
2021-03-07 20:03:16 +01:00
|
|
|
content += f" {x}\n"
|
2019-01-02 12:29:15 +01:00
|
|
|
else:
|
2021-03-07 20:03:16 +01:00
|
|
|
content += f"{key} = {value}\n"
|
2019-01-02 12:29:15 +01:00
|
|
|
return content
|
|
|
|
|
|
|
|
|
2019-03-05 13:25:59 +01:00
|
|
|
def get_ini_content():
|
2021-09-20 11:47:51 +02:00
|
|
|
CORE.add_platformio_option(
|
|
|
|
"lib_deps", [x.as_lib_dep for x in CORE.libraries] + ["${common.lib_deps}"]
|
|
|
|
)
|
|
|
|
# Sort to avoid changing build flags order
|
|
|
|
CORE.add_platformio_option("build_flags", sorted(CORE.build_flags))
|
2019-01-02 12:29:15 +01:00
|
|
|
|
2023-02-16 01:27:32 +01:00
|
|
|
content = "[platformio]\n"
|
|
|
|
content += f"description = ESPHome {__version__}\n"
|
|
|
|
|
|
|
|
content += f"[env:{CORE.name}]\n"
|
2021-09-20 11:47:51 +02:00
|
|
|
content += format_ini(CORE.platformio_options)
|
2019-01-02 12:29:15 +01:00
|
|
|
|
2018-05-16 19:45:33 +02:00
|
|
|
return content
|
2018-04-07 01:23:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
def find_begin_end(text, begin_s, end_s):
|
|
|
|
begin_index = text.find(begin_s)
|
|
|
|
if begin_index == -1:
|
2021-03-07 20:03:16 +01:00
|
|
|
raise EsphomeError(
|
|
|
|
"Could not find auto generated code begin in file, either "
|
|
|
|
"delete the main sketch file or insert the comment again."
|
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
if text.find(begin_s, begin_index + 1) != -1:
|
2021-03-07 20:03:16 +01:00
|
|
|
raise EsphomeError(
|
|
|
|
"Found multiple auto generate code begins, don't know "
|
|
|
|
"which to chose, please remove one of them."
|
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
end_index = text.find(end_s)
|
|
|
|
if end_index == -1:
|
2021-03-07 20:03:16 +01:00
|
|
|
raise EsphomeError(
|
|
|
|
"Could not find auto generated code end in file, either "
|
|
|
|
"delete the main sketch file or insert the comment again."
|
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
if text.find(end_s, end_index + 1) != -1:
|
2021-03-07 20:03:16 +01:00
|
|
|
raise EsphomeError(
|
|
|
|
"Found multiple auto generate code endings, don't know "
|
|
|
|
"which to chose, please remove one of them."
|
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
return text[:begin_index], text[(end_index + len(end_s)) :]
|
2018-04-07 01:23:03 +02:00
|
|
|
|
|
|
|
|
2019-04-17 12:06:00 +02:00
|
|
|
def write_platformio_ini(content):
|
2018-12-05 21:22:06 +01:00
|
|
|
update_storage_json()
|
2021-03-07 20:03:16 +01:00
|
|
|
path = CORE.relative_build_path("platformio.ini")
|
2018-12-05 21:22:06 +01:00
|
|
|
|
2018-04-07 01:23:03 +02:00
|
|
|
if os.path.isfile(path):
|
2019-04-17 12:06:00 +02:00
|
|
|
text = read_file(path)
|
2021-03-07 20:03:16 +01:00
|
|
|
content_format = find_begin_end(
|
|
|
|
text, INI_AUTO_GENERATE_BEGIN, INI_AUTO_GENERATE_END
|
|
|
|
)
|
2018-04-07 01:23:03 +02:00
|
|
|
else:
|
|
|
|
content_format = INI_BASE_FORMAT
|
2021-09-19 19:22:28 +02:00
|
|
|
full_file = f"{content_format[0] + INI_AUTO_GENERATE_BEGIN}\n{content}"
|
2018-12-05 21:22:06 +01:00
|
|
|
full_file += INI_AUTO_GENERATE_END + content_format[1]
|
2019-10-24 21:53:42 +02:00
|
|
|
write_file_if_changed(path, full_file)
|
2018-04-07 01:23:03 +02:00
|
|
|
|
|
|
|
|
2018-12-05 21:22:06 +01:00
|
|
|
def write_platformio_project():
|
|
|
|
mkdir_p(CORE.build_path)
|
|
|
|
|
|
|
|
content = get_ini_content()
|
2020-12-21 22:19:26 +01:00
|
|
|
if not get_bool_env(ENV_NOGITIGNORE):
|
|
|
|
write_gitignore()
|
2019-04-17 12:06:00 +02:00
|
|
|
write_platformio_ini(content)
|
|
|
|
|
|
|
|
|
2023-12-12 22:59:10 +01:00
|
|
|
DEFINES_H_FORMAT = (
|
|
|
|
ESPHOME_H_FORMAT
|
|
|
|
) = """\
|
2019-04-17 12:06:00 +02:00
|
|
|
#pragma once
|
2022-01-24 10:34:34 +01:00
|
|
|
#include "esphome/core/macros.h"
|
2019-04-17 12:06:00 +02:00
|
|
|
{}
|
|
|
|
"""
|
2019-12-07 18:28:55 +01:00
|
|
|
VERSION_H_FORMAT = """\
|
2019-06-03 16:07:15 +02:00
|
|
|
#pragma once
|
2021-09-20 10:16:59 +02:00
|
|
|
#include "esphome/core/macros.h"
|
2019-06-03 16:07:15 +02:00
|
|
|
#define ESPHOME_VERSION "{}"
|
2021-09-20 10:16:59 +02:00
|
|
|
#define ESPHOME_VERSION_CODE VERSION_CODE({}, {}, {})
|
2019-06-03 16:07:15 +02:00
|
|
|
"""
|
2021-03-07 20:03:16 +01:00
|
|
|
DEFINES_H_TARGET = "esphome/core/defines.h"
|
|
|
|
VERSION_H_TARGET = "esphome/core/version.h"
|
2019-12-07 18:28:55 +01:00
|
|
|
ESPHOME_README_TXT = """
|
2019-04-17 12:06:00 +02:00
|
|
|
THIS DIRECTORY IS AUTO-GENERATED, DO NOT MODIFY
|
|
|
|
|
2021-10-23 12:38:57 +02:00
|
|
|
ESPHome automatically populates the build directory, and any
|
2019-04-17 12:06:00 +02:00
|
|
|
changes to this directory will be removed the next time esphome is
|
|
|
|
run.
|
|
|
|
|
2021-10-23 12:38:57 +02:00
|
|
|
For modifying esphome's core files, please use a development esphome install,
|
|
|
|
the custom_components folder or the external_components feature.
|
2019-04-17 12:06:00 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def copy_src_tree():
|
2022-10-05 09:09:27 +02:00
|
|
|
source_files: list[loader.FileResource] = []
|
2019-04-17 12:06:00 +02:00
|
|
|
for _, component, _ in iter_components(CORE.config):
|
2021-09-20 11:47:51 +02:00
|
|
|
source_files += component.resources
|
|
|
|
source_files_map = {
|
|
|
|
Path(x.package.replace(".", "/") + "/" + x.resource): x for x in source_files
|
|
|
|
}
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
# Convert to list and sort
|
2021-09-20 11:47:51 +02:00
|
|
|
source_files_l = list(source_files_map.items())
|
2019-04-17 12:06:00 +02:00
|
|
|
source_files_l.sort()
|
|
|
|
|
2019-05-10 22:13:26 +02:00
|
|
|
# Build #include list for esphome.h
|
2019-04-17 12:06:00 +02:00
|
|
|
include_l = []
|
2021-05-07 20:02:17 +02:00
|
|
|
for target, _ in source_files_l:
|
|
|
|
if target.suffix in HEADER_FILE_EXTENSIONS:
|
2019-12-07 18:28:55 +01:00
|
|
|
include_l.append(f'#include "{target}"')
|
2021-03-07 20:03:16 +01:00
|
|
|
include_l.append("")
|
|
|
|
include_s = "\n".join(include_l)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
2021-09-20 11:47:51 +02:00
|
|
|
source_files_copy = source_files_map.copy()
|
2021-05-07 20:02:17 +02:00
|
|
|
ignore_targets = [Path(x) for x in (DEFINES_H_TARGET, VERSION_H_TARGET)]
|
|
|
|
for t in ignore_targets:
|
|
|
|
source_files_copy.pop(t)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
2021-05-07 20:02:17 +02:00
|
|
|
for fname in walk_files(CORE.relative_src_path("esphome")):
|
|
|
|
p = Path(fname)
|
|
|
|
if p.suffix not in SOURCE_FILE_EXTENSIONS:
|
2019-04-17 12:06:00 +02:00
|
|
|
# Not a source file, ignore
|
|
|
|
continue
|
|
|
|
# Transform path to target path name
|
2021-05-07 20:02:17 +02:00
|
|
|
target = p.relative_to(CORE.relative_src_path())
|
|
|
|
if target in ignore_targets:
|
2019-04-17 12:06:00 +02:00
|
|
|
# Ignore defines.h, will be dealt with later
|
|
|
|
continue
|
|
|
|
if target not in source_files_copy:
|
|
|
|
# Source file removed, delete target
|
2021-05-07 20:02:17 +02:00
|
|
|
p.unlink()
|
2019-04-17 12:06:00 +02:00
|
|
|
else:
|
2021-05-07 20:02:17 +02:00
|
|
|
src_file = source_files_copy.pop(target)
|
|
|
|
with src_file.path() as src_path:
|
|
|
|
copy_file_if_changed(src_path, p)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
# Now copy new files
|
2021-05-07 20:02:17 +02:00
|
|
|
for target, src_file in source_files_copy.items():
|
|
|
|
dst_path = CORE.relative_src_path(*target.parts)
|
|
|
|
with src_file.path() as src_path:
|
|
|
|
copy_file_if_changed(src_path, dst_path)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
# Finally copy defines
|
2021-03-07 20:03:16 +01:00
|
|
|
write_file_if_changed(
|
|
|
|
CORE.relative_src_path("esphome", "core", "defines.h"), generate_defines_h()
|
|
|
|
)
|
2021-10-23 12:38:57 +02:00
|
|
|
write_file_if_changed(CORE.relative_build_path("README.txt"), ESPHOME_README_TXT)
|
2021-03-07 20:03:16 +01:00
|
|
|
write_file_if_changed(
|
|
|
|
CORE.relative_src_path("esphome.h"), ESPHOME_H_FORMAT.format(include_s)
|
|
|
|
)
|
|
|
|
write_file_if_changed(
|
2021-09-20 10:16:59 +02:00
|
|
|
CORE.relative_src_path("esphome", "core", "version.h"), generate_version_h()
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
2021-09-20 11:47:51 +02:00
|
|
|
if CORE.is_esp32:
|
|
|
|
from esphome.components.esp32 import copy_files
|
|
|
|
|
|
|
|
copy_files()
|
|
|
|
|
2022-01-11 03:24:26 +01:00
|
|
|
elif CORE.is_esp8266:
|
|
|
|
from esphome.components.esp8266 import copy_files
|
|
|
|
|
|
|
|
copy_files()
|
|
|
|
|
2023-05-22 00:31:27 +02:00
|
|
|
elif CORE.is_rp2040:
|
|
|
|
from esphome.components.rp2040 import copy_files
|
|
|
|
|
|
|
|
(pio) = copy_files()
|
|
|
|
if pio:
|
|
|
|
write_file_if_changed(
|
|
|
|
CORE.relative_src_path("esphome.h"),
|
|
|
|
ESPHOME_H_FORMAT.format(include_s + '\n#include "pio_includes.h"'),
|
|
|
|
)
|
|
|
|
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
def generate_defines_h():
|
|
|
|
define_content_l = [x.as_macro for x in CORE.defines]
|
|
|
|
define_content_l.sort()
|
2021-03-07 20:03:16 +01:00
|
|
|
return DEFINES_H_FORMAT.format("\n".join(define_content_l))
|
2018-06-12 21:18:04 +02:00
|
|
|
|
|
|
|
|
2021-09-20 10:16:59 +02:00
|
|
|
def generate_version_h():
|
|
|
|
match = re.match(r"^(\d+)\.(\d+).(\d+)-?\w*$", __version__)
|
|
|
|
if not match:
|
|
|
|
raise EsphomeError(f"Could not parse version {__version__}.")
|
|
|
|
return VERSION_H_FORMAT.format(
|
|
|
|
__version__, match.group(1), match.group(2), match.group(3)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-12-05 21:22:06 +01:00
|
|
|
def write_cpp(code_s):
|
2021-03-07 20:03:16 +01:00
|
|
|
path = CORE.relative_src_path("main.cpp")
|
2018-04-07 01:23:03 +02:00
|
|
|
if os.path.isfile(path):
|
2019-04-17 12:06:00 +02:00
|
|
|
text = read_file(path)
|
2021-03-07 20:03:16 +01:00
|
|
|
code_format = find_begin_end(
|
|
|
|
text, CPP_AUTO_GENERATE_BEGIN, CPP_AUTO_GENERATE_END
|
|
|
|
)
|
|
|
|
code_format_ = find_begin_end(
|
|
|
|
code_format[0], CPP_INCLUDE_BEGIN, CPP_INCLUDE_END
|
|
|
|
)
|
2018-12-05 21:22:06 +01:00
|
|
|
code_format = (code_format_[0], code_format_[1], code_format[1])
|
2018-04-07 01:23:03 +02:00
|
|
|
else:
|
|
|
|
code_format = CPP_BASE_FORMAT
|
|
|
|
|
2019-05-10 22:13:26 +02:00
|
|
|
copy_src_tree()
|
2019-12-07 18:28:55 +01:00
|
|
|
global_s = '#include "esphome.h"\n'
|
2019-04-17 12:06:00 +02:00
|
|
|
global_s += CORE.cpp_global_section
|
2018-12-05 21:22:06 +01:00
|
|
|
|
2021-09-19 19:22:28 +02:00
|
|
|
full_file = f"{code_format[0] + CPP_INCLUDE_BEGIN}\n{global_s}{CPP_INCLUDE_END}"
|
2021-03-07 20:03:16 +01:00
|
|
|
full_file += (
|
2021-09-19 19:22:28 +02:00
|
|
|
f"{code_format[1] + CPP_AUTO_GENERATE_BEGIN}\n{code_s}{CPP_AUTO_GENERATE_END}"
|
2021-03-07 20:03:16 +01:00
|
|
|
)
|
2018-12-05 21:22:06 +01:00
|
|
|
full_file += code_format[2]
|
2019-10-24 21:53:42 +02:00
|
|
|
write_file_if_changed(path, full_file)
|
2018-06-08 11:34:06 +02:00
|
|
|
|
|
|
|
|
2018-12-05 21:22:06 +01:00
|
|
|
def clean_build():
|
2019-04-08 22:19:21 +02:00
|
|
|
import shutil
|
|
|
|
|
2019-03-03 16:50:06 +01:00
|
|
|
pioenvs = CORE.relative_pioenvs_path()
|
|
|
|
if os.path.isdir(pioenvs):
|
|
|
|
_LOGGER.info("Deleting %s", pioenvs)
|
|
|
|
shutil.rmtree(pioenvs)
|
|
|
|
piolibdeps = CORE.relative_piolibdeps_path()
|
|
|
|
if os.path.isdir(piolibdeps):
|
|
|
|
_LOGGER.info("Deleting %s", piolibdeps)
|
|
|
|
shutil.rmtree(piolibdeps)
|
2018-12-18 19:31:43 +01:00
|
|
|
|
|
|
|
|
2019-02-13 16:54:02 +01:00
|
|
|
GITIGNORE_CONTENT = """# Gitignore settings for ESPHome
|
2018-12-18 19:31:43 +01:00
|
|
|
# This is an example and may include too much for your use-case.
|
|
|
|
# You can modify this file to suit your needs.
|
2019-02-13 16:54:02 +01:00
|
|
|
/.esphome/
|
2018-12-18 19:31:43 +01:00
|
|
|
/secrets.yaml
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def write_gitignore():
|
2021-03-07 20:03:16 +01:00
|
|
|
path = CORE.relative_config_path(".gitignore")
|
2018-12-18 19:31:43 +01:00
|
|
|
if not os.path.isfile(path):
|
2021-08-31 04:00:58 +02:00
|
|
|
with open(file=path, mode="w", encoding="utf-8") as f:
|
2018-12-18 19:31:43 +01:00
|
|
|
f.write(GITIGNORE_CONTENT)
|