Compare commits
No commits in common. "51b4f0f5f29ef0af7e523eae026f19793fac8941" and "0e2b638bbbf6efe4cdf23bc1f6bd86059e23abd5" have entirely different histories.
51b4f0f5f2
...
0e2b638bbb
10 changed files with 45 additions and 53 deletions
|
@ -4,12 +4,12 @@
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from rwx import fs
|
import fs
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
file_path: Path = Path(__file__).resolve()
|
file_path = Path(__file__).resolve()
|
||||||
root_path: Path = file_path.parent
|
root_path = file_path.parent
|
||||||
directory_path: Path = root_path / "tmp"
|
directory_path = root_path / "tmp"
|
||||||
file_path = directory_path / "file"
|
file_path = directory_path / "file"
|
||||||
|
|
||||||
fs.wipe(directory_path)
|
fs.wipe(directory_path)
|
||||||
|
|
|
@ -6,7 +6,6 @@ packages: list[str] = []
|
||||||
|
|
||||||
def need(command: str) -> None:
|
def need(command: str) -> None:
|
||||||
"""Assert package dependency for a command."""
|
"""Assert package dependency for a command."""
|
||||||
package: str | None
|
|
||||||
match command:
|
match command:
|
||||||
case "debootstrap":
|
case "debootstrap":
|
||||||
package = "debootstrap"
|
package = "debootstrap"
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
"""Wrap SquashFS commands."""
|
"""Wrap SquashFS commands."""
|
||||||
|
|
||||||
from rwx import cmd, ps
|
import ps
|
||||||
|
|
||||||
cmd.need("mksquashfs")
|
import rwx.cmd
|
||||||
|
|
||||||
|
rwx.cmd.need("mksquashfs")
|
||||||
|
|
||||||
|
|
||||||
def mksquashfs(input_root: str, output_file: str) -> None:
|
def mksquashfs(input_root: str, output_file: str) -> None:
|
||||||
"""Make a SquashFS bootable image file."""
|
"""Make a SquashFS bootable image file."""
|
||||||
ps.run(
|
ps.run(
|
||||||
|
[
|
||||||
"mksquashfs",
|
"mksquashfs",
|
||||||
input_root,
|
input_root,
|
||||||
output_file,
|
output_file,
|
||||||
|
@ -15,4 +18,5 @@ def mksquashfs(input_root: str, output_file: str) -> None:
|
||||||
"zstd",
|
"zstd",
|
||||||
"-Xcompression-level",
|
"-Xcompression-level",
|
||||||
str(18),
|
str(18),
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
"""Wrap Debian commands."""
|
"""Wrap Debian commands."""
|
||||||
|
|
||||||
from rwx import cmd, ps
|
import cmd
|
||||||
|
|
||||||
|
import ps
|
||||||
|
|
||||||
cmd.need("debootstrap")
|
cmd.need("debootstrap")
|
||||||
|
|
||||||
|
@ -18,4 +20,4 @@ def bootstrap(root_path: str, suite: str, mirror_location: str) -> None:
|
||||||
(root_path,),
|
(root_path,),
|
||||||
(mirror_location,),
|
(mirror_location,),
|
||||||
]
|
]
|
||||||
ps.run(*command)
|
return ps.run(command)
|
||||||
|
|
|
@ -14,11 +14,11 @@ def create_image(file_path: str, size_bytes: int) -> None:
|
||||||
ps.run(
|
ps.run(
|
||||||
("qemu-img", "create"),
|
("qemu-img", "create"),
|
||||||
("-f", "qcow2"),
|
("-f", "qcow2"),
|
||||||
(file_path, str(size_bytes)),
|
(file_path, size_bytes),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def empty_file(path: Path) -> None:
|
def empty_file(path: str) -> None:
|
||||||
"""Empty the file at provided path."""
|
"""Empty the file at provided path."""
|
||||||
write(path, "")
|
write(path, "")
|
||||||
|
|
||||||
|
@ -36,9 +36,9 @@ def get_mount_uuid(path: str) -> str:
|
||||||
def get_path_mount(path: str) -> str:
|
def get_path_mount(path: str) -> str:
|
||||||
"""Return the mountpoint path of an arbitrary path."""
|
"""Return the mountpoint path of an arbitrary path."""
|
||||||
return ps.run_line(
|
return ps.run_line(
|
||||||
"stat",
|
("stat",),
|
||||||
("--format", "%m"),
|
("--format", "%m"),
|
||||||
path,
|
(path,),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,9 +47,9 @@ def get_path_uuid(path: str) -> str:
|
||||||
return get_mount_uuid(get_path_mount(path))
|
return get_mount_uuid(get_path_mount(path))
|
||||||
|
|
||||||
|
|
||||||
def make_directory(path: Path) -> None:
|
def make_directory(path: str) -> None:
|
||||||
"""Make a directory (and its parents) from a path."""
|
"""Make a directory (and its parents) from a path."""
|
||||||
path.mkdir(exist_ok=True, parents=True)
|
Path(path).mkdir(exist_ok=True, parents=True)
|
||||||
|
|
||||||
|
|
||||||
def read_file_bytes(file_path: str) -> bytes:
|
def read_file_bytes(file_path: str) -> bytes:
|
||||||
|
@ -68,17 +68,17 @@ def read_file_text(file_path: str, charset: str = CHARSET) -> str:
|
||||||
return read_file_bytes(file_path).decode(charset)
|
return read_file_bytes(file_path).decode(charset)
|
||||||
|
|
||||||
|
|
||||||
def wipe(path: Path) -> None:
|
def wipe(path: str) -> None:
|
||||||
"""Wipe provided path, whether directory or file."""
|
"""Wipe provided path, whether directory or file."""
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
except NotADirectoryError:
|
except NotADirectoryError:
|
||||||
path.unlink(missing_ok=True)
|
Path(path).unlink(missing_ok=True)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def write(file_path: Path, text: str, charset: str = CHARSET) -> None:
|
def write(file_path: str, text: str, charset: str = CHARSET) -> None:
|
||||||
"""Write text into a file."""
|
"""Write text into a file."""
|
||||||
with file_path.open(encoding=charset, mode="w") as file_object:
|
with Path(file_path).open(encoding=charset, mode="w") as file_object:
|
||||||
file_object.write(text)
|
file_object.write(text)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
"""Wrap GRUB commands."""
|
"""Wrap GRUB commands."""
|
||||||
|
|
||||||
from rwx import cmd, ps
|
import cmd
|
||||||
|
|
||||||
|
import ps
|
||||||
|
|
||||||
cmd.need("grub-mkimage")
|
cmd.need("grub-mkimage")
|
||||||
|
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
"""Control Operating Systems."""
|
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
|
|
||||||
class OS:
|
|
||||||
"""Operating System."""
|
|
||||||
|
|
||||||
def __init__(self, path: str) -> None:
|
|
||||||
"""Set root."""
|
|
||||||
self.root = Path(path)
|
|
|
@ -1,5 +1,6 @@
|
||||||
"""Handle projects."""
|
"""Handle projects."""
|
||||||
|
|
||||||
|
from os.path import realpath
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,6 +9,6 @@ class Project:
|
||||||
|
|
||||||
def __init__(self, file_path: str) -> None:
|
def __init__(self, file_path: str) -> None:
|
||||||
"""Set file, root & name."""
|
"""Set file, root & name."""
|
||||||
self.file: Path = Path(file_path).resolve()
|
self.file: str = realpath(file_path)
|
||||||
self.root: Path = self.file.parent
|
self.root: str = Path(self.file).parent
|
||||||
self.name: str = self.root.name
|
self.name: str = self.root.name
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
"""Project consisting only of a Sphinx documentation."""
|
"""Project consisting only of a Sphinx documentation."""
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from sphinx.cmd.build import build_main
|
from sphinx.cmd.build import build_main
|
||||||
|
|
||||||
from rwx.fs import wipe
|
from rwx.fs import wipe
|
||||||
|
@ -20,7 +15,7 @@ class SphinxProject(Project):
|
||||||
|
|
||||||
def build(self) -> None:
|
def build(self) -> None:
|
||||||
"""Build the project."""
|
"""Build the project."""
|
||||||
output_root: Path = self.root / "out"
|
output_root: str = self.root / "out"
|
||||||
wipe(output_root)
|
wipe(output_root)
|
||||||
arguments: list[str] = [
|
arguments: list[str] = [
|
||||||
"-E",
|
"-E",
|
||||||
|
@ -35,9 +30,9 @@ class SphinxProject(Project):
|
||||||
"-D",
|
"-D",
|
||||||
"html_theme={}".format("sphinx_rtd_theme"),
|
"html_theme={}".format("sphinx_rtd_theme"),
|
||||||
"-c",
|
"-c",
|
||||||
str(self.root),
|
self.root,
|
||||||
# "-C",
|
# "-C",
|
||||||
str(self.root / self.name),
|
self.root / self.name,
|
||||||
str(output_root / "web"),
|
output_root / "web",
|
||||||
]
|
]
|
||||||
build_main(arguments)
|
build_main(arguments)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import subprocess
|
||||||
from rwx import txt
|
from rwx import txt
|
||||||
|
|
||||||
|
|
||||||
def get_tuples_args(*items: str | tuple[str, ...]) -> list[str]:
|
def get_tuples_args(*items: str | tuple[str]) -> list[str]:
|
||||||
"""Turn arguments tuples into an arguments list."""
|
"""Turn arguments tuples into an arguments list."""
|
||||||
args: list[str] = []
|
args: list[str] = []
|
||||||
for item in items:
|
for item in items:
|
||||||
|
@ -16,21 +16,21 @@ def get_tuples_args(*items: str | tuple[str, ...]) -> list[str]:
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
def run(*items: str | tuple[str, ...]) -> subprocess.CompletedProcess:
|
def run(*items: str | tuple[str]) -> subprocess.CompletedProcess:
|
||||||
"""Run from a list of arguments tuples."""
|
"""Run from a list of arguments tuples."""
|
||||||
return subprocess.run(
|
return subprocess.run(
|
||||||
get_tuples_args(*items), capture_output=False, check=True
|
get_tuples_args(*items), capture_output=False, check=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def run_line(*items: str | tuple[str, ...], charset: str = txt.CHARSET) -> str:
|
def run_line(*items: str | tuple[str], charset: str = txt.CHARSET) -> str:
|
||||||
"""Run and return output line."""
|
"""Run and return output line."""
|
||||||
line, *_ = run_lines(*items, charset=charset)
|
line, *_ = run_lines(*items, charset=charset)
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
|
||||||
def run_lines(
|
def run_lines(
|
||||||
*items: str | tuple[str, ...], charset: str = txt.CHARSET
|
*items: str | tuple[str], charset: str = txt.CHARSET
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
"""Run and return output lines."""
|
"""Run and return output lines."""
|
||||||
process = subprocess.run(
|
process = subprocess.run(
|
||||||
|
|
Loading…
Reference in a new issue