From ddf4d47c42fc6788e6e24a69343d900638ee029a Mon Sep 17 00:00:00 2001 From: Mathieu Beligon <mathieu@feedly.com> Date: Sat, 20 Feb 2021 19:41:13 -0500 Subject: [PATCH] [utils] Add path utils --- src/polystar/utils/path.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/polystar/utils/path.py diff --git a/src/polystar/utils/path.py b/src/polystar/utils/path.py new file mode 100644 index 0000000..be35166 --- /dev/null +++ b/src/polystar/utils/path.py @@ -0,0 +1,22 @@ +from pathlib import Path +from shutil import copy, make_archive, move +from typing import Iterable + + +def move_file(source: Path, destination_directory: Path): + destination_directory.mkdir(exist_ok=True, parents=True) + move(str(source), str(destination_directory)) + + +def move_files(sources: Iterable[Path], destination_directory: Path): + for source in sources: + move_file(source, destination_directory) + + +def copy_file(source: Path, destination_directory: Path): + destination_directory.mkdir(exist_ok=True, parents=True) + copy(str(source), str(destination_directory)) + + +def archive_directory(directory:Path): + make_archive(str(directory), "zip", str(directory)) -- GitLab