mirror of
https://github.com/esphome/esphome.git
synced 2025-10-11 22:33:49 +01:00
[core] os.path -> Path (#10654)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: J. Nick Koston <nick@koston.org> Co-authored-by: J. Nick Koston <nick@home-assistant.io>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import random
|
||||
import string
|
||||
from typing import Literal, NotRequired, TypedDict, Unpack
|
||||
@@ -213,7 +213,7 @@ class WizardWriteKwargs(TypedDict):
|
||||
file_text: NotRequired[str]
|
||||
|
||||
|
||||
def wizard_write(path: str, **kwargs: Unpack[WizardWriteKwargs]) -> bool:
|
||||
def wizard_write(path: Path, **kwargs: Unpack[WizardWriteKwargs]) -> bool:
|
||||
from esphome.components.bk72xx import boards as bk72xx_boards
|
||||
from esphome.components.esp32 import boards as esp32_boards
|
||||
from esphome.components.esp8266 import boards as esp8266_boards
|
||||
@@ -256,13 +256,13 @@ def wizard_write(path: str, **kwargs: Unpack[WizardWriteKwargs]) -> bool:
|
||||
file_text = wizard_file(**kwargs)
|
||||
|
||||
# Check if file already exists to prevent overwriting
|
||||
if os.path.exists(path) and os.path.isfile(path):
|
||||
if path.exists() and path.is_file():
|
||||
safe_print(color(AnsiFore.RED, f'The file "{path}" already exists.'))
|
||||
return False
|
||||
|
||||
write_file(path, file_text)
|
||||
storage = StorageJSON.from_wizard(name, name, f"{name}.local", hardware)
|
||||
storage_path = ext_storage_path(os.path.basename(path))
|
||||
storage_path = ext_storage_path(path.name)
|
||||
storage.save(storage_path)
|
||||
|
||||
return True
|
||||
@@ -301,7 +301,7 @@ def strip_accents(value: str) -> str:
|
||||
)
|
||||
|
||||
|
||||
def wizard(path: str) -> int:
|
||||
def wizard(path: Path) -> int:
|
||||
from esphome.components.bk72xx import boards as bk72xx_boards
|
||||
from esphome.components.esp32 import boards as esp32_boards
|
||||
from esphome.components.esp8266 import boards as esp8266_boards
|
||||
@@ -309,14 +309,14 @@ def wizard(path: str) -> int:
|
||||
from esphome.components.rp2040 import boards as rp2040_boards
|
||||
from esphome.components.rtl87xx import boards as rtl87xx_boards
|
||||
|
||||
if not path.endswith(".yaml") and not path.endswith(".yml"):
|
||||
if path.suffix not in (".yaml", ".yml"):
|
||||
safe_print(
|
||||
f"Please make your configuration file {color(AnsiFore.CYAN, path)} have the extension .yaml or .yml"
|
||||
f"Please make your configuration file {color(AnsiFore.CYAN, str(path))} have the extension .yaml or .yml"
|
||||
)
|
||||
return 1
|
||||
if os.path.exists(path):
|
||||
if path.exists():
|
||||
safe_print(
|
||||
f"Uh oh, it seems like {color(AnsiFore.CYAN, path)} already exists, please delete that file first or chose another configuration file."
|
||||
f"Uh oh, it seems like {color(AnsiFore.CYAN, str(path))} already exists, please delete that file first or chose another configuration file."
|
||||
)
|
||||
return 2
|
||||
|
||||
@@ -549,7 +549,7 @@ def wizard(path: str) -> int:
|
||||
safe_print()
|
||||
safe_print(
|
||||
color(AnsiFore.CYAN, "DONE! I've now written a new configuration file to ")
|
||||
+ color(AnsiFore.BOLD_CYAN, path)
|
||||
+ color(AnsiFore.BOLD_CYAN, str(path))
|
||||
)
|
||||
safe_print()
|
||||
safe_print("Next steps:")
|
||||
|
Reference in New Issue
Block a user