From 803a91c0723533f62148528a81f9d0411b57438e Mon Sep 17 00:00:00 2001 From: Dmitrii Agibov Date: Mon, 20 Feb 2023 15:42:33 +0000 Subject: MLIA-813 Change default output directory - Use directory mlia-output as output directory for MLIA - If parameter --output-dir provided then place directory mlia-output under specified path or otherwise create it in the current working directory Change-Id: I298088c4aa8dbe9f35dee69ecb9ff6e9ea3cac0a --- src/mlia/utils/filesystem.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/mlia/utils') diff --git a/src/mlia/utils/filesystem.py b/src/mlia/utils/filesystem.py index f92629b..f8e8962 100644 --- a/src/mlia/utils/filesystem.py +++ b/src/mlia/utils/filesystem.py @@ -14,6 +14,8 @@ from tempfile import TemporaryDirectory from typing import Generator from typing import Iterable +USER_ONLY_PERM_MASK = 0o700 + def get_mlia_resources() -> Path: """Get the path to the resources directory.""" @@ -96,6 +98,17 @@ def copy_all(*paths: Path, dest: Path) -> None: shutil.copytree(path, dest, dirs_exist_ok=True) +def recreate_directory(dir_path: Path, mode: int = USER_ONLY_PERM_MASK) -> None: + """Recreate directory.""" + if dir_path.exists(): + if not dir_path.is_dir(): + raise ValueError(f"Path {dir_path} is not a directory.") + + shutil.rmtree(dir_path) + + dir_path.mkdir(exist_ok=True, mode=mode) + + @contextmanager def working_directory( working_dir: Path, create_dir: bool = False -- cgit v1.2.1