aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/testing/yatest_common/yatest/common/path.py
diff options
context:
space:
mode:
authordvshkurko <dvshkurko@yandex-team.ru>2022-02-10 16:45:51 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:51 +0300
commit321ee9bce31ec6e238be26dbcbe539cffa2c3309 (patch)
tree14407a2757cbf29eb97e266b7f07e851f971000c /library/python/testing/yatest_common/yatest/common/path.py
parent2f6ca198245aeffd5e2d82b65927c2465b68b4f5 (diff)
downloadydb-321ee9bce31ec6e238be26dbcbe539cffa2c3309.tar.gz
Restoring authorship annotation for <dvshkurko@yandex-team.ru>. 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.py60
1 files changed, 30 insertions, 30 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..1d08f72e62 100644
--- a/library/python/testing/yatest_common/yatest/common/path.py
+++ b/library/python/testing/yatest_common/yatest/common/path.py
@@ -1,13 +1,13 @@
# coding=utf-8
-import errno
+import errno
import os
import shutil
import contextlib
-import library.python.fs as lpf
-
+import library.python.fs as lpf
+
def replace_in_file(path, old, new):
"""
Replace text occurrences in a file
@@ -18,7 +18,7 @@ def replace_in_file(path, old, new):
with open(path) as fp:
content = fp.read()
- lpf.ensure_removed(path)
+ lpf.ensure_removed(path)
with open(path, 'w') as fp:
fp.write(content.replace(old, new))
@@ -56,35 +56,35 @@ def copytree(src, dst, symlinks=False, ignore=None, postprocessing=None):
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:
+def get_unique_file_path(dir_path, file_pattern, create_file=True, max_suffix=10000):
+ def atomic_file_create(path):
+ try:
fd = os.open(path, os.O_CREAT | os.O_EXCL, 0o644)
- os.close(fd)
- return True
- except OSError as e:
- if e.errno in [errno.EEXIST, errno.EISDIR, errno.ETXTBSY]:
- return False
- # Access issue with file itself, not parent directory.
- if e.errno == errno.EACCES and os.path.exists(path):
- return False
- raise e
-
- def atomic_dir_create(path):
- try:
- os.mkdir(path)
- return True
- except OSError as e:
- if e.errno == errno.EEXIST:
- return False
- raise e
-
+ os.close(fd)
+ return True
+ except OSError as e:
+ if e.errno in [errno.EEXIST, errno.EISDIR, errno.ETXTBSY]:
+ return False
+ # Access issue with file itself, not parent directory.
+ if e.errno == errno.EACCES and os.path.exists(path):
+ return False
+ raise e
+
+ def atomic_dir_create(path):
+ try:
+ os.mkdir(path)
+ return True
+ except OSError as e:
+ if e.errno == errno.EEXIST:
+ return False
+ raise e
+
file_path = os.path.join(dir_path, file_pattern)
- lpf.ensure_dir(os.path.dirname(file_path))
+ lpf.ensure_dir(os.path.dirname(file_path))
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):
+ 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
- assert file_counter < max_suffix
+ assert file_counter < max_suffix
return file_path