esp-idf/tools/test_build_system/test_build_system_helpers/editing.py

18 lines
585 B
Python
Raw Normal View History

# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import typing
from pathlib import Path
def append_to_file(filename: typing.Union[str, Path], what: str) -> None:
with open(filename, 'a', encoding='utf-8') as f:
f.write(what)
def replace_in_file(filename: typing.Union[str, Path], search: str, replace: str) -> None:
with open(filename, 'r', encoding='utf-8') as f:
data = f.read()
result = data.replace(search, replace)
with open(filename, 'w', encoding='utf-8') as f:
f.write(result)