diff options
Diffstat (limited to 'dots_manager/stow.py')
-rw-r--r-- | dots_manager/stow.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/dots_manager/stow.py b/dots_manager/stow.py new file mode 100644 index 0000000..52a9e36 --- /dev/null +++ b/dots_manager/stow.py @@ -0,0 +1,40 @@ +from pathlib import Path +from typing import Literal +from .env import Environment +from .shell import run_shell_command +from .parallel import parallelize +from .utils import is_some + + +def list_stowable_packages(packages: Path) -> list[Path]: + denylist = [".", "__"] + return [ + d + for d in packages.iterdir() + if d.is_dir() and all(y not in d.name for y in denylist) + ] + + +def apply_stow_operation_to_packages( + packages: Path, + target: Path, + stow_op: Literal["-D", "--no-folding"], + env: Environment, +) -> bool: + if not run_shell_command(["stow", "--version"], env.logger): + env.logger.error("stow not installed D:") + return False + + package_command = ["stow", "-d", str(packages), "-t", str(target), stow_op] + _packages = list_stowable_packages(packages) + env.logger.debug(f"found dotfile packages: {_packages}") + + commands = [package_command + [package.name] for package in _packages] + env.logger.debug(f"stowing packages: {commands}") + + results = parallelize( + lambda command: is_some(run_shell_command, command, env.logger)[0], + commands, + env, + ) + return len(commands) == sum(1 if x else 0 for x in results) |