From 03646d1e891271339ca256fadd15eaa8ac678911 Mon Sep 17 00:00:00 2001 From: Elizabeth Date: Mon, 2 Jun 2025 15:54:32 -0700 Subject: Make it a python package --- dots_manager/stow.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 dots_manager/stow.py (limited to 'dots_manager/stow.py') 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) -- cgit v1.2.3-70-g09d2