diff options
author | alexv-smirnov <alex@ydb.tech> | 2023-10-18 11:29:37 +0300 |
---|---|---|
committer | alexv-smirnov <alex@ydb.tech> | 2023-10-18 13:06:09 +0300 |
commit | 9ae2b50e805245bff2d8be04123f4e7f08806324 (patch) | |
tree | d97eaff30d6ea46d9c957ddbb57573f9044b5523 /library/python/testing/swag/pathutil.py | |
parent | 18dc72ed9a86762cd037f5e41fb79cec458b3c2c (diff) | |
download | ydb-9ae2b50e805245bff2d8be04123f4e7f08806324.tar.gz |
Move swag from devtools/ to library/python/testing/
Diffstat (limited to 'library/python/testing/swag/pathutil.py')
-rw-r--r-- | library/python/testing/swag/pathutil.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/library/python/testing/swag/pathutil.py b/library/python/testing/swag/pathutil.py new file mode 100644 index 00000000000..3f7910eff3e --- /dev/null +++ b/library/python/testing/swag/pathutil.py @@ -0,0 +1,26 @@ +import os +import tempfile + + +def get_valid_filename(filename, dirname): + current_file, counter = filename, 0 + while os.path.exists(os.path.join(dirname, current_file)): + current_file = "%s_%d" % (filename, counter) + counter += 1 + valid_path = os.path.join(dirname, current_file) + os.mknod(valid_path) + return valid_path + + +def get_valid_tmpdir(name, tmp_dir): + current_dir, counter = name, 0 + while os.path.exists(os.path.join(tmp_dir, current_dir)): + current_dir = "%s_%d" % (name, counter) + counter += 1 + os.mkdir(os.path.join(tmp_dir, current_dir)) + return os.path.join(tmp_dir, current_dir) + + +def get_base_tmpdir(name): + tmppath = tempfile.gettempdir() + return get_valid_tmpdir(name, tmppath) |