-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "cobbler-tftp setup" command to install configuration files
- Loading branch information
1 parent
ddfc818
commit 6c0eb91
Showing
2 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
Various utility functions for cobbler-tftp | ||
""" | ||
|
||
from pathlib import Path | ||
from typing import List, Tuple | ||
|
||
try: | ||
from importlib.abc import Traversable | ||
except ImportError: | ||
from importlib_resources.abc import Traversable | ||
|
||
|
||
def copy_file( | ||
src_dir: Traversable, dst_dir: Path, name: str, patch: List[Tuple[str, str]] = [] | ||
): | ||
""" | ||
Copy a file to a different directory, preserving the name and | ||
possibly replacing strings in it. | ||
:param src_dir: Directory that contains the file to copy. | ||
:param dst_dir: Directory to copy the file into. | ||
:param name: Name of the file (in both directories). | ||
:param patch: List of (old, new) strings to replace in the file. | ||
""" | ||
src = src_dir / name | ||
dst = dst_dir / name | ||
contents: bytes = src.read_bytes() # type: ignore | ||
for old, new in patch: | ||
contents = contents.replace(old.encode("UTF-8"), new.encode("UTF-8")) | ||
dst.write_bytes(contents) |