aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/fs
diff options
context:
space:
mode:
authorAleksandr <ivansduck@gmail.com>2022-02-10 16:47:52 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:52 +0300
commitea6c5b7f172becca389cacaff7d5f45f6adccbe6 (patch)
treed16cef493ac1e092b4a03ab9437ec06ffe3d188f /library/python/fs
parent37de222addabbef336dcaaea5f7c7645a629fc6d (diff)
downloadydb-ea6c5b7f172becca389cacaff7d5f45f6adccbe6.tar.gz
Restoring authorship annotation for Aleksandr <ivansduck@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/python/fs')
-rw-r--r--library/python/fs/__init__.py96
-rw-r--r--library/python/fs/test/test_fs.py62
2 files changed, 79 insertions, 79 deletions
diff --git a/library/python/fs/__init__.py b/library/python/fs/__init__.py
index b1b7cde079..c9651b03ae 100644
--- a/library/python/fs/__init__.py
+++ b/library/python/fs/__init__.py
@@ -4,11 +4,11 @@ import codecs
import errno
import logging
import os
-import random
+import random
import shutil
import six
import stat
-import sys
+import sys
import library.python.func
import library.python.strings
@@ -202,13 +202,13 @@ def hardlink_or_copy(src, lnk):
if WindowsError is not None and isinstance(exc, WindowsError) and exc.winerror == 1142: # too many hardlinks
return True
# cross-device hardlink or too many hardlinks, or some known WSL error
- if isinstance(exc, OSError) and exc.errno in (
- errno.EXDEV,
- errno.EMLINK,
- errno.EINVAL,
- errno.EACCES,
- errno.EPERM,
- ):
+ if isinstance(exc, OSError) and exc.errno in (
+ errno.EXDEV,
+ errno.EMLINK,
+ errno.EINVAL,
+ errno.EACCES,
+ errno.EPERM,
+ ):
return True
return False
@@ -312,9 +312,9 @@ def read_file_unicode(path, binary=True, enc='utf-8'):
@errorfix_win
def open_file(*args, **kwargs):
- return (
- library.python.windows.open_file(*args, **kwargs) if library.python.windows.on_win() else open(*args, **kwargs)
- )
+ return (
+ library.python.windows.open_file(*args, **kwargs) if library.python.windows.on_win() else open(*args, **kwargs)
+ )
# Atomic file write
@@ -363,15 +363,15 @@ def get_tree_size(path, recursive=False, raise_all_errors=False):
# Directory copy ported from Python 3
-def copytree3(
- src,
- dst,
- symlinks=False,
- ignore=None,
- copy_function=shutil.copy2,
- ignore_dangling_symlinks=False,
- dirs_exist_ok=False,
-):
+def copytree3(
+ src,
+ dst,
+ symlinks=False,
+ ignore=None,
+ copy_function=shutil.copy2,
+ ignore_dangling_symlinks=False,
+ dirs_exist_ok=False,
+):
"""Recursively copy a directory tree.
The copytree3 is a port of shutil.copytree function from python-3.2.
@@ -467,35 +467,35 @@ def walk_relative(path, topdown=True, onerror=None, followlinks=False):
for dirpath, dirnames, filenames in os.walk(path, topdown=topdown, onerror=onerror, followlinks=followlinks):
yield os.path.relpath(dirpath, path), dirnames, filenames
-
+
def supports_clone():
if 'darwin' in sys.platform:
import platform
-
+
return list(map(int, platform.mac_ver()[0].split('.'))) >= [10, 13]
return False
-
-
-def commonpath(paths):
- assert paths
- if len(paths) == 1:
- return next(iter(paths))
-
- split_paths = [path.split(os.sep) for path in paths]
- smin = min(split_paths)
- smax = max(split_paths)
-
- common = smin
- for i, c in enumerate(smin):
- if c != smax[i]:
- common = smin[:i]
- break
-
- return os.path.sep.join(common)
-
-
-def set_execute_bits(filename):
- stm = os.stat(filename).st_mode
- exe = stm | 0o111
- if stm != exe:
- os.chmod(filename, exe)
+
+
+def commonpath(paths):
+ assert paths
+ if len(paths) == 1:
+ return next(iter(paths))
+
+ split_paths = [path.split(os.sep) for path in paths]
+ smin = min(split_paths)
+ smax = max(split_paths)
+
+ common = smin
+ for i, c in enumerate(smin):
+ if c != smax[i]:
+ common = smin[:i]
+ break
+
+ return os.path.sep.join(common)
+
+
+def set_execute_bits(filename):
+ stm = os.stat(filename).st_mode
+ exe = stm | 0o111
+ if stm != exe:
+ os.chmod(filename, exe)
diff --git a/library/python/fs/test/test_fs.py b/library/python/fs/test/test_fs.py
index 9e2c70c069..5c1c6030b5 100644
--- a/library/python/fs/test/test_fs.py
+++ b/library/python/fs/test/test_fs.py
@@ -18,16 +18,16 @@ def in_env(case):
def wrapped_case(*args, **kwargs):
with library.python.tmp.temp_dir() as temp_dir:
case(lambda path: os.path.join(temp_dir, path))
-
+
return wrapped_case
def mkfile(path, data=''):
with open(path, 'wb') as f:
if data:
- f.write(data) if isinstance(data, six.binary_type) else f.write(
- data.encode(library.python.strings.fs_encoding())
- )
+ f.write(data) if isinstance(data, six.binary_type) else f.write(
+ data.encode(library.python.strings.fs_encoding())
+ )
def mktree_example(path, name):
@@ -820,20 +820,20 @@ def test_read_file_empty(path):
@in_env
def test_read_file_multiline(path):
mkfile(path('src'), 'SRC line 1\nSRC line 2\n')
- assert (
- library.python.fs.read_file(path('src')).decode(library.python.strings.fs_encoding())
- == 'SRC line 1\nSRC line 2\n'
- )
+ assert (
+ library.python.fs.read_file(path('src')).decode(library.python.strings.fs_encoding())
+ == 'SRC line 1\nSRC line 2\n'
+ )
assert library.python.fs.read_file(path('src'), binary=False) == 'SRC line 1\nSRC line 2\n'
@in_env
def test_read_file_multiline_crlf(path):
mkfile(path('src'), 'SRC line 1\r\nSRC line 2\r\n')
- assert (
- library.python.fs.read_file(path('src')).decode(library.python.strings.fs_encoding())
- == 'SRC line 1\r\nSRC line 2\r\n'
- )
+ assert (
+ library.python.fs.read_file(path('src')).decode(library.python.strings.fs_encoding())
+ == 'SRC line 1\r\nSRC line 2\r\n'
+ )
if library.python.windows.on_win() or six.PY3: # universal newlines are by default in text mode in python3
assert library.python.fs.read_file(path('src'), binary=False) == 'SRC line 1\nSRC line 2\n'
else:
@@ -1005,9 +1005,9 @@ def test_copy_tree_custom_copy_function():
shutil.copy2(src, dst)
copied.append(dst)
- library.python.fs.copy_tree(
- "test_copy_tree_src", yatest.common.work_path("test_copy_tree_dst"), copy_function=copy_function
- )
+ library.python.fs.copy_tree(
+ "test_copy_tree_src", yatest.common.work_path("test_copy_tree_dst"), copy_function=copy_function
+ )
assert len(copied) == 2
assert yatest.common.work_path("test_copy_tree_dst/deepper/deepper.txt") in copied
assert yatest.common.work_path("test_copy_tree_dst/deepper/inner/inner.txt") in copied
@@ -1019,19 +1019,19 @@ def test_copy2():
assert os.path.islink("link2")
assert os.readlink("link2") == "non-existent"
-
-
-def test_commonpath():
- pj = os.path.join
- pja = lambda *x: os.path.abspath(pj(*x))
-
- assert library.python.fs.commonpath(['a', 'b']) == ''
- assert library.python.fs.commonpath([pj('t', '1')]) == pj('t', '1')
- assert library.python.fs.commonpath([pj('t', '1'), pj('t', '2')]) == pj('t')
- assert library.python.fs.commonpath([pj('t', '1', '2'), pj('t', '1', '2')]) == pj('t', '1', '2')
- assert library.python.fs.commonpath([pj('t', '1', '1'), pj('t', '1', '2')]) == pj('t', '1')
- assert library.python.fs.commonpath([pj('t', '1', '1'), pj('t', '1', '2'), pj('t', '1', '3')]) == pj('t', '1')
-
- assert library.python.fs.commonpath([pja('t', '1', '1'), pja('t', '1', '2')]) == pja('t', '1')
-
- assert library.python.fs.commonpath({pj('t', '1'), pj('t', '2')}) == pj('t')
+
+
+def test_commonpath():
+ pj = os.path.join
+ pja = lambda *x: os.path.abspath(pj(*x))
+
+ assert library.python.fs.commonpath(['a', 'b']) == ''
+ assert library.python.fs.commonpath([pj('t', '1')]) == pj('t', '1')
+ assert library.python.fs.commonpath([pj('t', '1'), pj('t', '2')]) == pj('t')
+ assert library.python.fs.commonpath([pj('t', '1', '2'), pj('t', '1', '2')]) == pj('t', '1', '2')
+ assert library.python.fs.commonpath([pj('t', '1', '1'), pj('t', '1', '2')]) == pj('t', '1')
+ assert library.python.fs.commonpath([pj('t', '1', '1'), pj('t', '1', '2'), pj('t', '1', '3')]) == pj('t', '1')
+
+ assert library.python.fs.commonpath([pja('t', '1', '1'), pja('t', '1', '2')]) == pja('t', '1')
+
+ assert library.python.fs.commonpath({pj('t', '1'), pj('t', '2')}) == pj('t')