From 5361fbd9a06f6d97e880893a39dee8f6af20ea27 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 20 Aug 2024 14:14:03 +0200 Subject: [PATCH 001/102] 3.11 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 66a3933..756a434 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ keywords = [] license-files = { paths = ["license.md"] } name = "rwx" readme = "readme.md" -requires-python = ">= 3.10" +requires-python = ">= 3.11" [project.scripts] # command = "package.module:function" From 2dfdabed260bfd92de3e0cdbbac86e55aa9b70c8 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 15:40:19 +0200 Subject: [PATCH 002/102] lint/sphinx --- rwx/prj/sphinx.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rwx/prj/sphinx.py b/rwx/prj/sphinx.py index 3cef334..afa0901 100644 --- a/rwx/prj/sphinx.py +++ b/rwx/prj/sphinx.py @@ -1,3 +1,5 @@ +"""Project consisting only of a Sphinx documentation.""" + from os import path from sphinx.cmd.build import build_main @@ -10,7 +12,7 @@ class SphinxProject(Project): def __init__(self, file_path: str) -> None: super().__init__(file_path) - def build(self): + def build(self) -> None: output_root: str = path.join(self.root, "out") wipe(output_root) arguments: list[str] = [ From e306971534f4fee794356db5d08d18d52a484fdc Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 15:45:17 +0200 Subject: [PATCH 003/102] lint/cmd --- rwx/cmd/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rwx/cmd/__init__.py b/rwx/cmd/__init__.py index de764fa..e3b75bc 100644 --- a/rwx/cmd/__init__.py +++ b/rwx/cmd/__init__.py @@ -1,8 +1,11 @@ +"""Handle system commands & packages.""" + commands: list[str] = [] packages: list[str] = [] def need(command: str) -> None: + """Assert package dependency for a command.""" match command: case "debootstrap": package = "debootstrap" From 63d30013a335389503e7e382f2bed1debfa595eb Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 15:53:20 +0200 Subject: [PATCH 004/102] lint/fs --- rwx/fs/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index e769358..c91e0b8 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -1,3 +1,5 @@ +"""Operations involving FileSystems.""" + import os import shutil @@ -6,7 +8,8 @@ from rwx import ps CHARSET = "UTF-8" -def create_image(file_path: str, size_bytes: int): +def create_image(file_path: str, size_bytes: int) -> None: + """Create a virtual device image file.""" ps.run( ("qemu-img", "create"), ("-f", "qcow2"), @@ -14,11 +17,13 @@ def create_image(file_path: str, size_bytes: int): ) -def empty_file(path: str): +def empty_file(path: str) -> None: + """Empty the file at provided path.""" write(path, "") -def get_mount_uuid(path: str): +def get_mount_uuid(path: str) -> str: + """Return the UUID of provided mountpoint path.""" return ps.run_line( ("findmnt",), ("--noheadings",), From 076f654a2dc66cfbc07853e40bb330a61ddc540f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 15:55:46 +0200 Subject: [PATCH 005/102] lint/arg --- rwx/arg/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rwx/arg/__init__.py b/rwx/arg/__init__.py index aa6e4b8..71ce0a7 100644 --- a/rwx/arg/__init__.py +++ b/rwx/arg/__init__.py @@ -1,6 +1,9 @@ +"""Handle system arguments.""" + import sys def split() -> tuple[str, list[str]]: + """Split command & actual arguments.""" command, *arguments = sys.argv return command, arguments From 12a2a82cfeb328468ed47620e7bba019df0bff39 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 16:27:04 +0200 Subject: [PATCH 006/102] lint/log --- rwx/log/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rwx/log/__init__.py b/rwx/log/__init__.py index 50048e5..5470e67 100644 --- a/rwx/log/__init__.py +++ b/rwx/log/__init__.py @@ -3,29 +3,29 @@ import sys def get_file_logger(name: str) -> logging.Logger: + # formatter formatter = logging.Formatter( "%(name)s: %(asctime)s | %(levelname)s | %(filename)s:%(lineno)s | %(process)d >>> %(message)s", ) - # + # handler out_handler = logging.StreamHandler(stream=sys.stdout) out_handler.setFormatter(formatter) out_handler.setLevel(logging.INFO) - # + # logger logger = logging.getLogger(name) logger.addHandler(out_handler) logger.setLevel(logging.INFO) - # return logger def get_stream_logger(level: int) -> logging.Logger: + # handler out_handler = logging.StreamHandler(stream=sys.stdout) out_handler.setLevel(level) - # + # logger logger = logging.getLogger() logger.addHandler(out_handler) logger.setLevel(level) - # return logger From 26632881275443890e02694934231523e874c336 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 16:36:29 +0200 Subject: [PATCH 007/102] lint/log --- rwx/log/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rwx/log/__init__.py b/rwx/log/__init__.py index 5470e67..12fb781 100644 --- a/rwx/log/__init__.py +++ b/rwx/log/__init__.py @@ -1,8 +1,11 @@ +"""Handle logging.""" + import logging import sys def get_file_logger(name: str) -> logging.Logger: + """Return a file logger.""" # formatter formatter = logging.Formatter( "%(name)s: %(asctime)s | %(levelname)s | %(filename)s:%(lineno)s | %(process)d >>> %(message)s", @@ -19,6 +22,7 @@ def get_file_logger(name: str) -> logging.Logger: def get_stream_logger(level: int) -> logging.Logger: + """Return a stream logger.""" # handler out_handler = logging.StreamHandler(stream=sys.stdout) out_handler.setLevel(level) From eb5a386e02e2ebfa19762b355cd7826090bde3e3 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 16:45:07 +0200 Subject: [PATCH 008/102] lint/ps --- rwx/ps/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index b66c21b..b2eca55 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -1,9 +1,12 @@ +"""Handle processes.""" + import subprocess from rwx import txt -def get_tuples_args(tuples) -> list[str]: +def get_tuples_args(*tuples: tuple[str]) -> list[str]: + """Turn arguments tuples into an arguments list.""" args: list[str] = [] for item in tuples: if type(item) is tuple: @@ -13,18 +16,21 @@ def get_tuples_args(tuples) -> list[str]: return args -def run(*tuples) -> subprocess.CompletedProcess: +def run(*tuples: tuple[str]) -> subprocess.CompletedProcess: + """Run from a list of arguments tuples.""" return subprocess.run( get_tuples_args(tuples), capture_output=False, check=True ) -def run_line(*tuples, charset: str = txt.CHARSET) -> str: +def run_line(*tuples: tuple[str], charset: str = txt.CHARSET) -> str: + """Run and return output line.""" lines = run_lines(*get_tuples_args(tuples), charset=charset) return lines[0] -def run_lines(*tuples, charset: str = txt.CHARSET) -> list[str]: +def run_lines(*tuples: tuple[str], charset: str = txt.CHARSET) -> list[str]: + """Run and return output lines.""" process = subprocess.run( get_tuples_args(tuples), capture_output=True, check=True ) From 8c896c9074f1a9b1f17f4ed56092d6d3fbd1c127 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 16:45:56 +0200 Subject: [PATCH 009/102] lint/txt --- rwx/txt/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rwx/txt/__init__.py b/rwx/txt/__init__.py index 369202c..be2f273 100644 --- a/rwx/txt/__init__.py +++ b/rwx/txt/__init__.py @@ -1 +1,3 @@ +"""Handle text.""" + CHARSET = "UTF-8" From 88311cb55c1af0df40e4d1ea1486b655bafd9fb6 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 16:50:20 +0200 Subject: [PATCH 010/102] lint/prj --- rwx/prj/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rwx/prj/__init__.py b/rwx/prj/__init__.py index 227a686..6a3e059 100644 --- a/rwx/prj/__init__.py +++ b/rwx/prj/__init__.py @@ -1,8 +1,13 @@ +"""Handle projects.""" + from os import path class Project: + """Parent class for any type of project.""" + def __init__(self, file_path: str) -> None: + """Set file, root & name.""" self.file: str = path.realpath(file_path) self.root: str = path.dirname(self.file) self.name: str = path.basename(self.root) From f46d5a97656a4ed6bbfcf8c4a6d595fabcfba3ed Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 16:52:01 +0200 Subject: [PATCH 011/102] lint/grub --- rwx/grub/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rwx/grub/__init__.py b/rwx/grub/__init__.py index cd016ab..dde847a 100644 --- a/rwx/grub/__init__.py +++ b/rwx/grub/__init__.py @@ -1,3 +1,5 @@ +"""Wrap GRUB commands.""" + import cmd import ps @@ -24,6 +26,7 @@ def make_image( memdisk_path: str, pubkey_path: str | None = None, ) -> None: + """Make a binary bootable image.""" args = [ ("grub-mkimage",), ("--compress", COMPRESSION), From 9bb800381249b4b7d3f4fb165dd8131c4618f8bb Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 16:54:22 +0200 Subject: [PATCH 012/102] lint/sphinx --- rwx/prj/sphinx.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rwx/prj/sphinx.py b/rwx/prj/sphinx.py index afa0901..13252f8 100644 --- a/rwx/prj/sphinx.py +++ b/rwx/prj/sphinx.py @@ -9,10 +9,14 @@ from rwx.prj import Project class SphinxProject(Project): + """Child class for a project based on Sphinx.""" + def __init__(self, file_path: str) -> None: + """Call the parent constructor.""" super().__init__(file_path) def build(self) -> None: + """Build the project.""" output_root: str = path.join(self.root, "out") wipe(output_root) arguments: list[str] = [ From ce3629a77601141735c9423246824bd3c3300fb4 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 16:56:01 +0200 Subject: [PATCH 013/102] lint/deb --- rwx/deb/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rwx/deb/__init__.py b/rwx/deb/__init__.py index e9c6a9e..f022ca5 100644 --- a/rwx/deb/__init__.py +++ b/rwx/deb/__init__.py @@ -1,3 +1,5 @@ +"""Wrap Debian commands.""" + import cmd import ps @@ -8,7 +10,8 @@ BOOTSTRAP_ARCHITECTURE = "amd64" 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 = [ ("debootstrap",), ("--arch", BOOTSTRAP_ARCHITECTURE), From f7c1d90dfdcd562ffb3f3b3459e237dc7040e0c9 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 16:58:01 +0200 Subject: [PATCH 014/102] lint/squashfs --- rwx/cmd/squashfs/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rwx/cmd/squashfs/__init__.py b/rwx/cmd/squashfs/__init__.py index 322186c..85e20b2 100644 --- a/rwx/cmd/squashfs/__init__.py +++ b/rwx/cmd/squashfs/__init__.py @@ -1,3 +1,5 @@ +"""Wrap SquashFS commands.""" + import ps import rwx.cmd @@ -5,7 +7,8 @@ import rwx.cmd 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( [ "mksquashfs", From 08b6364d9b8f1098983478731ade680b0cf7ace6 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 17:00:39 +0200 Subject: [PATCH 015/102] lint/err --- rwx/err/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rwx/err/__init__.py b/rwx/err/__init__.py index b996913..5df6b97 100644 --- a/rwx/err/__init__.py +++ b/rwx/err/__init__.py @@ -1,2 +1,4 @@ -class Exception(Exception): - pass +"""Handle errors.""" + +class Error(Exception): + """Parent class for all errors.""" From 3e0d5bf2bcd403d991fd149ab77ef1e6189bcfa4 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 17:07:27 +0200 Subject: [PATCH 016/102] lint/fs --- rwx/fs/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index c91e0b8..9189778 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -23,7 +23,7 @@ def empty_file(path: str) -> None: 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( ("findmnt",), ("--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( ("stat",), ("--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)) -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) From aa1f06c20fc756227b18459c6d1883fd700df140 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 17:13:16 +0200 Subject: [PATCH 017/102] lint/fs --- rwx/fs/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 9189778..64a8483 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -56,15 +56,16 @@ def read_file(file_path: str): 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) -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) -def wipe(path: str): +def wipe(path: str) -> None: + """Wipe provided path, whether directory or file.""" try: shutil.rmtree(path) except NotADirectoryError: @@ -73,6 +74,7 @@ def wipe(path: str): 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: file_object.write(text.encode(charset)) From 3393f0990742dda006ded747dae2e50319356af2 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 17:13:37 +0200 Subject: [PATCH 018/102] format --- rwx/err/__init__.py | 1 + rwx/fs/__init__.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/rwx/err/__init__.py b/rwx/err/__init__.py index 5df6b97..294d8d8 100644 --- a/rwx/err/__init__.py +++ b/rwx/err/__init__.py @@ -1,4 +1,5 @@ """Handle errors.""" + class Error(Exception): """Parent class for all errors.""" diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 64a8483..514fcec 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -56,11 +56,11 @@ def read_file(file_path: str): return file_object.read() -def read_file_lines(file_path: str, charset:str=CHARSET): +def read_file_lines(file_path: str, charset: str = CHARSET): return read_file_text(file_path).split(os.linesep) -def read_file_text(file_path: str, charset:str=CHARSET): +def read_file_text(file_path: str, charset: str = CHARSET): return read_file(file_path).decode(charset) @@ -74,7 +74,7 @@ def wipe(path: str) -> None: pass -def write(file_path: str, text: str, charset:str=CHARSET) -> None: +def write(file_path: str, text: str, charset: str = CHARSET) -> None: """Write text into a file.""" with open(file_path, "bw") as file_object: file_object.write(text.encode(charset)) From 0a9404fb2f6a908e9469179433e78eb2ec9c3e61 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 17:19:33 +0200 Subject: [PATCH 019/102] fs/unlink --- rwx/fs/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 514fcec..a7cc5b0 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -2,6 +2,7 @@ import os import shutil +from pathlib import Path from rwx import ps @@ -69,7 +70,7 @@ def wipe(path: str) -> None: try: shutil.rmtree(path) except NotADirectoryError: - os.remove(path) + Path(path).unlink(missing_ok=True) except FileNotFoundError: pass From ef45fc9d810000da64ab8ad9f309906ff8c5db86 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 17:22:36 +0200 Subject: [PATCH 020/102] fs/open --- rwx/fs/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index a7cc5b0..cb97ceb 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -77,5 +77,5 @@ def wipe(path: str) -> None: def write(file_path: str, text: str, charset: str = CHARSET) -> None: """Write text into a file.""" - with open(file_path, "bw") as file_object: - file_object.write(text.encode(charset)) + with Path(file_path).open(mode="w", encoding=charset) as file_object: + file_object.write(text) From de80d7ecff21069f2a0c5bfd960fbb17e35eefa3 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 17:24:37 +0200 Subject: [PATCH 021/102] fs/mkdir --- rwx/fs/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index cb97ceb..1037fd0 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -49,7 +49,7 @@ def get_path_uuid(path: str) -> str: def make_directory(path: str) -> None: """Make a directory (and its parents) from a path.""" - os.makedirs(path, exist_ok=True) + Path(path).mkdir(exist_ok=True, parents=True) def read_file(file_path: str): @@ -77,5 +77,5 @@ def wipe(path: str) -> None: def write(file_path: str, text: str, charset: str = CHARSET) -> None: """Write text into a file.""" - with Path(file_path).open(mode="w", encoding=charset) as file_object: + with Path(file_path).open(encoding=charset, mode="w") as file_object: file_object.write(text) From cfa9ca9e3c15e33114c051b20d52ead57dd17d17 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 17:39:39 +0200 Subject: [PATCH 022/102] prj/Path --- rwx/prj/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rwx/prj/__init__.py b/rwx/prj/__init__.py index 6a3e059..8b70a4a 100644 --- a/rwx/prj/__init__.py +++ b/rwx/prj/__init__.py @@ -1,6 +1,7 @@ """Handle projects.""" -from os import path +from os.path import realpath +from pathlib import Path class Project: @@ -8,6 +9,6 @@ class Project: def __init__(self, file_path: str) -> None: """Set file, root & name.""" - self.file: str = path.realpath(file_path) - self.root: str = path.dirname(self.file) - self.name: str = path.basename(self.root) + self.file: str = realpath(file_path) + self.root: str = Path(self.file).parent + self.name: str = self.root.name From 5e3c8e93ff9705afce27a06a1083c565466b219b Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 17:41:49 +0200 Subject: [PATCH 023/102] sphinx/ --- rwx/prj/sphinx.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rwx/prj/sphinx.py b/rwx/prj/sphinx.py index 13252f8..b85cfa5 100644 --- a/rwx/prj/sphinx.py +++ b/rwx/prj/sphinx.py @@ -1,7 +1,5 @@ """Project consisting only of a Sphinx documentation.""" -from os import path - from sphinx.cmd.build import build_main from rwx.fs import wipe @@ -17,7 +15,7 @@ class SphinxProject(Project): def build(self) -> None: """Build the project.""" - output_root: str = path.join(self.root, "out") + output_root: str = self.root / "out" wipe(output_root) arguments: list[str] = [ "-E", @@ -34,7 +32,7 @@ class SphinxProject(Project): "-c", self.root, # "-C", - path.join(self.root, self.name), - path.join(output_root, "web"), + self.root / self.name, + output_root / "web", ] build_main(arguments) From 065d647e517135cf82fa8ee3c48076b5643d11ef Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 18:55:31 +0200 Subject: [PATCH 024/102] read/bytes --- rwx/fs/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 1037fd0..b1da3a2 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -52,8 +52,9 @@ def make_directory(path: str) -> None: Path(path).mkdir(exist_ok=True, parents=True) -def read_file(file_path: str): - with open(file_path, "br") as file_object: +def read_file_bytes(file_path: str) -> bytes: + """Read whole file bytes.""" + with Path(file_path).open("br") as file_object: return file_object.read() @@ -62,7 +63,7 @@ def read_file_lines(file_path: str, charset: str = CHARSET): def read_file_text(file_path: str, charset: str = CHARSET): - return read_file(file_path).decode(charset) + return read_file_bytes(file_path).decode(charset) def wipe(path: str) -> None: From b3e66ec1c3f21b672cc26ddd540e1343f3b57cda Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 18:57:49 +0200 Subject: [PATCH 025/102] read/text --- rwx/fs/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index b1da3a2..82b7c16 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -62,7 +62,8 @@ def read_file_lines(file_path: str, charset: str = CHARSET): return read_file_text(file_path).split(os.linesep) -def read_file_text(file_path: str, charset: str = CHARSET): +def read_file_text(file_path: str, charset: str = CHARSET) -> str: + """Read whole file text.""" return read_file_bytes(file_path).decode(charset) From 78dd431ca5fd969841774f9deb4129d9eb299c7f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 18:58:57 +0200 Subject: [PATCH 026/102] read/lines --- rwx/fs/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 82b7c16..a8865e7 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -58,8 +58,9 @@ def read_file_bytes(file_path: str) -> bytes: return file_object.read() -def read_file_lines(file_path: str, charset: str = CHARSET): - return read_file_text(file_path).split(os.linesep) +def read_file_lines(file_path: str, charset: str = CHARSET) -> list[str]: + """Read whole file lines.""" + return read_file_text(file_path, charset).split(os.linesep) def read_file_text(file_path: str, charset: str = CHARSET) -> str: From bf1b3402ae58e9f0bb97259e8e016c5c8d7841aa Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 19:24:11 +0200 Subject: [PATCH 027/102] log/template --- rwx/log/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rwx/log/__init__.py b/rwx/log/__init__.py index 12fb781..3b245ae 100644 --- a/rwx/log/__init__.py +++ b/rwx/log/__init__.py @@ -7,9 +7,14 @@ import sys def get_file_logger(name: str) -> logging.Logger: """Return a file logger.""" # formatter - formatter = logging.Formatter( - "%(name)s: %(asctime)s | %(levelname)s | %(filename)s:%(lineno)s | %(process)d >>> %(message)s", - ) + items = [ + "%(name)s: %(asctime)s", + "%(levelname)s", + "%(filename)s:%(lineno)s", + "%(process)d >>> %(message)s", + ] + template = " | ".join(items) + formatter = logging.Formatter(template) # handler out_handler = logging.StreamHandler(stream=sys.stdout) out_handler.setFormatter(formatter) From 07699b08eb6a89e0e14455c443e2c8408d40c0c6 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 20:47:49 +0200 Subject: [PATCH 028/102] ps/items --- rwx/ps/__init__.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index b2eca55..1bb552d 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -5,10 +5,10 @@ import subprocess from rwx import txt -def get_tuples_args(*tuples: tuple[str]) -> list[str]: +def get_tuples_args(*items: str | tuple[str]) -> list[str]: """Turn arguments tuples into an arguments list.""" args: list[str] = [] - for item in tuples: + for item in items: if type(item) is tuple: args.extend(item) else: @@ -16,23 +16,25 @@ def get_tuples_args(*tuples: tuple[str]) -> list[str]: return args -def run(*tuples: tuple[str]) -> subprocess.CompletedProcess: +def run(*items: str | tuple[str]) -> subprocess.CompletedProcess: """Run from a list of arguments tuples.""" return subprocess.run( - get_tuples_args(tuples), capture_output=False, check=True + get_tuples_args(*items), capture_output=False, check=True ) -def run_line(*tuples: tuple[str], charset: str = txt.CHARSET) -> str: +def run_line(*items: str | tuple[str], charset: str = txt.CHARSET) -> str: """Run and return output line.""" - lines = run_lines(*get_tuples_args(tuples), charset=charset) + lines = run_lines(get_tuples_args(*items), charset=charset) return lines[0] -def run_lines(*tuples: tuple[str], charset: str = txt.CHARSET) -> list[str]: +def run_lines( + *items: str | tuple[str], charset: str = txt.CHARSET +) -> list[str]: """Run and return output lines.""" process = subprocess.run( - get_tuples_args(tuples), capture_output=True, check=True + get_tuples_args(*items), capture_output=True, check=True ) string = process.stdout.decode(charset) return string.rstrip().splitlines() From c024c553b0df3c7f1ea0f2c248b95c407d9ac46c Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 20:52:33 +0200 Subject: [PATCH 029/102] fix --- rwx/ps/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index 1bb552d..67dd2bc 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -25,7 +25,7 @@ def run(*items: str | tuple[str]) -> subprocess.CompletedProcess: def run_line(*items: str | tuple[str], charset: str = txt.CHARSET) -> str: """Run and return output line.""" - lines = run_lines(get_tuples_args(*items), charset=charset) + lines = run_lines(*items, charset=charset) return lines[0] From 0e2b638bbbf6efe4cdf23bc1f6bd86059e23abd5 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 21:11:24 +0200 Subject: [PATCH 030/102] run/line --- rwx/ps/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index 67dd2bc..e45672e 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -25,8 +25,8 @@ def run(*items: str | tuple[str]) -> subprocess.CompletedProcess: def run_line(*items: str | tuple[str], charset: str = txt.CHARSET) -> str: """Run and return output line.""" - lines = run_lines(*items, charset=charset) - return lines[0] + line, *_ = run_lines(*items, charset=charset) + return line def run_lines( From b1970c1f783b6b2d81220ec7c2881684bd012755 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 22:55:45 +0200 Subject: [PATCH 031/102] main/rwx --- rwx/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rwx/__main__.py b/rwx/__main__.py index f6276e4..ee4a31b 100755 --- a/rwx/__main__.py +++ b/rwx/__main__.py @@ -4,7 +4,7 @@ from pathlib import Path -import fs +from rwx import fs if __name__ == "__main__": file_path = Path(__file__).resolve() From 17b16ec9d041fe2bafb60651b57aed92928fdab8 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 23:02:29 +0200 Subject: [PATCH 032/102] mypy/prj --- rwx/prj/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rwx/prj/__init__.py b/rwx/prj/__init__.py index 8b70a4a..36dab99 100644 --- a/rwx/prj/__init__.py +++ b/rwx/prj/__init__.py @@ -1,6 +1,5 @@ """Handle projects.""" -from os.path import realpath from pathlib import Path @@ -9,6 +8,6 @@ class Project: def __init__(self, file_path: str) -> None: """Set file, root & name.""" - self.file: str = realpath(file_path) - self.root: str = Path(self.file).parent + self.file: Path = Path(file_path).resolve() + self.root: Path = self.file.parent self.name: str = self.root.name From 3a8b239b9f1c963be421947c6976ac4e37ce9ffb Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 23:07:39 +0200 Subject: [PATCH 033/102] mypy/cmd --- rwx/cmd/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rwx/cmd/__init__.py b/rwx/cmd/__init__.py index e3b75bc..ca4dced 100644 --- a/rwx/cmd/__init__.py +++ b/rwx/cmd/__init__.py @@ -6,6 +6,7 @@ packages: list[str] = [] def need(command: str) -> None: """Assert package dependency for a command.""" + package: str | None match command: case "debootstrap": package = "debootstrap" From e2132859879f25f79ece247908a63b267e5baa6c Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 23:17:09 +0200 Subject: [PATCH 034/102] mypy/fs,sphinx --- rwx/fs/__init__.py | 4 ++-- rwx/prj/sphinx.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index a8865e7..d1c2732 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -68,12 +68,12 @@ def read_file_text(file_path: str, charset: str = CHARSET) -> str: return read_file_bytes(file_path).decode(charset) -def wipe(path: str) -> None: +def wipe(path: Path) -> None: """Wipe provided path, whether directory or file.""" try: shutil.rmtree(path) except NotADirectoryError: - Path(path).unlink(missing_ok=True) + path.unlink(missing_ok=True) except FileNotFoundError: pass diff --git a/rwx/prj/sphinx.py b/rwx/prj/sphinx.py index b85cfa5..be207ef 100644 --- a/rwx/prj/sphinx.py +++ b/rwx/prj/sphinx.py @@ -1,5 +1,10 @@ """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 rwx.fs import wipe @@ -15,7 +20,7 @@ class SphinxProject(Project): def build(self) -> None: """Build the project.""" - output_root: str = self.root / "out" + output_root: Path = self.root / "out" wipe(output_root) arguments: list[str] = [ "-E", @@ -30,9 +35,9 @@ class SphinxProject(Project): "-D", "html_theme={}".format("sphinx_rtd_theme"), "-c", - self.root, + str(self.root), # "-C", - self.root / self.name, - output_root / "web", + str(self.root / self.name), + str(output_root / "web"), ] build_main(arguments) From 114ee6110208710cdfcb2ed57d9525167daad2fd Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 23:22:12 +0200 Subject: [PATCH 035/102] mypy/fs,main --- rwx/__main__.py | 6 +++--- rwx/fs/__init__.py | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rwx/__main__.py b/rwx/__main__.py index ee4a31b..e19dea1 100755 --- a/rwx/__main__.py +++ b/rwx/__main__.py @@ -7,9 +7,9 @@ from pathlib import Path from rwx import fs if __name__ == "__main__": - file_path = Path(__file__).resolve() - root_path = file_path.parent - directory_path = root_path / "tmp" + file_path: Path = Path(__file__).resolve() + root_path: Path = file_path.parent + directory_path: Path = root_path / "tmp" file_path = directory_path / "file" fs.wipe(directory_path) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index d1c2732..3902b5a 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -18,7 +18,7 @@ def create_image(file_path: str, size_bytes: int) -> None: ) -def empty_file(path: str) -> None: +def empty_file(path: Path) -> None: """Empty the file at provided path.""" write(path, "") @@ -47,9 +47,9 @@ def get_path_uuid(path: str) -> str: return get_mount_uuid(get_path_mount(path)) -def make_directory(path: str) -> None: +def make_directory(path: Path) -> None: """Make a directory (and its parents) from a path.""" - Path(path).mkdir(exist_ok=True, parents=True) + path.mkdir(exist_ok=True, parents=True) def read_file_bytes(file_path: str) -> bytes: @@ -78,7 +78,7 @@ def wipe(path: Path) -> None: pass -def write(file_path: str, text: str, charset: str = CHARSET) -> None: +def write(file_path: Path, text: str, charset: str = CHARSET) -> None: """Write text into a file.""" - with Path(file_path).open(encoding=charset, mode="w") as file_object: + with file_path.open(encoding=charset, mode="w") as file_object: file_object.write(text) From 56404078f7e8933324d05e490726a61d52113dcb Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 23:38:08 +0200 Subject: [PATCH 036/102] rwx/deb,grub --- rwx/deb/__init__.py | 2 +- rwx/grub/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rwx/deb/__init__.py b/rwx/deb/__init__.py index f022ca5..d205222 100644 --- a/rwx/deb/__init__.py +++ b/rwx/deb/__init__.py @@ -2,7 +2,7 @@ import cmd -import ps +from rwx import ps cmd.need("debootstrap") diff --git a/rwx/grub/__init__.py b/rwx/grub/__init__.py index dde847a..f4ceaea 100644 --- a/rwx/grub/__init__.py +++ b/rwx/grub/__init__.py @@ -2,7 +2,7 @@ import cmd -import ps +from rwx import ps cmd.need("grub-mkimage") From 4fac21da0807cedccdf29a1a5d49bb52892cd30f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 23:40:53 +0200 Subject: [PATCH 037/102] rwx/squashfs --- rwx/cmd/squashfs/__init__.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/rwx/cmd/squashfs/__init__.py b/rwx/cmd/squashfs/__init__.py index 85e20b2..3162b88 100644 --- a/rwx/cmd/squashfs/__init__.py +++ b/rwx/cmd/squashfs/__init__.py @@ -1,10 +1,8 @@ """Wrap SquashFS commands.""" -import ps +from rwx import cmd, ps -import rwx.cmd - -rwx.cmd.need("mksquashfs") +cmd.need("mksquashfs") def mksquashfs(input_root: str, output_file: str) -> None: From 521884102e01e6e0d4005eb0404a72f01a363b1d Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 23:41:19 +0200 Subject: [PATCH 038/102] os --- rwx/os/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 rwx/os/__init__.py diff --git a/rwx/os/__init__.py b/rwx/os/__init__.py new file mode 100644 index 0000000..70ca05c --- /dev/null +++ b/rwx/os/__init__.py @@ -0,0 +1,11 @@ +"""Control Operating Systems.""" + +from pathlib import Path + + +class OS: + """Operating System.""" + + def __init__(self, path: str) -> None: + """Set root.""" + self.root = Path(path) From cd4e7403ae6142273b929c024d38b1df0c225f98 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 23:54:32 +0200 Subject: [PATCH 039/102] ps/str,... --- rwx/ps/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index e45672e..e18e250 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -5,7 +5,7 @@ import subprocess 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.""" args: list[str] = [] for item in items: @@ -16,21 +16,21 @@ def get_tuples_args(*items: str | tuple[str]) -> list[str]: 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.""" return subprocess.run( 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.""" line, *_ = run_lines(*items, charset=charset) return line def run_lines( - *items: str | tuple[str], charset: str = txt.CHARSET + *items: str | tuple[str, ...], charset: str = txt.CHARSET ) -> list[str]: """Run and return output lines.""" process = subprocess.run( From 378a2127862b63d0c43e86e495c351c79c2ff220 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 23:55:02 +0200 Subject: [PATCH 040/102] mypy/deb,fs,grub --- rwx/deb/__init__.py | 6 ++---- rwx/fs/__init__.py | 6 +++--- rwx/grub/__init__.py | 4 +--- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/rwx/deb/__init__.py b/rwx/deb/__init__.py index d205222..fcd4198 100644 --- a/rwx/deb/__init__.py +++ b/rwx/deb/__init__.py @@ -1,8 +1,6 @@ """Wrap Debian commands.""" -import cmd - -from rwx import ps +from rwx import cmd, ps cmd.need("debootstrap") @@ -20,4 +18,4 @@ def bootstrap(root_path: str, suite: str, mirror_location: str) -> None: (root_path,), (mirror_location,), ] - return ps.run(command) + ps.run(*command) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 3902b5a..0685c44 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -14,7 +14,7 @@ def create_image(file_path: str, size_bytes: int) -> None: ps.run( ("qemu-img", "create"), ("-f", "qcow2"), - (file_path, size_bytes), + (file_path, str(size_bytes)), ) @@ -36,9 +36,9 @@ def get_mount_uuid(path: str) -> str: def get_path_mount(path: str) -> str: """Return the mountpoint path of an arbitrary path.""" return ps.run_line( - ("stat",), + "stat", ("--format", "%m"), - (path,), + path, ) diff --git a/rwx/grub/__init__.py b/rwx/grub/__init__.py index f4ceaea..accec9f 100644 --- a/rwx/grub/__init__.py +++ b/rwx/grub/__init__.py @@ -1,8 +1,6 @@ """Wrap GRUB commands.""" -import cmd - -from rwx import ps +from rwx import cmd, ps cmd.need("grub-mkimage") From 51b4f0f5f29ef0af7e523eae026f19793fac8941 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 13 Sep 2024 23:57:35 +0200 Subject: [PATCH 041/102] mypy/squashfs --- rwx/cmd/squashfs/__init__.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/rwx/cmd/squashfs/__init__.py b/rwx/cmd/squashfs/__init__.py index 3162b88..db603da 100644 --- a/rwx/cmd/squashfs/__init__.py +++ b/rwx/cmd/squashfs/__init__.py @@ -8,13 +8,11 @@ cmd.need("mksquashfs") def mksquashfs(input_root: str, output_file: str) -> None: """Make a SquashFS bootable image file.""" ps.run( - [ - "mksquashfs", - input_root, - output_file, - "-comp", - "zstd", - "-Xcompression-level", - str(18), - ] + "mksquashfs", + input_root, + output_file, + "-comp", + "zstd", + "-Xcompression-level", + str(18), ) From 2ad223fa834645974806ddc663fe98a69849342f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 00:07:34 +0200 Subject: [PATCH 042/102] grub/extra --- rwx/grub/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rwx/grub/__init__.py b/rwx/grub/__init__.py index accec9f..21b2bf5 100644 --- a/rwx/grub/__init__.py +++ b/rwx/grub/__init__.py @@ -35,6 +35,6 @@ def make_image( if pubkey_path: args.append(("--pubkey", pubkey_path)) args.extend(modules) - if modules := MODULES.get(image_format): - args.extend(modules) + if extra_modules := MODULES.get(image_format): + args.extend(extra_modules) ps.run(*args) From 68cbe3cd88db3d39652a831e277c12a1bdb342e7 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 00:13:59 +0200 Subject: [PATCH 043/102] mypy/ps --- rwx/ps/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index e18e250..0bbab9c 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -9,10 +9,11 @@ def get_tuples_args(*items: str | tuple[str, ...]) -> list[str]: """Turn arguments tuples into an arguments list.""" args: list[str] = [] for item in items: - if type(item) is tuple: - args.extend(item) - else: - args.append(item) + match item: + case str(): + args.append(item) + case tuple(): + args.extend(item) return args From d4d60982415d69ab5e4759c6cd62e5db27866d02 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 00:17:17 +0200 Subject: [PATCH 044/102] mypy/grub --- rwx/grub/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rwx/grub/__init__.py b/rwx/grub/__init__.py index 21b2bf5..7c0cccc 100644 --- a/rwx/grub/__init__.py +++ b/rwx/grub/__init__.py @@ -25,8 +25,8 @@ def make_image( pubkey_path: str | None = None, ) -> None: """Make a binary bootable image.""" - args = [ - ("grub-mkimage",), + args: list[str | tuple[str, ...]] = [ + "grub-mkimage", ("--compress", COMPRESSION), ("--format", image_format), ("--output", image_path), From cc0b131a564dec9a4a8219debf423ed0afc274f0 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 02:39:52 +0200 Subject: [PATCH 045/102] py.typed --- rwx/py.typed | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 rwx/py.typed diff --git a/rwx/py.typed b/rwx/py.typed new file mode 100644 index 0000000..e69de29 From 4e369df232f527dc9640e1a55373453d70f0feb6 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 02:47:52 +0200 Subject: [PATCH 046/102] mypy/fs --- rwx/fs/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 0685c44..ee1925d 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -52,18 +52,18 @@ def make_directory(path: Path) -> None: path.mkdir(exist_ok=True, parents=True) -def read_file_bytes(file_path: str) -> bytes: +def read_file_bytes(file_path: Path) -> bytes: """Read whole file bytes.""" - with Path(file_path).open("br") as file_object: + with file_path.open("br") as file_object: return file_object.read() -def read_file_lines(file_path: str, charset: str = CHARSET) -> list[str]: +def read_file_lines(file_path: Path, charset: str = CHARSET) -> list[str]: """Read whole file lines.""" return read_file_text(file_path, charset).split(os.linesep) -def read_file_text(file_path: str, charset: str = CHARSET) -> str: +def read_file_text(file_path: Path, charset: str = CHARSET) -> str: """Read whole file text.""" return read_file_bytes(file_path).decode(charset) From 909e652f0d5d915231fffa2f6a9b47a18a012cad Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 15:23:06 +0200 Subject: [PATCH 047/102] os/debian --- rwx/os/__init__.py | 17 +++++++++++++++-- rwx/os/debian.py | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 rwx/os/debian.py diff --git a/rwx/os/__init__.py b/rwx/os/__init__.py index 70ca05c..3bd3c15 100644 --- a/rwx/os/__init__.py +++ b/rwx/os/__init__.py @@ -2,10 +2,23 @@ from pathlib import Path +from rwx.err import Error +from rwx.os.debian import Debian + class OS: """Operating System.""" - def __init__(self, path: str) -> None: + def __init__(self, path: Path) -> None: """Set root.""" - self.root = Path(path) + self.root = path + self.name = self.get_name() + + def get_name(self) -> str: + """Return mandatory name.""" + raise Error + + +def from_path(path: Path) -> OS: + """Initialize from an already existing path.""" + return Debian(path) diff --git a/rwx/os/debian.py b/rwx/os/debian.py new file mode 100644 index 0000000..f8b5fdd --- /dev/null +++ b/rwx/os/debian.py @@ -0,0 +1,17 @@ +"""Debian operating system.""" + +from pathlib import Path + +from . import OS + + +class Debian(OS): + """Debian operating system.""" + + def __init__(self, path: Path) -> None: + """Initialize.""" + super().__init__(path) + + def get_name(self) -> str: + """Return name.""" + return "Debian" From 9c1136cfa0b978c9ed85311209dcdc6518f7bef6 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 15:41:56 +0200 Subject: [PATCH 048/102] staticmethod --- rwx/os/__init__.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/rwx/os/__init__.py b/rwx/os/__init__.py index 3bd3c15..d13857c 100644 --- a/rwx/os/__init__.py +++ b/rwx/os/__init__.py @@ -1,10 +1,15 @@ """Control Operating Systems.""" -from pathlib import Path +from __future__ import annotations + +from typing import TYPE_CHECKING from rwx.err import Error from rwx.os.debian import Debian +if TYPE_CHECKING: + from pathlib import Path + class OS: """Operating System.""" @@ -18,7 +23,7 @@ class OS: """Return mandatory name.""" raise Error - -def from_path(path: Path) -> OS: - """Initialize from an already existing path.""" - return Debian(path) + @staticmethod + def from_path(path: Path) -> OS: + """Initialize from an already existing path.""" + return Debian(path) From e75a624c466b77d05b781f760dd3d9536483892e Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 15:45:44 +0200 Subject: [PATCH 049/102] abc --- rwx/os/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rwx/os/__init__.py b/rwx/os/__init__.py index d13857c..1594cbb 100644 --- a/rwx/os/__init__.py +++ b/rwx/os/__init__.py @@ -2,16 +2,16 @@ from __future__ import annotations +from abc import ABC, abstractmethod from typing import TYPE_CHECKING -from rwx.err import Error from rwx.os.debian import Debian if TYPE_CHECKING: from pathlib import Path -class OS: +class OS(ABC): """Operating System.""" def __init__(self, path: Path) -> None: @@ -19,9 +19,9 @@ class OS: self.root = path self.name = self.get_name() + @abstractmethod def get_name(self) -> str: """Return mandatory name.""" - raise Error @staticmethod def from_path(path: Path) -> OS: From c5930b4107c212dc652f958728e343f366179691 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 16:24:10 +0200 Subject: [PATCH 050/102] os.os --- rwx/os/__init__.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/rwx/os/__init__.py b/rwx/os/__init__.py index 1594cbb..3dfa782 100644 --- a/rwx/os/__init__.py +++ b/rwx/os/__init__.py @@ -3,12 +3,10 @@ from __future__ import annotations from abc import ABC, abstractmethod -from typing import TYPE_CHECKING +from os import sep +from pathlib import Path -from rwx.os.debian import Debian - -if TYPE_CHECKING: - from pathlib import Path +from .debian import Debian class OS(ABC): @@ -27,3 +25,6 @@ class OS(ABC): def from_path(path: Path) -> OS: """Initialize from an already existing path.""" return Debian(path) + + +os = OS.from_path(Path(sep)) From f4498f691c9bd03d44898ff91f239f6f65209a7d Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 17:43:37 +0200 Subject: [PATCH 051/102] pm,ps --- rwx/os/pm/__init__.py | 17 +++++++++++++++++ rwx/os/pm/apt.py | 16 ++++++++++++++++ rwx/ps/__init__.py | 4 ++++ 3 files changed, 37 insertions(+) create mode 100644 rwx/os/pm/__init__.py create mode 100644 rwx/os/pm/apt.py diff --git a/rwx/os/pm/__init__.py b/rwx/os/pm/__init__.py new file mode 100644 index 0000000..0bcf1e6 --- /dev/null +++ b/rwx/os/pm/__init__.py @@ -0,0 +1,17 @@ +"""Package Manager.""" + +from abc import ABC, abstractmethod + +from rwx.ps import Command + + +class PM(ABC): + """Package Manager.""" + + def __init__(self) -> None: + """Set commands.""" + self.install = self.get_install_command() + + @abstractmethod + def get_install_command(self) -> Command: + """Command to install package(s).""" diff --git a/rwx/os/pm/apt.py b/rwx/os/pm/apt.py new file mode 100644 index 0000000..17caac3 --- /dev/null +++ b/rwx/os/pm/apt.py @@ -0,0 +1,16 @@ +"""Advanced Package Tool.""" + +from rwx.os.pm import PM +from rwx.ps import Command + + +class APT(PM): + """Advanced Package Tool.""" + + def __init__(self) -> None: + """Initialize.""" + super().__init__() + + def get_install_command(self) -> Command: + """Return install command.""" + return Command() diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index 0bbab9c..07ccce8 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -5,6 +5,10 @@ import subprocess from rwx import txt +class Command: + """Command to run.""" + + def get_tuples_args(*items: str | tuple[str, ...]) -> list[str]: """Turn arguments tuples into an arguments list.""" args: list[str] = [] From 148f757d5dbafe09a0bada3bad3daea8ae56cd6b Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 18:07:01 +0200 Subject: [PATCH 052/102] command/wip --- rwx/ps/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index 07ccce8..3ea9702 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -8,6 +8,11 @@ from rwx import txt class Command: """Command to run.""" + def __init__(self, *arguments: str | tuple[str, ...]) -> None: + """Set raw & flat arguments.""" + self.raw = arguments + self.flat: list[str] = [] + def get_tuples_args(*items: str | tuple[str, ...]) -> list[str]: """Turn arguments tuples into an arguments list.""" From 4d8c1d7aabb764bca4f9c2c9bf5df7626b97abdf Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 18:15:42 +0200 Subject: [PATCH 053/102] lint --- rwx/os/debian.py | 6 ------ rwx/os/pm/apt.py | 4 ---- rwx/prj/sphinx.py | 8 ++------ 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/rwx/os/debian.py b/rwx/os/debian.py index f8b5fdd..dbaaabb 100644 --- a/rwx/os/debian.py +++ b/rwx/os/debian.py @@ -1,17 +1,11 @@ """Debian operating system.""" -from pathlib import Path - from . import OS class Debian(OS): """Debian operating system.""" - def __init__(self, path: Path) -> None: - """Initialize.""" - super().__init__(path) - def get_name(self) -> str: """Return name.""" return "Debian" diff --git a/rwx/os/pm/apt.py b/rwx/os/pm/apt.py index 17caac3..ac669b6 100644 --- a/rwx/os/pm/apt.py +++ b/rwx/os/pm/apt.py @@ -7,10 +7,6 @@ from rwx.ps import Command class APT(PM): """Advanced Package Tool.""" - def __init__(self) -> None: - """Initialize.""" - super().__init__() - def get_install_command(self) -> Command: """Return install command.""" return Command() diff --git a/rwx/prj/sphinx.py b/rwx/prj/sphinx.py index be207ef..c1b2c17 100644 --- a/rwx/prj/sphinx.py +++ b/rwx/prj/sphinx.py @@ -14,10 +14,6 @@ from rwx.prj import Project class SphinxProject(Project): """Child class for a project based on Sphinx.""" - def __init__(self, file_path: str) -> None: - """Call the parent constructor.""" - super().__init__(file_path) - def build(self) -> None: """Build the project.""" output_root: Path = self.root / "out" @@ -31,9 +27,9 @@ class SphinxProject(Project): "-D", f"project={self.name}", "-D", - "master_doc={}".format("index"), + "master_doc=index", "-D", - "html_theme={}".format("sphinx_rtd_theme"), + "html_theme=sphinx_rtd_theme", "-c", str(self.root), # "-C", From 6f9ba7f8f704a24ded03b4c30071f9546b850ba1 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 18:16:40 +0200 Subject: [PATCH 054/102] imports --- rwx/prj/sphinx.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rwx/prj/sphinx.py b/rwx/prj/sphinx.py index c1b2c17..592e6dd 100644 --- a/rwx/prj/sphinx.py +++ b/rwx/prj/sphinx.py @@ -2,14 +2,14 @@ from typing import TYPE_CHECKING -if TYPE_CHECKING: - from pathlib import Path - from sphinx.cmd.build import build_main from rwx.fs import wipe from rwx.prj import Project +if TYPE_CHECKING: + from pathlib import Path + class SphinxProject(Project): """Child class for a project based on Sphinx.""" From 0ad5cc97018d13482820304d62494414a1eee995 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 23:40:39 +0200 Subject: [PATCH 055/102] cyclic --- rwx/os/__init__.py | 25 +++++-------------------- rwx/os/abstract.py | 17 +++++++++++++++++ rwx/os/debian.py | 2 +- 3 files changed, 23 insertions(+), 21 deletions(-) create mode 100644 rwx/os/abstract.py diff --git a/rwx/os/__init__.py b/rwx/os/__init__.py index 3dfa782..75a0bc9 100644 --- a/rwx/os/__init__.py +++ b/rwx/os/__init__.py @@ -1,30 +1,15 @@ """Control Operating Systems.""" -from __future__ import annotations - -from abc import ABC, abstractmethod from os import sep from pathlib import Path +from .abstract import OS from .debian import Debian -class OS(ABC): - """Operating System.""" - - def __init__(self, path: Path) -> None: - """Set root.""" - self.root = path - self.name = self.get_name() - - @abstractmethod - def get_name(self) -> str: - """Return mandatory name.""" - - @staticmethod - def from_path(path: Path) -> OS: - """Initialize from an already existing path.""" - return Debian(path) +def from_path(path: Path) -> OS: + """Initialize from an already existing path.""" + return Debian(path) -os = OS.from_path(Path(sep)) +up = from_path(Path(sep)) diff --git a/rwx/os/abstract.py b/rwx/os/abstract.py new file mode 100644 index 0000000..2d86f7e --- /dev/null +++ b/rwx/os/abstract.py @@ -0,0 +1,17 @@ +"""Abstract Operating System.""" + +from abc import ABC, abstractmethod +from pathlib import Path + + +class OS(ABC): + """Operating System.""" + + def __init__(self, path: Path) -> None: + """Set root.""" + self.root = path + self.name = self.get_name() + + @abstractmethod + def get_name(self) -> str: + """Return mandatory name.""" diff --git a/rwx/os/debian.py b/rwx/os/debian.py index dbaaabb..98c8928 100644 --- a/rwx/os/debian.py +++ b/rwx/os/debian.py @@ -1,6 +1,6 @@ """Debian operating system.""" -from . import OS +from .abstract import OS class Debian(OS): From f2991cff049828b0e28c2c24b6eda712f7357894 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 01:35:33 +0200 Subject: [PATCH 056/102] pm/str --- rwx/os/pm/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rwx/os/pm/__init__.py b/rwx/os/pm/__init__.py index 0bcf1e6..e359a88 100644 --- a/rwx/os/pm/__init__.py +++ b/rwx/os/pm/__init__.py @@ -15,3 +15,9 @@ class PM(ABC): @abstractmethod def get_install_command(self) -> Command: """Command to install package(s).""" + + def __str__(self) -> str: + """Return commands.""" + return f"""\ +install = {self.install} +""" From 73c7ac00f426548d88c8af11e9a94d4788e817c8 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 01:37:45 +0200 Subject: [PATCH 057/102] os/str --- rwx/os/abstract.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rwx/os/abstract.py b/rwx/os/abstract.py index 2d86f7e..e985dc5 100644 --- a/rwx/os/abstract.py +++ b/rwx/os/abstract.py @@ -15,3 +15,10 @@ class OS(ABC): @abstractmethod def get_name(self) -> str: """Return mandatory name.""" + + def __str__(self) -> str: + """Return root & name.""" + return f"""\ +root = {self.root} +name = {self.name} +""" From 5038e587af65449a7f674be2da7849a8c8d7ab6f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 01:45:06 +0200 Subject: [PATCH 058/102] command/str --- rwx/ps/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index 3ea9702..7f21c5d 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -13,6 +13,13 @@ class Command: self.raw = arguments self.flat: list[str] = [] + def __str__(self) -> str: + """Return raw & flat.""" + return f"""\ + raw = {self.raw} +flat = {self.flat} +""" + def get_tuples_args(*items: str | tuple[str, ...]) -> list[str]: """Turn arguments tuples into an arguments list.""" From 304c2bc617b49e8fc466e212f323cf5e2fbd42b3 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 01:46:25 +0200 Subject: [PATCH 059/102] project/str --- rwx/prj/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rwx/prj/__init__.py b/rwx/prj/__init__.py index 36dab99..04f1cd9 100644 --- a/rwx/prj/__init__.py +++ b/rwx/prj/__init__.py @@ -11,3 +11,11 @@ class Project: self.file: Path = Path(file_path).resolve() self.root: Path = self.file.parent self.name: str = self.root.name + + def __str__(self) -> str: + """Return file, root & name.""" + return f"""\ +file = {self.file} +root = {self.root} +name = {self.name} +""" From 63c179a0a48b237ae5a581ed823c93ce062f83fe Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 01:49:39 +0200 Subject: [PATCH 060/102] pm/clean --- rwx/os/pm/__init__.py | 6 ++++++ rwx/os/pm/apt.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/rwx/os/pm/__init__.py b/rwx/os/pm/__init__.py index e359a88..d248e47 100644 --- a/rwx/os/pm/__init__.py +++ b/rwx/os/pm/__init__.py @@ -10,8 +10,13 @@ class PM(ABC): def __init__(self) -> None: """Set commands.""" + self.clean = self.get_clean_command() self.install = self.get_install_command() + @abstractmethod + def get_clean_command(self) -> Command: + """Command to clean packages cache.""" + @abstractmethod def get_install_command(self) -> Command: """Command to install package(s).""" @@ -19,5 +24,6 @@ class PM(ABC): def __str__(self) -> str: """Return commands.""" return f"""\ + clean = {self.clean} install = {self.install} """ diff --git a/rwx/os/pm/apt.py b/rwx/os/pm/apt.py index ac669b6..03217b8 100644 --- a/rwx/os/pm/apt.py +++ b/rwx/os/pm/apt.py @@ -7,6 +7,10 @@ from rwx.ps import Command class APT(PM): """Advanced Package Tool.""" + def get_clean_command(self) -> Command: + """Return clean command.""" + return Command() + def get_install_command(self) -> Command: """Return install command.""" return Command() From f8567686fd196d36ef6dd6c2be6304bbef8b328c Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 01:59:00 +0200 Subject: [PATCH 061/102] project/repr --- rwx/prj/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rwx/prj/__init__.py b/rwx/prj/__init__.py index 04f1cd9..f4a8acb 100644 --- a/rwx/prj/__init__.py +++ b/rwx/prj/__init__.py @@ -6,15 +6,21 @@ from pathlib import Path class Project: """Parent class for any type of project.""" - def __init__(self, file_path: str) -> None: + def __init__(self, file: Path) -> None: """Set file, root & name.""" - self.file: Path = Path(file_path).resolve() + self.raw = file + self.file = self.raw.resolve() self.root: Path = self.file.parent self.name: str = self.root.name + def __repr__(self) -> str: + """Represent project.""" + return f"Project(file={self.raw!r})" + def __str__(self) -> str: """Return file, root & name.""" return f"""\ + raw = {self.raw} file = {self.file} root = {self.root} name = {self.name} From 5a25c6df27b8be0530f286a27d29e7db55c7f359 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 02:02:36 +0200 Subject: [PATCH 062/102] command/repr --- rwx/ps/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index 7f21c5d..54d58cf 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -13,6 +13,10 @@ class Command: self.raw = arguments self.flat: list[str] = [] + def __repr__(self) -> str: + """Represent command.""" + return f"Command({self.raw!r})" + def __str__(self) -> str: """Return raw & flat.""" return f"""\ From 04eaae7ba3042b33c9debcac8d4fb678ada1e77d Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 15:03:13 +0200 Subject: [PATCH 063/102] pyproject/pydoclint --- pyproject.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 756a434..462a1d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,11 @@ requires-python = ">= 3.11" [tool.hatch.version] path = "rwx/__init__.py" +[tool.pydoclint] +allow-init-docstring = true +skip-checking-short-docstrings = false +style = "sphinx" + [tool.ruff] line-length = 80 From db47d5c80a70253b584a3cefcee35dc97bf194ea Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 15:07:47 +0200 Subject: [PATCH 064/102] doc/arg.split --- rwx/arg/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rwx/arg/__init__.py b/rwx/arg/__init__.py index 71ce0a7..a35dd4f 100644 --- a/rwx/arg/__init__.py +++ b/rwx/arg/__init__.py @@ -4,6 +4,10 @@ import sys def split() -> tuple[str, list[str]]: - """Split command & actual arguments.""" + """Split command & actual arguments. + + :return: both + :rtype: tuple[str, list[str]] + """ command, *arguments = sys.argv return command, arguments From 2f0c3a04874805570b850bb415e20091a204516d Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 23:05:05 +0200 Subject: [PATCH 065/102] readme/wipe --- readme.fr.rst | 7 ------- readme.rst | 8 -------- 2 files changed, 15 deletions(-) delete mode 100644 readme.fr.rst delete mode 100644 readme.rst diff --git a/readme.fr.rst b/readme.fr.rst deleted file mode 100644 index c8e6491..0000000 --- a/readme.fr.rst +++ /dev/null @@ -1,7 +0,0 @@ -****************** -Read Write eXecute -****************** - -`English `_ | `Français `_ - -Français diff --git a/readme.rst b/readme.rst deleted file mode 100644 index 954b375..0000000 --- a/readme.rst +++ /dev/null @@ -1,8 +0,0 @@ -Read Write eXecute -================== - -`English `_ ---------------------------------- - -`Français `_ ----------------------------------- From c300ab86d730e88fc8775985f2fae36d213f7732 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 23:35:51 +0200 Subject: [PATCH 066/102] readme/md --- readme.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 readme.md diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..b149e9d --- /dev/null +++ b/readme.md @@ -0,0 +1,52 @@ +# Read Write eXecute + +A tiny framework to read, write & execute things. + +--- + +## Why + +--- + +## How + +--- + +## What + +--- + +## Who + +### By + +* [Marc Beninca](https://marc.beninca.link) + +### For + +* myself + +--- + +## Where + +### Chat + +* [Discord](https://discord.com/channels/983145051985154108/1255894474895134761) +* [IRC](ircs://irc.libera.chat/##rwx) + +### Forge + +* [Repository](https://forge.rwx.work/rwx.work/rwx) +* [RSS](https://forge.rwx.work/rwx.work/rwx.rss) +* [Workflows](https://forge.rwx.work/rwx.work/rwx/actions) + +### Deployment + +* [Site](https://rwx.rwx.work) + +--- + +## When + +### Task stack From 26fea93bdb344a180bcf283435c489f81745e38c Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 23:40:15 +0200 Subject: [PATCH 067/102] stack --- readme.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/readme.md b/readme.md index b149e9d..a8a258c 100644 --- a/readme.md +++ b/readme.md @@ -50,3 +50,11 @@ A tiny framework to read, write & execute things. ## When ### Task stack + +* character constants for box drawing +* parse pyproject.toml to write commands +* write classes for + * steps bars to log + * system commands to run + * with single call of subprocess.run + * or alternate subprocess method? From ca88e5bc1d03137626ecd2887800b75ef273f421 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 16 Sep 2024 01:17:55 +0200 Subject: [PATCH 068/102] doc/quiet --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 462a1d5..1d231ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ path = "rwx/__init__.py" [tool.pydoclint] allow-init-docstring = true +quiet = true skip-checking-short-docstrings = false style = "sphinx" From 450e10e2f4d82997baf6942f98aa18d3ca48d435 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 16 Sep 2024 11:14:40 +0200 Subject: [PATCH 069/102] class,os --- rwx/__init__.py | 17 +++++++++++++++++ rwx/os/abstract.py | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/rwx/__init__.py b/rwx/__init__.py index a1c5ee6..ee9f51e 100644 --- a/rwx/__init__.py +++ b/rwx/__init__.py @@ -1,3 +1,20 @@ """Read Write eXecute.""" __version__ = "0.0.1" + + +class Class: + """Root class.""" + + def __repr__(self) -> str: + """Represent object variables. + + :return: representation + :rtype: str + """ + name = self.__class__.__name__ + attributes = [ + f"{k}={v!r}" for k, v in vars(self).items() if not k.startswith("_") + ] + arguments = ", ".join(attributes) + return f"{name}({arguments})" diff --git a/rwx/os/abstract.py b/rwx/os/abstract.py index e985dc5..8b99c28 100644 --- a/rwx/os/abstract.py +++ b/rwx/os/abstract.py @@ -3,8 +3,10 @@ from abc import ABC, abstractmethod from pathlib import Path +from rwx import Class -class OS(ABC): + +class OS(Class, ABC): """Operating System.""" def __init__(self, path: Path) -> None: From b7eec788f7b0a77355835a323516adaa5b19aacd Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 16 Sep 2024 11:35:29 +0200 Subject: [PATCH 070/102] =?UTF-8?q?=E2=88=92repr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rwx/err/__init__.py | 4 +++- rwx/os/pm/__init__.py | 3 ++- rwx/prj/__init__.py | 8 +++----- rwx/ps/__init__.py | 8 ++------ 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/rwx/err/__init__.py b/rwx/err/__init__.py index 294d8d8..53a63c7 100644 --- a/rwx/err/__init__.py +++ b/rwx/err/__init__.py @@ -1,5 +1,7 @@ """Handle errors.""" +from rwx import Class -class Error(Exception): + +class Error(Class, Exception): """Parent class for all errors.""" diff --git a/rwx/os/pm/__init__.py b/rwx/os/pm/__init__.py index d248e47..b3cacc4 100644 --- a/rwx/os/pm/__init__.py +++ b/rwx/os/pm/__init__.py @@ -2,10 +2,11 @@ from abc import ABC, abstractmethod +from rwx import Class from rwx.ps import Command -class PM(ABC): +class PM(Class, ABC): """Package Manager.""" def __init__(self) -> None: diff --git a/rwx/prj/__init__.py b/rwx/prj/__init__.py index f4a8acb..3cba90b 100644 --- a/rwx/prj/__init__.py +++ b/rwx/prj/__init__.py @@ -2,8 +2,10 @@ from pathlib import Path +from rwx import Class -class Project: + +class Project(Class): """Parent class for any type of project.""" def __init__(self, file: Path) -> None: @@ -13,10 +15,6 @@ class Project: self.root: Path = self.file.parent self.name: str = self.root.name - def __repr__(self) -> str: - """Represent project.""" - return f"Project(file={self.raw!r})" - def __str__(self) -> str: """Return file, root & name.""" return f"""\ diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index 54d58cf..601aca3 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -2,10 +2,10 @@ import subprocess -from rwx import txt +from rwx import Class, txt -class Command: +class Command(Class): """Command to run.""" def __init__(self, *arguments: str | tuple[str, ...]) -> None: @@ -13,10 +13,6 @@ class Command: self.raw = arguments self.flat: list[str] = [] - def __repr__(self) -> str: - """Represent command.""" - return f"Command({self.raw!r})" - def __str__(self) -> str: """Return raw & flat.""" return f"""\ From 487d7cb9b2edd5d9d7f058da427c8e2db5a45176 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 16 Sep 2024 12:04:43 +0200 Subject: [PATCH 071/102] str --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index a8a258c..e2beac8 100644 --- a/readme.md +++ b/readme.md @@ -52,6 +52,7 @@ A tiny framework to read, write & execute things. ### Task stack * character constants for box drawing +* common __str__ function * parse pyproject.toml to write commands * write classes for * steps bars to log From 8227524a7c45a1ac01a7b6c4568507ee289b94a4 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 16 Sep 2024 21:41:45 +0200 Subject: [PATCH 072/102] class/str --- rwx/__init__.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/rwx/__init__.py b/rwx/__init__.py index ee9f51e..50c7cbe 100644 --- a/rwx/__init__.py +++ b/rwx/__init__.py @@ -2,14 +2,16 @@ __version__ = "0.0.1" +from os import linesep + class Class: """Root class.""" def __repr__(self) -> str: - """Represent object variables. + """Return machine-readable state. - :return: representation + :return: state :rtype: str """ name = self.__class__.__name__ @@ -18,3 +20,14 @@ class Class: ] arguments = ", ".join(attributes) return f"{name}({arguments})" + + def __str__(self) -> str: + """Return human-readable state. + + :return: state + :rtype: str + """ + attributes = [ + f"{k} = {v}" for k, v in vars(self).items() if not k.startswith("_") + ] + return linesep.join(attributes) From e5bb634cf41e5266d1a6e254f241e6c9bf2066ef Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 16 Sep 2024 21:45:21 +0200 Subject: [PATCH 073/102] =?UTF-8?q?=E2=88=92str?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rwx/os/abstract.py | 7 ------- rwx/os/pm/__init__.py | 7 ------- rwx/prj/__init__.py | 9 --------- rwx/ps/__init__.py | 7 ------- 4 files changed, 30 deletions(-) diff --git a/rwx/os/abstract.py b/rwx/os/abstract.py index 8b99c28..f4837fc 100644 --- a/rwx/os/abstract.py +++ b/rwx/os/abstract.py @@ -17,10 +17,3 @@ class OS(Class, ABC): @abstractmethod def get_name(self) -> str: """Return mandatory name.""" - - def __str__(self) -> str: - """Return root & name.""" - return f"""\ -root = {self.root} -name = {self.name} -""" diff --git a/rwx/os/pm/__init__.py b/rwx/os/pm/__init__.py index b3cacc4..6236ee6 100644 --- a/rwx/os/pm/__init__.py +++ b/rwx/os/pm/__init__.py @@ -21,10 +21,3 @@ class PM(Class, ABC): @abstractmethod def get_install_command(self) -> Command: """Command to install package(s).""" - - def __str__(self) -> str: - """Return commands.""" - return f"""\ - clean = {self.clean} -install = {self.install} -""" diff --git a/rwx/prj/__init__.py b/rwx/prj/__init__.py index 3cba90b..c0251e2 100644 --- a/rwx/prj/__init__.py +++ b/rwx/prj/__init__.py @@ -14,12 +14,3 @@ class Project(Class): self.file = self.raw.resolve() self.root: Path = self.file.parent self.name: str = self.root.name - - def __str__(self) -> str: - """Return file, root & name.""" - return f"""\ - raw = {self.raw} -file = {self.file} -root = {self.root} -name = {self.name} -""" diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index 601aca3..584c50d 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -13,13 +13,6 @@ class Command(Class): self.raw = arguments self.flat: list[str] = [] - def __str__(self) -> str: - """Return raw & flat.""" - return f"""\ - raw = {self.raw} -flat = {self.flat} -""" - def get_tuples_args(*items: str | tuple[str, ...]) -> list[str]: """Turn arguments tuples into an arguments list.""" From 622122cdefd7bd32a1647d24e3f637bbc555ae8f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Sep 2024 12:53:17 +0200 Subject: [PATCH 074/102] doc/prj --- rwx/prj/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rwx/prj/__init__.py b/rwx/prj/__init__.py index c0251e2..cfbe3ae 100644 --- a/rwx/prj/__init__.py +++ b/rwx/prj/__init__.py @@ -9,7 +9,11 @@ class Project(Class): """Parent class for any type of project.""" def __init__(self, file: Path) -> None: - """Set file, root & name.""" + """Set file, root & name. + + :param file: root reference file + :type file: Path + """ self.raw = file self.file = self.raw.resolve() self.root: Path = self.file.parent From d6e112d6c50115faa4d54c6c21fd6aa26541ce46 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Sep 2024 12:54:41 +0200 Subject: [PATCH 075/102] doc/debian --- rwx/os/debian.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rwx/os/debian.py b/rwx/os/debian.py index 98c8928..5cefdaa 100644 --- a/rwx/os/debian.py +++ b/rwx/os/debian.py @@ -7,5 +7,8 @@ class Debian(OS): """Debian operating system.""" def get_name(self) -> str: - """Return name.""" + """Return name. + + :rtype: str + """ return "Debian" From 012b10f7d56d12b7125798cbed00e7f28b8ef61f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Sep 2024 14:53:21 +0200 Subject: [PATCH 076/102] doc/grub --- rwx/grub/__init__.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rwx/grub/__init__.py b/rwx/grub/__init__.py index 7c0cccc..572b13e 100644 --- a/rwx/grub/__init__.py +++ b/rwx/grub/__init__.py @@ -24,7 +24,19 @@ def make_image( memdisk_path: str, pubkey_path: str | None = None, ) -> None: - """Make a binary bootable image.""" + """Make a binary bootable image. + + :param image_format: output format (x86_64-efi, i386-pc, arm64-efi) + :type image_format: str + :param image_path: output file + :type image_path: str + :param modules: modules to embed + :type modules: list[str] + :param memdisk_path: archive to include + :type memdisk_path: str + :param pubkey_path: extra public key to add + :type pubkey_path: str | None + """ args: list[str | tuple[str, ...]] = [ "grub-mkimage", ("--compress", COMPRESSION), From b9754b5dde4ad682883f1ea7affabeb207c6a276 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Sep 2024 21:32:08 +0200 Subject: [PATCH 077/102] doc/cmd --- rwx/cmd/__init__.py | 6 +++++- rwx/cmd/squashfs/__init__.py | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/rwx/cmd/__init__.py b/rwx/cmd/__init__.py index ca4dced..be9e540 100644 --- a/rwx/cmd/__init__.py +++ b/rwx/cmd/__init__.py @@ -5,7 +5,11 @@ packages: list[str] = [] def need(command: str) -> None: - """Assert package dependency for a command.""" + """Assert package dependency for a command. + + :param command: name of the requested command + :type command: str + """ package: str | None match command: case "debootstrap": diff --git a/rwx/cmd/squashfs/__init__.py b/rwx/cmd/squashfs/__init__.py index db603da..b3ec864 100644 --- a/rwx/cmd/squashfs/__init__.py +++ b/rwx/cmd/squashfs/__init__.py @@ -1,16 +1,24 @@ """Wrap SquashFS commands.""" +from pathlib import Path + from rwx import cmd, ps cmd.need("mksquashfs") -def mksquashfs(input_root: str, output_file: str) -> None: - """Make a SquashFS bootable image file.""" +def mksquashfs(input_root: Path, output_file: Path) -> None: + """Make a SquashFS bootable image file. + + :param input_root: ? + :type input_root: Path + :param output_file: ? + :type output_file: Path + """ ps.run( "mksquashfs", - input_root, - output_file, + str(input_root), + str(output_file), "-comp", "zstd", "-Xcompression-level", From 2e00140e8267a2840828f1d4646cd01a0ed4e4b8 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Sep 2024 22:08:14 +0200 Subject: [PATCH 078/102] doc/deb --- rwx/deb/__init__.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/rwx/deb/__init__.py b/rwx/deb/__init__.py index fcd4198..2537321 100644 --- a/rwx/deb/__init__.py +++ b/rwx/deb/__init__.py @@ -1,5 +1,7 @@ """Wrap Debian commands.""" +from pathlib import Path + from rwx import cmd, ps cmd.need("debootstrap") @@ -8,14 +10,22 @@ BOOTSTRAP_ARCHITECTURE = "amd64" BOOTSTRAP_VARIANT = "minbase" -def bootstrap(root_path: str, suite: str, mirror_location: str) -> None: - """Boostrap a base operating filesystem.""" - command = [ - ("debootstrap",), +def bootstrap(root_path: Path, suite: str, mirror_location: str) -> None: + """Boostrap a base operating filesystem. + + :param root_path: target output path + :type root_path: Path + :param suite: target distribution name + :type suite: str + :param mirror_location: source input repository + :type mirror_location: str + """ + command = ( + "debootstrap", ("--arch", BOOTSTRAP_ARCHITECTURE), ("--variant", BOOTSTRAP_VARIANT), - (suite,), - (root_path,), - (mirror_location,), - ] + suite, + str(root_path), + mirror_location, + ) ps.run(*command) From 3940d3219561aca50f321ad8749addaa325536bd Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Sep 2024 22:14:01 +0200 Subject: [PATCH 079/102] doc/pm --- rwx/os/pm/__init__.py | 10 ++++++++-- rwx/os/pm/apt.py | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/rwx/os/pm/__init__.py b/rwx/os/pm/__init__.py index 6236ee6..c55179a 100644 --- a/rwx/os/pm/__init__.py +++ b/rwx/os/pm/__init__.py @@ -16,8 +16,14 @@ class PM(Class, ABC): @abstractmethod def get_clean_command(self) -> Command: - """Command to clean packages cache.""" + """Command to clean packages cache. + + :rtype: Command + """ @abstractmethod def get_install_command(self) -> Command: - """Command to install package(s).""" + """Command to install package(s). + + :rtype: Command + """ diff --git a/rwx/os/pm/apt.py b/rwx/os/pm/apt.py index 03217b8..3e3cb81 100644 --- a/rwx/os/pm/apt.py +++ b/rwx/os/pm/apt.py @@ -8,9 +8,15 @@ class APT(PM): """Advanced Package Tool.""" def get_clean_command(self) -> Command: - """Return clean command.""" + """Return clean command. + + :rtype: Command + """ return Command() def get_install_command(self) -> Command: - """Return install command.""" + """Return install command. + + :rtype: Command + """ return Command() From e9d228ba2c556822a946a146952312e719a13cd7 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Sep 2024 22:17:41 +0200 Subject: [PATCH 080/102] doc/os --- rwx/os/__init__.py | 7 ++++++- rwx/os/abstract.py | 11 +++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/rwx/os/__init__.py b/rwx/os/__init__.py index 75a0bc9..27c1748 100644 --- a/rwx/os/__init__.py +++ b/rwx/os/__init__.py @@ -8,7 +8,12 @@ from .debian import Debian def from_path(path: Path) -> OS: - """Initialize from an already existing path.""" + """Initialize from an already existing path. + + :param path: source root directory + :type path: Path + :rtype: OS + """ return Debian(path) diff --git a/rwx/os/abstract.py b/rwx/os/abstract.py index f4837fc..77f9cb1 100644 --- a/rwx/os/abstract.py +++ b/rwx/os/abstract.py @@ -10,10 +10,17 @@ class OS(Class, ABC): """Operating System.""" def __init__(self, path: Path) -> None: - """Set root.""" + """Set root. + + :param path: root directory + :type path: Path + """ self.root = path self.name = self.get_name() @abstractmethod def get_name(self) -> str: - """Return mandatory name.""" + """Return mandatory name. + + :rtype: str + """ From 149ed2dc3be27e1d336fffddf1bd3cfd6b3ded21 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Sep 2024 22:22:03 +0200 Subject: [PATCH 081/102] doc/log --- rwx/log/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/rwx/log/__init__.py b/rwx/log/__init__.py index 3b245ae..53cfebc 100644 --- a/rwx/log/__init__.py +++ b/rwx/log/__init__.py @@ -5,7 +5,12 @@ import sys def get_file_logger(name: str) -> logging.Logger: - """Return a file logger.""" + """Return a file logger. + + :param name: arbitrary name + :type name: str + :rtype: logging.Logger + """ # formatter items = [ "%(name)s: %(asctime)s", @@ -27,7 +32,12 @@ def get_file_logger(name: str) -> logging.Logger: def get_stream_logger(level: int) -> logging.Logger: - """Return a stream logger.""" + """Return a stream logger. + + :param level: filtering level + :type level: int + :rtype: logging.Logger + """ # handler out_handler = logging.StreamHandler(stream=sys.stdout) out_handler.setLevel(level) From 313cc30aec004067751607d3ca62570d4ffc5671 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Sep 2024 22:35:05 +0200 Subject: [PATCH 082/102] doc/ps --- rwx/ps/__init__.py | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index 584c50d..821b9e3 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -9,13 +9,22 @@ class Command(Class): """Command to run.""" def __init__(self, *arguments: str | tuple[str, ...]) -> None: - """Set raw & flat arguments.""" + """Set raw & flat arguments. + + :param *arguments: single argument or grouped ones + :type *arguments: str | tuple[str, ...] + """ self.raw = arguments self.flat: 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. + + :param *items: single item or grouped ones + :type *items: str | tuple[str, ...] + :rtype: list[str] + """ args: list[str] = [] for item in items: match item: @@ -27,14 +36,26 @@ def get_tuples_args(*items: str | tuple[str, ...]) -> list[str]: def run(*items: str | tuple[str, ...]) -> subprocess.CompletedProcess: - """Run from a list of arguments tuples.""" + """Run from a list of arguments tuples. + + :param *items: single item or grouped ones + :type *items: str | tuple[str, ...] + :rtype: subprocess.CompletedProcess + """ return subprocess.run( get_tuples_args(*items), capture_output=False, check=True ) def run_line(*items: str | tuple[str, ...], charset: str = txt.CHARSET) -> str: - """Run and return output line.""" + """Run and return output line. + + :param *items: single item or grouped ones + :type *items: str | tuple[str, ...] + :param charset: charset to use for decoding binary output + :type charset: str + :rtype: str + """ line, *_ = run_lines(*items, charset=charset) return line @@ -42,7 +63,14 @@ def run_line(*items: str | tuple[str, ...], charset: str = txt.CHARSET) -> str: def run_lines( *items: str | tuple[str, ...], charset: str = txt.CHARSET ) -> list[str]: - """Run and return output lines.""" + """Run and return output lines. + + :param *items: single item or grouped ones + :type *items: str | tuple[str, ...] + :param charset: charset to use for decoding binary output + :type charset: str + :rtype: list[str] + """ process = subprocess.run( get_tuples_args(*items), capture_output=True, check=True ) From b05de437d000545c73d169debe36aff1a7d60edf Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Sep 2024 22:42:19 +0200 Subject: [PATCH 083/102] doc/wipe --- rwx/fs/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index ee1925d..1b9e811 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -69,7 +69,11 @@ def read_file_text(file_path: Path, charset: str = CHARSET) -> str: def wipe(path: Path) -> None: - """Wipe provided path, whether directory or file.""" + """Wipe provided path, whether directory or file. + + :param path: target path + :type path: Path + """ try: shutil.rmtree(path) except NotADirectoryError: From eb0f8621252b0daf3f83545d1754adf877dc3920 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Sep 2024 23:05:00 +0200 Subject: [PATCH 084/102] doc/write --- rwx/fs/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 1b9e811..7595335 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -83,6 +83,14 @@ def wipe(path: Path) -> None: def write(file_path: Path, text: str, charset: str = CHARSET) -> None: - """Write text into a file.""" + """Write text into a file. + + :param file_path: target file path + :type file_path: Path + :param text: content to write + :type text: str + :param charset: charset to use for encoding ouput + :type charset: str + """ with file_path.open(encoding=charset, mode="w") as file_object: file_object.write(text) From 2c6bec253c4ddf88fa567816963cb8e16be2ff73 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Sep 2024 23:07:41 +0200 Subject: [PATCH 085/102] doc/empty_file --- rwx/fs/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 7595335..21ead50 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -19,7 +19,11 @@ def create_image(file_path: str, size_bytes: int) -> None: def empty_file(path: Path) -> None: - """Empty the file at provided path.""" + """Empty the file at provided path. + + :param path: target file to empty + :type path: Path + """ write(path, "") From 0d77038392952ceb36786ffb00d59153c6086b2d Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Sep 2024 23:17:36 +0200 Subject: [PATCH 086/102] doc/create_image --- rwx/fs/__init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 21ead50..b320ed2 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -9,12 +9,18 @@ from rwx import ps CHARSET = "UTF-8" -def create_image(file_path: str, size_bytes: int) -> None: - """Create a virtual device image file.""" +def create_image(file_path: Path, size_bytes: int) -> None: + """Create a virtual device image file. + + :param file_path: target image file + :type file_path: Path + :param size_bytes: virtual volume + :type size_bytes: int + """ ps.run( ("qemu-img", "create"), ("-f", "qcow2"), - (file_path, str(size_bytes)), + (str(file_path), str(size_bytes)), ) From 6fab5ce9b401eeffa123a7ba10aee71eba94a16c Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Sep 2024 23:19:29 +0200 Subject: [PATCH 087/102] doc/make_directory --- rwx/fs/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index b320ed2..374a658 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -58,7 +58,11 @@ def get_path_uuid(path: str) -> str: def make_directory(path: Path) -> None: - """Make a directory (and its parents) from a path.""" + """Make a directory (and its parents) from a path. + + :param path: directory to create + :type path: Path + """ path.mkdir(exist_ok=True, parents=True) From 094d66bc33fc39d344153db245192da6caf7c007 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Sep 2024 23:23:38 +0200 Subject: [PATCH 088/102] doc/read_file_ --- rwx/fs/__init__.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 374a658..5767015 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -67,18 +67,37 @@ def make_directory(path: Path) -> None: def read_file_bytes(file_path: Path) -> bytes: - """Read whole file bytes.""" + """Read whole file bytes. + + :param file_path: source input file + :type file_path: Path + :rtype: bytes + """ with file_path.open("br") as file_object: return file_object.read() def read_file_lines(file_path: Path, charset: str = CHARSET) -> list[str]: - """Read whole file lines.""" + """Read whole file lines. + + :param file_path: source input file + :type file_path: Path + :param charset: charset to use for decoding input + :type charset: str + :rtype: list[str] + """ return read_file_text(file_path, charset).split(os.linesep) def read_file_text(file_path: Path, charset: str = CHARSET) -> str: - """Read whole file text.""" + """Read whole file text. + + :param file_path: source input file + :type file_path: Path + :param charset: charset to use for decoding input + :type charset: str + :rtype: str + """ return read_file_bytes(file_path).decode(charset) From 2327d5388dc93f1e5d6255dcfde567ef523c0ba2 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Sep 2024 23:32:51 +0200 Subject: [PATCH 089/102] doc/get_path_uuid --- rwx/fs/__init__.py | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 5767015..6abcce7 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -33,27 +33,44 @@ def empty_file(path: Path) -> None: write(path, "") -def get_mount_uuid(path: str) -> str: - """Return the filesystem UUID of a mountpoint path.""" +def get_mount_uuid(path: Path) -> str: + """Return the filesystem UUID of a mountpoint path. + + :param path: mountpoint path + :type path: Path + :rtype: str + """ return ps.run_line( - ("findmnt",), - ("--noheadings",), + "findmnt", + "--noheadings", ("--output", "UUID"), - (path,), + str(path), ) -def get_path_mount(path: str) -> str: - """Return the mountpoint path of an arbitrary path.""" - return ps.run_line( - "stat", - ("--format", "%m"), - path, +def get_path_mount(path: Path) -> Path: + """Return the mountpoint path of an arbitrary path. + + :param path: arbitrary path + :type path: Path + :rtype: Path + """ + return Path( + ps.run_line( + "stat", + ("--format", "%m"), + str(path), + ) ) -def get_path_uuid(path: str) -> str: - """Return the filesystem UUID of an arbitrary path.""" +def get_path_uuid(path: Path) -> str: + """Return the filesystem UUID of an arbitrary path. + + :param path: arbitrary path + :type path: Path + :rtype: str + """ return get_mount_uuid(get_path_mount(path)) From e61be6cf4fdd00a51b6b7f039b005e1a58937051 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 23 Sep 2024 12:53:28 +0200 Subject: [PATCH 090/102] sw.freetube --- rwx/sw/freetube/__init__.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 rwx/sw/freetube/__init__.py diff --git a/rwx/sw/freetube/__init__.py b/rwx/sw/freetube/__init__.py new file mode 100644 index 0000000..cb60ff9 --- /dev/null +++ b/rwx/sw/freetube/__init__.py @@ -0,0 +1 @@ +"""Handle FreeTube configuration.""" From 19153b3bc1f7372b2142f1ec403afb87012f003b Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 23 Sep 2024 13:04:56 +0200 Subject: [PATCH 091/102] freetube.db --- rwx/sw/freetube/db.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 rwx/sw/freetube/db.py diff --git a/rwx/sw/freetube/db.py b/rwx/sw/freetube/db.py new file mode 100644 index 0000000..4b3f56b --- /dev/null +++ b/rwx/sw/freetube/db.py @@ -0,0 +1,20 @@ +"""Handle FreeTube db.""" + +def to_db(value: object) -> str: + """Render value as string. + + :param value: value to render + :type value: object + :rtype: str + """ + match value: + case bool(): + text = str(value).lower() + case dict(): + sub = ",".join([f'"{i}":{to_db(v)}' for i, v in value.items()]) + text = f"{{{sub}}}" + case float() | str(): + text = f'"{value}"' + case _: + text = str(value) + return text From 45df47519543f239ba7e4ef7ac6c4969aa1c315d Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 23 Sep 2024 13:27:16 +0200 Subject: [PATCH 092/102] freetube.settings --- rwx/sw/freetube/__init__.py | 2 +- rwx/sw/freetube/db.py | 2 +- rwx/sw/freetube/settings.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 rwx/sw/freetube/settings.py diff --git a/rwx/sw/freetube/__init__.py b/rwx/sw/freetube/__init__.py index cb60ff9..250b9c3 100644 --- a/rwx/sw/freetube/__init__.py +++ b/rwx/sw/freetube/__init__.py @@ -1 +1 @@ -"""Handle FreeTube configuration.""" +"""Configure FreeTube.""" diff --git a/rwx/sw/freetube/db.py b/rwx/sw/freetube/db.py index 4b3f56b..9e37162 100644 --- a/rwx/sw/freetube/db.py +++ b/rwx/sw/freetube/db.py @@ -1,4 +1,4 @@ -"""Handle FreeTube db.""" +"""Output FreeTube db.""" def to_db(value: object) -> str: """Render value as string. diff --git a/rwx/sw/freetube/settings.py b/rwx/sw/freetube/settings.py new file mode 100644 index 0000000..67bb084 --- /dev/null +++ b/rwx/sw/freetube/settings.py @@ -0,0 +1,33 @@ +"""FreeTube settings.""" + +from rwx import Class + +from .db import to_db + + +class Setting(Class): + """FreeTube setting.""" + + def __init__(self, uid: str, value: object) -> None: + """Set uid & value. + + :param uid: unique identifier + :type uid: str + :param value: value + :type value: object + """ + self.uid = uid + self.value = value + + def to_db(self) -> str: + """Return uid & value as db string. + + :rtype: str + """ + return f"""\ +{{\ +"_id":"{self.uid}"\ +,\ +"value":{to_db(self.value)}\ +}}\ +""" From 2a01ef0066b332f7165f298bfab8a907e67f5d48 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 23 Sep 2024 14:24:58 +0200 Subject: [PATCH 093/102] freetube.channels --- rwx/sw/freetube/channels.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 rwx/sw/freetube/channels.py diff --git a/rwx/sw/freetube/channels.py b/rwx/sw/freetube/channels.py new file mode 100644 index 0000000..48f6d05 --- /dev/null +++ b/rwx/sw/freetube/channels.py @@ -0,0 +1,29 @@ +"""FreeTube channels.""" + +from rwx import Class + + +class Channel(Class): + """FreeTube channel.""" + + def __init__(self, uid: str, name: str) -> None: + """Set uid & name. + + :param uid: unique identifier + :type uid: str + :param name: label + :type name: str + """ + self.id = uid + self.name = name + + def to_db(self) -> str: + """Return identifier as db. + + :rtype: str + """ + return f"""\ +{{\ +"id":"{self.id}"\ +}}\ +""" From 6ece695be4c1d2d508bd4aaebc12798ebdf9a484 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 23 Sep 2024 14:35:16 +0200 Subject: [PATCH 094/102] channel.uid --- rwx/sw/freetube/channels.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rwx/sw/freetube/channels.py b/rwx/sw/freetube/channels.py index 48f6d05..30777e9 100644 --- a/rwx/sw/freetube/channels.py +++ b/rwx/sw/freetube/channels.py @@ -14,7 +14,7 @@ class Channel(Class): :param name: label :type name: str """ - self.id = uid + self.uid = uid self.name = name def to_db(self) -> str: @@ -24,6 +24,6 @@ class Channel(Class): """ return f"""\ {{\ -"id":"{self.id}"\ +"id":"{self.uid}"\ }}\ """ From 46ec104b7571a8dd1de42a5044841aaa28305015 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 23 Sep 2024 14:35:32 +0200 Subject: [PATCH 095/102] freetube.videos --- rwx/sw/freetube/videos.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 rwx/sw/freetube/videos.py diff --git a/rwx/sw/freetube/videos.py b/rwx/sw/freetube/videos.py new file mode 100644 index 0000000..8a53713 --- /dev/null +++ b/rwx/sw/freetube/videos.py @@ -0,0 +1,33 @@ +"""FreeTube videos.""" + +from rwx import Class + + +class Video(Class): + """FreeTube video.""" + + def __init__(self, uid: str, name: str) -> None: + """Set id & name. + + :param uid: identifier + :type uid: str + :param name: label + :type name: str + """ + self.uid = uid + self.name = name + + def to_db(self) -> str: + """Return identifier, zero length & title. + + :rtype: str + """ + return f"""\ +{{\ +"videoId":"{self.uid}"\ +,\ +"lengthSeconds":0\ +,\ +"title":"{self.name}"\ +}}\ +""" From a92a3a786a672dc93b3ad20904ffdcc1b94c5b6f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 23 Sep 2024 14:46:13 +0200 Subject: [PATCH 096/102] freetube.playlists --- rwx/sw/freetube/playlists.py | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 rwx/sw/freetube/playlists.py diff --git a/rwx/sw/freetube/playlists.py b/rwx/sw/freetube/playlists.py new file mode 100644 index 0000000..4183336 --- /dev/null +++ b/rwx/sw/freetube/playlists.py @@ -0,0 +1,47 @@ +"""FreeTube playlists.""" + +from rwx import Class + +from .videos import Video + + +class Playlist(Class): + """FreeTube playlist.""" + + def __init__(self, uid: str, name: str) -> None: + """Set uid & name. + + :param uid: identifier + :type uid: str + :param name: label + :type name: str + """ + self.uid = uid + self.name = name + self.videos: list[Video] = [] + + def add(self, video: Video) -> None: + """Add video. + + :param video: video to add + :type video: Video + """ + self.videos.append(video) + + def to_db(self) -> str: + """Return identifier, name & videos. + + :rtype: str + """ + videos = ",".join([video.to_db() for video in self.videos]) + return f"""\ +{{\ +"_id":"{self.uid}"\ +,\ +"playlistName":"{self.name}"\ +,\ +"protected":true\ +,\ +"videos":[{videos}]\ +}}\ +""" From edd8e15978b1d08938f363f48339fa691776afe7 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 23 Sep 2024 14:59:00 +0200 Subject: [PATCH 097/102] freetube.profiles --- rwx/sw/freetube/profiles.py | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 rwx/sw/freetube/profiles.py diff --git a/rwx/sw/freetube/profiles.py b/rwx/sw/freetube/profiles.py new file mode 100644 index 0000000..ffb0adc --- /dev/null +++ b/rwx/sw/freetube/profiles.py @@ -0,0 +1,45 @@ +"""FreeTube profiles.""" + +from rwx import Class + +from .channels import Channel + + +class Profile(Class): + """FreeTube profile.""" + + def __init__(self, uid: str, name: str) -> None: + """Set uid & name. + + :param uid: unique identifier + :type uid: str + :param name: label + :type name: str + """ + self.id = uid + self.name = name + self.channels: list[Channel] = [] + + def add(self, channel: Channel) -> None: + """Add channel. + + :param channel: channel to add + :type channel: Channel + """ + self.channels.append(channel) + + def to_db(self) -> str: + """Return identifier, name & channels. + + :rtype: str + """ + channels = ",".join([channel.to_db() for channel in self.channels]) + return f"""\ +{{\ +"_id":"{self.id}"\ +,\ +"name":"{self.name}"\ +,\ +"subscriptions":[{channels}]\ +}}\ +""" From 5eae0334de4494b63207e8e1ad784f8a4c1c7d4d Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 23 Sep 2024 17:25:57 +0200 Subject: [PATCH 098/102] fs.read_file_object --- rwx/fs/__init__.py | 14 ++++++++++++++ rwx/sw/freetube/db.py | 1 + 2 files changed, 15 insertions(+) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 6abcce7..184c198 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -2,6 +2,7 @@ import os import shutil +import tomllib from pathlib import Path from rwx import ps @@ -106,6 +107,19 @@ def read_file_lines(file_path: Path, charset: str = CHARSET) -> list[str]: return read_file_text(file_path, charset).split(os.linesep) +def read_file_object(file_path: Path, charset: str = CHARSET) -> object: + """Read whole file as toml object. + + :param file_path: source input file + :type file_path: Path + :param charset: charset to use for decoding input + :type charset: str + :rtype: object + """ + text = read_file_text(file_path, charset) + return tomllib.loads(text) + + def read_file_text(file_path: Path, charset: str = CHARSET) -> str: """Read whole file text. diff --git a/rwx/sw/freetube/db.py b/rwx/sw/freetube/db.py index 9e37162..e3eb31e 100644 --- a/rwx/sw/freetube/db.py +++ b/rwx/sw/freetube/db.py @@ -1,5 +1,6 @@ """Output FreeTube db.""" + def to_db(value: object) -> str: """Render value as string. From daccf01b8c406704d088a621a6b18f567bcba673 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 23 Sep 2024 18:48:44 +0200 Subject: [PATCH 099/102] read_file_dict --- rwx/fs/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 184c198..46a26e6 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -107,14 +107,14 @@ def read_file_lines(file_path: Path, charset: str = CHARSET) -> list[str]: return read_file_text(file_path, charset).split(os.linesep) -def read_file_object(file_path: Path, charset: str = CHARSET) -> object: +def read_file_dict(file_path: Path, charset: str = CHARSET) -> dict: """Read whole file as toml object. :param file_path: source input file :type file_path: Path :param charset: charset to use for decoding input :type charset: str - :rtype: object + :rtype: dict """ text = read_file_text(file_path, charset) return tomllib.loads(text) From eb3c9814bb1f1f5408fa2667437cbf4050ac1493 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 23 Sep 2024 18:49:34 +0200 Subject: [PATCH 100/102] mv --- rwx/fs/__init__.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 46a26e6..205746d 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -95,18 +95,6 @@ def read_file_bytes(file_path: Path) -> bytes: return file_object.read() -def read_file_lines(file_path: Path, charset: str = CHARSET) -> list[str]: - """Read whole file lines. - - :param file_path: source input file - :type file_path: Path - :param charset: charset to use for decoding input - :type charset: str - :rtype: list[str] - """ - return read_file_text(file_path, charset).split(os.linesep) - - def read_file_dict(file_path: Path, charset: str = CHARSET) -> dict: """Read whole file as toml object. @@ -120,6 +108,18 @@ def read_file_dict(file_path: Path, charset: str = CHARSET) -> dict: return tomllib.loads(text) +def read_file_lines(file_path: Path, charset: str = CHARSET) -> list[str]: + """Read whole file lines. + + :param file_path: source input file + :type file_path: Path + :param charset: charset to use for decoding input + :type charset: str + :rtype: list[str] + """ + return read_file_text(file_path, charset).split(os.linesep) + + def read_file_text(file_path: Path, charset: str = CHARSET) -> str: """Read whole file text. From 1c4f52007cb1022da2011006708f1160afed9941 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 13 Oct 2024 21:42:16 +0200 Subject: [PATCH 101/102] build & workflow --- .forgejo/workflows/main.yaml | 18 ++++++++++++++++++ build.py | 11 +++++++++++ 2 files changed, 29 insertions(+) create mode 100644 .forgejo/workflows/main.yaml create mode 100755 build.py diff --git a/.forgejo/workflows/main.yaml b/.forgejo/workflows/main.yaml new file mode 100644 index 0000000..78facd9 --- /dev/null +++ b/.forgejo/workflows/main.yaml @@ -0,0 +1,18 @@ +on: [push] +jobs: + job: + container: + image: ${{vars.DOCKER}}debian:bookworm + steps: + - name: spcd + env: + SPCD: ${{vars.SPCD}} + SPCD_SSH_HOSTS: ${{vars.SPCD_SSH_HOSTS}} + SPCD_SSH_KEY: ${{secrets.SPCD_SSH_KEY}} + SPCD_TXT_LOCALE: ${{vars.SPCD_TXT_LOCALE}} + run: ${{vars.SPCD}} + + - run: spcd-check-project + - run: spcd-build-project + - run: spcd-browse-workspace + - run: spcd-synchronize diff --git a/build.py b/build.py new file mode 100755 index 0000000..3a0a957 --- /dev/null +++ b/build.py @@ -0,0 +1,11 @@ +#! /usr/bin/env python3 +"""Dummy build.""" + +from pathlib import Path + +from rwx.fs import make_directory, write + +if __name__ == "__main__": + out = Path(__file__).parent / "out" / "web" + make_directory(out) + write(out / "index.html", "rwx.rwx.work") From 98350281993d8821cba71087f7ad8ad83e9dded7 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 13 Oct 2024 21:46:54 +0200 Subject: [PATCH 102/102] =?UTF-8?q?=E2=88=92check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .forgejo/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/main.yaml b/.forgejo/workflows/main.yaml index 78facd9..bcc505a 100644 --- a/.forgejo/workflows/main.yaml +++ b/.forgejo/workflows/main.yaml @@ -12,7 +12,7 @@ jobs: SPCD_TXT_LOCALE: ${{vars.SPCD_TXT_LOCALE}} run: ${{vars.SPCD}} - - run: spcd-check-project + #- run: spcd-check-project - run: spcd-build-project - run: spcd-browse-workspace - run: spcd-synchronize