diff options
author | Dmitry Kopylov <kopylovd@gmail.com> | 2022-02-10 16:48:18 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:18 +0300 |
commit | b2f5101486cc0de2e979c8ba9ada2109785bf5fd (patch) | |
tree | affe28b840816b505db0467f2285b01c89c04247 /library/python/testing/yatest_common/yatest/common/path.py | |
parent | e9b28b5aad71453a4637b70dde02e801e4147a2a (diff) | |
download | ydb-b2f5101486cc0de2e979c8ba9ada2109785bf5fd.tar.gz |
Restoring authorship annotation for Dmitry Kopylov <kopylovd@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/python/testing/yatest_common/yatest/common/path.py')
-rw-r--r-- | library/python/testing/yatest_common/yatest/common/path.py | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/library/python/testing/yatest_common/yatest/common/path.py b/library/python/testing/yatest_common/yatest/common/path.py index 6fed7dda8a..d31df2d278 100644 --- a/library/python/testing/yatest_common/yatest/common/path.py +++ b/library/python/testing/yatest_common/yatest/common/path.py @@ -1,5 +1,5 @@ # coding=utf-8 - + import errno import os import shutil @@ -8,19 +8,19 @@ import contextlib import library.python.fs as lpf -def replace_in_file(path, old, new): - """ - Replace text occurrences in a file - :param path: path to the file - :param old: text to replace - :param new: replacement - """ - with open(path) as fp: - content = fp.read() - +def replace_in_file(path, old, new): + """ + Replace text occurrences in a file + :param path: path to the file + :param old: text to replace + :param new: replacement + """ + with open(path) as fp: + content = fp.read() + lpf.ensure_removed(path) - with open(path, 'w') as fp: - fp.write(content.replace(old, new)) + with open(path, 'w') as fp: + fp.write(content.replace(old, new)) @contextlib.contextmanager @@ -38,8 +38,8 @@ def copytree(src, dst, symlinks=False, ignore=None, postprocessing=None): Copy an entire directory of files into an existing directory instead of raising Exception what shtuil.copytree does ''' - if not os.path.exists(dst) and os.path.isdir(src): - os.makedirs(dst) + if not os.path.exists(dst) and os.path.isdir(src): + os.makedirs(dst) for item in os.listdir(src): s = os.path.join(src, item) d = os.path.join(dst, item) @@ -54,8 +54,8 @@ def copytree(src, dst, symlinks=False, ignore=None, postprocessing=None): postprocessing(os.path.join(root, path), False) for path in files: postprocessing(os.path.join(root, path), True) - - + + def get_unique_file_path(dir_path, file_pattern, create_file=True, max_suffix=10000): def atomic_file_create(path): try: @@ -79,12 +79,12 @@ def get_unique_file_path(dir_path, file_pattern, create_file=True, max_suffix=10 return False raise e - file_path = os.path.join(dir_path, file_pattern) + file_path = os.path.join(dir_path, file_pattern) lpf.ensure_dir(os.path.dirname(file_path)) - file_counter = 0 + file_counter = 0 handler = atomic_file_create if create_file else atomic_dir_create while os.path.exists(file_path) or not handler(file_path): - file_path = os.path.join(dir_path, file_pattern + ".{}".format(file_counter)) - file_counter += 1 + file_path = os.path.join(dir_path, file_pattern + ".{}".format(file_counter)) + file_counter += 1 assert file_counter < max_suffix - return file_path + return file_path |