Compare commits
9 commits
8c896c9074
...
3393f09907
Author | SHA1 | Date | |
---|---|---|---|
3393f09907 | |||
aa1f06c20f | |||
3e0d5bf2bc | |||
08b6364d9b | |||
f7c1d90dfd | |||
ce3629a776 | |||
9bb8003812 | |||
f46d5a9765 | |||
88311cb55c |
7 changed files with 38 additions and 12 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
"""Wrap SquashFS commands."""
|
||||||
|
|
||||||
import ps
|
import ps
|
||||||
|
|
||||||
import rwx.cmd
|
import rwx.cmd
|
||||||
|
@ -5,7 +7,8 @@ import rwx.cmd
|
||||||
rwx.cmd.need("mksquashfs")
|
rwx.cmd.need("mksquashfs")
|
||||||
|
|
||||||
|
|
||||||
def mksquashfs(input_root: str, output_file: str):
|
def mksquashfs(input_root: str, output_file: str) -> None:
|
||||||
|
"""Make a SquashFS bootable image file."""
|
||||||
ps.run(
|
ps.run(
|
||||||
[
|
[
|
||||||
"mksquashfs",
|
"mksquashfs",
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
"""Wrap Debian commands."""
|
||||||
|
|
||||||
import cmd
|
import cmd
|
||||||
|
|
||||||
import ps
|
import ps
|
||||||
|
@ -8,7 +10,8 @@ BOOTSTRAP_ARCHITECTURE = "amd64"
|
||||||
BOOTSTRAP_VARIANT = "minbase"
|
BOOTSTRAP_VARIANT = "minbase"
|
||||||
|
|
||||||
|
|
||||||
def bootstrap(root_path: str, suite: str, mirror_location: str):
|
def bootstrap(root_path: str, suite: str, mirror_location: str) -> None:
|
||||||
|
"""Boostrap a base operating filesystem."""
|
||||||
command = [
|
command = [
|
||||||
("debootstrap",),
|
("debootstrap",),
|
||||||
("--arch", BOOTSTRAP_ARCHITECTURE),
|
("--arch", BOOTSTRAP_ARCHITECTURE),
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
class Exception(Exception):
|
"""Handle errors."""
|
||||||
pass
|
|
||||||
|
|
||||||
|
class Error(Exception):
|
||||||
|
"""Parent class for all errors."""
|
||||||
|
|
|
@ -23,7 +23,7 @@ def empty_file(path: str) -> None:
|
||||||
|
|
||||||
|
|
||||||
def get_mount_uuid(path: str) -> str:
|
def get_mount_uuid(path: str) -> str:
|
||||||
"""Return the UUID of provided mountpoint path."""
|
"""Return the filesystem UUID of a mountpoint path."""
|
||||||
return ps.run_line(
|
return ps.run_line(
|
||||||
("findmnt",),
|
("findmnt",),
|
||||||
("--noheadings",),
|
("--noheadings",),
|
||||||
|
@ -32,7 +32,8 @@ def get_mount_uuid(path: str) -> str:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_path_mount(path: str):
|
def get_path_mount(path: str) -> str:
|
||||||
|
"""Return the mountpoint path of an arbitrary path."""
|
||||||
return ps.run_line(
|
return ps.run_line(
|
||||||
("stat",),
|
("stat",),
|
||||||
("--format", "%m"),
|
("--format", "%m"),
|
||||||
|
@ -40,11 +41,13 @@ def get_path_mount(path: str):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_path_uuid(path: str):
|
def get_path_uuid(path: str) -> str:
|
||||||
|
"""Return the filesystem UUID of an arbitrary path."""
|
||||||
return get_mount_uuid(get_path_mount(path))
|
return get_mount_uuid(get_path_mount(path))
|
||||||
|
|
||||||
|
|
||||||
def make_directory(path: str):
|
def make_directory(path: str) -> None:
|
||||||
|
"""Make a directory (and its parents) from a path."""
|
||||||
os.makedirs(path, exist_ok=True)
|
os.makedirs(path, exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,15 +56,16 @@ def read_file(file_path: str):
|
||||||
return file_object.read()
|
return file_object.read()
|
||||||
|
|
||||||
|
|
||||||
def read_file_lines(file_path: str, charset=CHARSET):
|
def read_file_lines(file_path: str, charset: str = CHARSET):
|
||||||
return read_file_text(file_path).split(os.linesep)
|
return read_file_text(file_path).split(os.linesep)
|
||||||
|
|
||||||
|
|
||||||
def read_file_text(file_path: str, charset=CHARSET):
|
def read_file_text(file_path: str, charset: str = CHARSET):
|
||||||
return read_file(file_path).decode(charset)
|
return read_file(file_path).decode(charset)
|
||||||
|
|
||||||
|
|
||||||
def wipe(path: str):
|
def wipe(path: str) -> None:
|
||||||
|
"""Wipe provided path, whether directory or file."""
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
except NotADirectoryError:
|
except NotADirectoryError:
|
||||||
|
@ -70,6 +74,7 @@ def wipe(path: str):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def write(file_path: str, text: str, charset=CHARSET):
|
def write(file_path: str, text: str, charset: str = CHARSET) -> None:
|
||||||
|
"""Write text into a file."""
|
||||||
with open(file_path, "bw") as file_object:
|
with open(file_path, "bw") as file_object:
|
||||||
file_object.write(text.encode(charset))
|
file_object.write(text.encode(charset))
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
"""Wrap GRUB commands."""
|
||||||
|
|
||||||
import cmd
|
import cmd
|
||||||
|
|
||||||
import ps
|
import ps
|
||||||
|
@ -24,6 +26,7 @@ def make_image(
|
||||||
memdisk_path: str,
|
memdisk_path: str,
|
||||||
pubkey_path: str | None = None,
|
pubkey_path: str | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
"""Make a binary bootable image."""
|
||||||
args = [
|
args = [
|
||||||
("grub-mkimage",),
|
("grub-mkimage",),
|
||||||
("--compress", COMPRESSION),
|
("--compress", COMPRESSION),
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
|
"""Handle projects."""
|
||||||
|
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
|
|
||||||
class Project:
|
class Project:
|
||||||
|
"""Parent class for any type of project."""
|
||||||
|
|
||||||
def __init__(self, file_path: str) -> None:
|
def __init__(self, file_path: str) -> None:
|
||||||
|
"""Set file, root & name."""
|
||||||
self.file: str = path.realpath(file_path)
|
self.file: str = path.realpath(file_path)
|
||||||
self.root: str = path.dirname(self.file)
|
self.root: str = path.dirname(self.file)
|
||||||
self.name: str = path.basename(self.root)
|
self.name: str = path.basename(self.root)
|
||||||
|
|
|
@ -9,10 +9,14 @@ from rwx.prj import Project
|
||||||
|
|
||||||
|
|
||||||
class SphinxProject(Project):
|
class SphinxProject(Project):
|
||||||
|
"""Child class for a project based on Sphinx."""
|
||||||
|
|
||||||
def __init__(self, file_path: str) -> None:
|
def __init__(self, file_path: str) -> None:
|
||||||
|
"""Call the parent constructor."""
|
||||||
super().__init__(file_path)
|
super().__init__(file_path)
|
||||||
|
|
||||||
def build(self) -> None:
|
def build(self) -> None:
|
||||||
|
"""Build the project."""
|
||||||
output_root: str = path.join(self.root, "out")
|
output_root: str = path.join(self.root, "out")
|
||||||
wipe(output_root)
|
wipe(output_root)
|
||||||
arguments: list[str] = [
|
arguments: list[str] = [
|
||||||
|
|
Loading…
Reference in a new issue