mirror of
https://github.com/esphome/esphome.git
synced 2025-09-22 13:12:22 +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,9 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import glob
|
||||
import inspect
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
import voluptuous as vol
|
||||
@@ -70,14 +70,14 @@ def get_component_names():
|
||||
component_names = ["esphome", "sensor", "esp32", "esp8266"]
|
||||
skip_components = []
|
||||
|
||||
for d in os.listdir(CORE_COMPONENTS_PATH):
|
||||
for d in CORE_COMPONENTS_PATH.iterdir():
|
||||
if (
|
||||
not d.startswith("__")
|
||||
and os.path.isdir(os.path.join(CORE_COMPONENTS_PATH, d))
|
||||
and d not in component_names
|
||||
and d not in skip_components
|
||||
not d.name.startswith("__")
|
||||
and d.is_dir()
|
||||
and d.name not in component_names
|
||||
and d.name not in skip_components
|
||||
):
|
||||
component_names.append(d)
|
||||
component_names.append(d.name)
|
||||
|
||||
return sorted(component_names)
|
||||
|
||||
@@ -121,7 +121,7 @@ from esphome.util import Registry # noqa: E402
|
||||
|
||||
|
||||
def write_file(name, obj):
|
||||
full_path = os.path.join(args.output_path, name + ".json")
|
||||
full_path = Path(args.output_path) / f"{name}.json"
|
||||
if JSON_DUMP_PRETTY:
|
||||
json_str = json.dumps(obj, indent=2)
|
||||
else:
|
||||
@@ -131,9 +131,10 @@ def write_file(name, obj):
|
||||
|
||||
|
||||
def delete_extra_files(keep_names):
|
||||
for d in os.listdir(args.output_path):
|
||||
if d.endswith(".json") and d[:-5] not in keep_names:
|
||||
os.remove(os.path.join(args.output_path, d))
|
||||
output_path = Path(args.output_path)
|
||||
for d in output_path.iterdir():
|
||||
if d.suffix == ".json" and d.stem not in keep_names:
|
||||
d.unlink()
|
||||
print(f"Deleted {d}")
|
||||
|
||||
|
||||
@@ -367,13 +368,11 @@ def get_logger_tags():
|
||||
"scheduler",
|
||||
"api.service",
|
||||
]
|
||||
for x in os.walk(CORE_COMPONENTS_PATH):
|
||||
for y in glob.glob(os.path.join(x[0], "*.cpp")):
|
||||
with open(y, encoding="utf-8") as file:
|
||||
data = file.read()
|
||||
match = pattern.search(data)
|
||||
if match:
|
||||
tags.append(match.group(1))
|
||||
for file in CORE_COMPONENTS_PATH.rglob("*.cpp"):
|
||||
data = file.read_text()
|
||||
match = pattern.search(data)
|
||||
if match:
|
||||
tags.append(match.group(1))
|
||||
return tags
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user