6from contextlib
import contextmanager
7from tempfile
import NamedTemporaryFile
8from typing
import Any, BinaryIO, Generator, List, Union, cast
16def check_path_owner(path: str) -> bool:
25 while path != previous:
32 path_uid = get_path_uid(path)
44def adjacent_tmp_file(path: str, **kwargs: Any) -> Generator[BinaryIO,
None,
None]:
45 """Return a file-like object pointing to a tmp file next to path.
47 The file is created securely and is ensured to be written to disk
48 after the context reaches its end.
50 kwargs will be passed to tempfile.NamedTemporaryFile to control
51 the way the temporary file will be opened.
53 with NamedTemporaryFile(
60 result = cast(BinaryIO, f)
76def test_writable_dir(path: str) -> bool:
77 """Check if a directory is writable.
79 Uses os.access() on POSIX, tries creating files on Windows.
97 basename =
"accesstest_deleteme_fishfingers_custard_"
98 alphabet =
"abcdefghijklmnopqrstuvwxyz0123456789"
104 except FileExistsError:
106 except PermissionError:
119 raise OSError(
"Unexpected condition testing for writable directory")
123 """Returns a list of absolute paths of files beneath path, recursively,
124 with filenames which match the UNIX-style shell glob pattern."""
125 result: List[str] = []
126 for root, _, files
in os.walk(path):
145 for root, _dirs, files
in os.walk(path):
146 for filename
in files:
List[str] find_files(str path, str pattern)
Union[int, float] directory_size(str path)
Union[int, float] file_size(str path)
str format_file_size(str path)
str format_directory_size(str path)
bool _test_writable_dir_win(str path)