From b969aa886e6d83ce815e36381f0b7d60b3d49057 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 09:34:45 +0200 Subject: [PATCH 01/37] ignore /.vscode --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 90c0433..0800ae8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ __pycache__ /tmp -/.idea +/.vscode /dist From 4ab0a575b7b9439c219e60d3768424d2dc6af40a Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 09:35:12 +0200 Subject: [PATCH 02/37] pyproject/ruff --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index ac386d1..2c1938b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,3 +30,6 @@ requires-python = '>= 3.10' [tool.hatch.version] path = 'rwx/__init__.py' + +[tool.ruff] +select = ["ALL"] From 566617758228ea575e0f518f0388e7ae15ec9d16 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 09:37:23 +0200 Subject: [PATCH 03/37] pyproject/" --- pyproject.toml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2c1938b..ccd0aa1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,35 +1,35 @@ [build-system] -requires = ['hatchling'] -build-backend = 'hatchling.build' +requires = ["hatchling"] +build-backend = "hatchling.build" [project] authors = [ - { name = 'Marc Beninca', email = 'git@marc.beninca.link' }, + { name = "Marc Beninca", email = "git@marc.beninca.link" }, ] maintainers = [ - { name = 'Marc Beninca', email = 'git@marc.beninca.link' }, + { name = "Marc Beninca", email = "git@marc.beninca.link" }, ] classifiers = [ - 'Programming Language :: Python :: 3', - 'License :: OSI Approved :: GNU Affero General Public License v3', - 'Operating System :: OS Independent', + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU Affero General Public License v3", + "Operating System :: OS Independent", ] dependencies = [] -description = 'Read Write eXecute' -dynamic = ['version'] +description = "Read Write eXecute" +dynamic = ["version"] keywords = [] -license-files = { paths = ['license.md'] } -name = 'rwx' -readme = 'readme.md' -requires-python = '>= 3.10' +license-files = { paths = ["license.md"] } +name = "rwx" +readme = "readme.md" +requires-python = ">= 3.10" [project.scripts] -# command = 'package.module:function' +# command = "package.module:function" [project.urls] [tool.hatch.version] -path = 'rwx/__init__.py' +path = "rwx/__init__.py" [tool.ruff] select = ["ALL"] From b197a156896d0e8cae8869122e05a1f4d5434027 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 09:38:08 +0200 Subject: [PATCH 04/37] linting --- rwx/prj/sphinx.py | 2 +- rwx/txt/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rwx/prj/sphinx.py b/rwx/prj/sphinx.py index 4da1ebf..392e7c2 100644 --- a/rwx/prj/sphinx.py +++ b/rwx/prj/sphinx.py @@ -10,7 +10,7 @@ class SphinxProject(Project): super().__init__(file_path) def build(self): - output_root: str = path.join(self.root, 'out') + output_root: str = path.join(self.root, "out") wipe(output_root) arguments: list[str] = [ "-E", diff --git a/rwx/txt/__init__.py b/rwx/txt/__init__.py index edb0624..369202c 100644 --- a/rwx/txt/__init__.py +++ b/rwx/txt/__init__.py @@ -1 +1 @@ -CHARSET = 'UTF-8' +CHARSET = "UTF-8" From fdbd850d231104fc6264536e2ef7d082152adf9e Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 09:41:34 +0200 Subject: [PATCH 05/37] lint rwx --- rwx/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rwx/__init__.py b/rwx/__init__.py index b8023d8..a721b9a 100644 --- a/rwx/__init__.py +++ b/rwx/__init__.py @@ -1 +1,2 @@ -__version__ = '0.0.1' +"""Read Write eXecute.""" +__version__ = "0.0.1" From a4f49d6ac09549d958588b3eec84cedcaaa0c412 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 09:43:22 +0200 Subject: [PATCH 06/37] exception --- rwx/err/__init__.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 rwx/err/__init__.py diff --git a/rwx/err/__init__.py b/rwx/err/__init__.py new file mode 100644 index 0000000..b996913 --- /dev/null +++ b/rwx/err/__init__.py @@ -0,0 +1,2 @@ +class Exception(Exception): + pass From c7db231dc2a5e6244e06dea770a4cb3f6a6ce430 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 09:50:13 +0200 Subject: [PATCH 07/37] lint grub --- rwx/grub/__init__.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/rwx/grub/__init__.py b/rwx/grub/__init__.py index b931ee3..a11cf7d 100644 --- a/rwx/grub/__init__.py +++ b/rwx/grub/__init__.py @@ -1,17 +1,17 @@ import cmd import ps -cmd.need('grub-mkimage') +cmd.need("grub-mkimage") -COMPRESSION = 'xz' +COMPRESSION = "xz" ENV_BYTES = 1024 -ENV_COMMENT = '#' -ENV_HEADER = f'''{ENV_COMMENT} GRUB Environment Block -''' +ENV_COMMENT = "#" +ENV_HEADER = f"""{ENV_COMMENT} GRUB Environment Block +""" MODULES = { - 'i386-pc': [ - ('biosdisk',), - ('ntldr',), + "i386-pc": [ + ("biosdisk",), + ("ntldr",), ] } @@ -19,14 +19,14 @@ MODULES = { def make_image(image_format: str, image_path: str, modules: list[str], memdisk_path: str, pubkey_path: str = None) -> None: args = [ - ('grub-mkimage',), - ('--compress', COMPRESSION), - ('--format', image_format), - ('--output', image_path), - ('--memdisk', memdisk_path), + ("grub-mkimage",), + ("--compress", COMPRESSION), + ("--format", image_format), + ("--output", image_path), + ("--memdisk", memdisk_path), ] if pubkey_path: - args.append(('--pubkey', pubkey_path)) + args.append(("--pubkey", pubkey_path)) args.extend(modules) if modules := MODULES.get(image_format, None): args.extend(modules) From 592023d2140ea11b5b854072a6893bbe8d8973f6 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 09:51:59 +0200 Subject: [PATCH 08/37] lint fs --- rwx/fs/__init__.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index ecaebf0..2a6af2c 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -3,13 +3,13 @@ import shutil from rwx import ps -CHARSET = 'UTF-8' +CHARSET = "UTF-8" def create_image(file_path: str, size_bytes: int): ps.run( - ('qemu-img', 'create'), - ('-f', 'qcow2'), + ("qemu-img", "create"), + ("-f", "qcow2"), (file_path, size_bytes), ) @@ -20,17 +20,17 @@ def empty_file(path: str): def get_mount_uuid(path: str): return ps.run_line( - ('findmnt',), - ('--noheadings',), - ('--output', 'UUID'), + ("findmnt",), + ("--noheadings",), + ("--output", "UUID"), (path,), ) def get_path_mount(path: str): return ps.run_line( - ('stat',), - ('--format', '%m'), + ("stat",), + ("--format", "%m"), (path,), ) @@ -44,7 +44,7 @@ def make_directory(path: str): def read_file(file_path: str): - with open(file_path, 'br') as file_object: + with open(file_path, "br") as file_object: return file_object.read() @@ -66,5 +66,5 @@ def wipe(path: str): def write(file_path: str, text: str, charset=CHARSET): - with open(file_path, 'bw') as file_object: + with open(file_path, "bw") as file_object: file_object.write(text.encode(charset)) From 470d7aa1e92480ff9e9fa8ccfeb6a2bbd5b4b2e3 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 09:52:56 +0200 Subject: [PATCH 09/37] lint deb --- rwx/deb/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rwx/deb/__init__.py b/rwx/deb/__init__.py index a773123..7059e93 100644 --- a/rwx/deb/__init__.py +++ b/rwx/deb/__init__.py @@ -1,17 +1,17 @@ import cmd import ps -cmd.need('debootstrap') +cmd.need("debootstrap") -BOOTSTRAP_ARCHITECTURE = 'amd64' -BOOTSTRAP_VARIANT = 'minbase' +BOOTSTRAP_ARCHITECTURE = "amd64" +BOOTSTRAP_VARIANT = "minbase" def bootstrap(root_path: str, suite: str, mirror_location: str): command = [ - ('debootstrap',), - ('--arch', BOOTSTRAP_ARCHITECTURE), - ('--variant', BOOTSTRAP_VARIANT), + ("debootstrap",), + ("--arch", BOOTSTRAP_ARCHITECTURE), + ("--variant", BOOTSTRAP_VARIANT), (suite,), (root_path,), (mirror_location,), From 67b8d4c9819ad3f1f6f2166b4d757f03e656e16e Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 09:53:51 +0200 Subject: [PATCH 10/37] lint squashfs --- rwx/cmd/squashfs/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rwx/cmd/squashfs/__init__.py b/rwx/cmd/squashfs/__init__.py index 637890a..4f793ca 100644 --- a/rwx/cmd/squashfs/__init__.py +++ b/rwx/cmd/squashfs/__init__.py @@ -1,14 +1,14 @@ import ps import rwx.cmd -rwx.cmd.need('mksquashfs') +rwx.cmd.need("mksquashfs") def mksquashfs(input_root: str, output_file: str): ps.run([ - 'mksquashfs', + "mksquashfs", input_root, output_file, - '-comp', 'zstd', - '-Xcompression-level', str(18), + "-comp", "zstd", + "-Xcompression-level", str(18), ]) From bf5a8a65d781c416aba5f6684150421bf8176893 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 09:55:13 +0200 Subject: [PATCH 11/37] lint cmd --- rwx/cmd/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rwx/cmd/__init__.py b/rwx/cmd/__init__.py index 9403d24..6ecb47c 100644 --- a/rwx/cmd/__init__.py +++ b/rwx/cmd/__init__.py @@ -4,10 +4,10 @@ packages: list[str] = [] def need(command: str) -> None: match command: - case 'debootstrap': - package = 'debootstrap' - case 'mksquashfs' | 'unsquashfs': - package = 'squashfs-tools' + case "debootstrap": + package = "debootstrap" + case "mksquashfs" | "unsquashfs": + package = "squashfs-tools" case _: package = None if package: From 517da87ffb51c2577a388a42c9627f8775516317 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 09:56:59 +0200 Subject: [PATCH 12/37] lint main --- rwx/__main__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rwx/__main__.py b/rwx/__main__.py index 0f73041..0f15b2e 100755 --- a/rwx/__main__.py +++ b/rwx/__main__.py @@ -5,14 +5,14 @@ import os import fs -if __name__ == '__main__': +if __name__ == "__main__": file_path = os.path.realpath(__file__) root_path = os.path.dirname(file_path) - directory_path = os.path.join(root_path, 'tmp') - file_path = os.path.join(directory_path, 'file') + directory_path = os.path.join(root_path, "tmp") + file_path = os.path.join(directory_path, "file") fs.wipe(directory_path) fs.make_directory(directory_path) - fs.write(file_path, 'Martine écrit beaucoup.') + fs.write(file_path, "Martine écrit beaucoup.") fs.empty_file(file_path) - fs.write(file_path, 'Martine écrit moins.') + fs.write(file_path, "Martine écrit moins.") From e84417c077d0bdd489a93c4703bf5bd3738e09a1 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 10:01:24 +0200 Subject: [PATCH 13/37] lint fs --- rwx/fs/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 2a6af2c..e769358 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -15,7 +15,7 @@ def create_image(file_path: str, size_bytes: int): def empty_file(path: str): - write(path, str()) + write(path, "") def get_mount_uuid(path: str): From fc3e191dc1aacd97f974836b8584cccae8572153 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 10:04:54 +0200 Subject: [PATCH 14/37] lint prj --- rwx/prj/__init__.py | 2 +- rwx/prj/sphinx.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rwx/prj/__init__.py b/rwx/prj/__init__.py index f0a2fe5..227a686 100644 --- a/rwx/prj/__init__.py +++ b/rwx/prj/__init__.py @@ -2,7 +2,7 @@ from os import path class Project: - def __init__(self, file_path: str): + def __init__(self, file_path: str) -> None: self.file: str = path.realpath(file_path) self.root: str = path.dirname(self.file) self.name: str = path.basename(self.root) diff --git a/rwx/prj/sphinx.py b/rwx/prj/sphinx.py index 392e7c2..a71bc35 100644 --- a/rwx/prj/sphinx.py +++ b/rwx/prj/sphinx.py @@ -6,7 +6,7 @@ from rwx.prj import Project class SphinxProject(Project): - def __init__(self, file_path: str): + def __init__(self, file_path: str) -> None: super().__init__(file_path) def build(self): From b44b6bd4d4e2c39d545e6314b5019c59755fcaa0 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 10:06:25 +0200 Subject: [PATCH 15/37] lint deb --- rwx/deb/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rwx/deb/__init__.py b/rwx/deb/__init__.py index 7059e93..bfb8a2f 100644 --- a/rwx/deb/__init__.py +++ b/rwx/deb/__init__.py @@ -16,5 +16,4 @@ def bootstrap(root_path: str, suite: str, mirror_location: str): (root_path,), (mirror_location,), ] - completed_process = ps.run(command) - return completed_process + return ps.run(command) From c7022836966379a640d007c2d8db8fd03d9f7d73 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 12:49:49 +0200 Subject: [PATCH 16/37] lint commas --- rwx/grub/__init__.py | 2 +- rwx/log/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rwx/grub/__init__.py b/rwx/grub/__init__.py index a11cf7d..3a70ad4 100644 --- a/rwx/grub/__init__.py +++ b/rwx/grub/__init__.py @@ -12,7 +12,7 @@ MODULES = { "i386-pc": [ ("biosdisk",), ("ntldr",), - ] + ], } diff --git a/rwx/log/__init__.py b/rwx/log/__init__.py index 2cf0b09..4d28f82 100644 --- a/rwx/log/__init__.py +++ b/rwx/log/__init__.py @@ -4,7 +4,7 @@ import sys def get_logger(name: str) -> logging.Logger: formatter = logging.Formatter( - "%(name)s: %(asctime)s | %(levelname)s | %(filename)s:%(lineno)s | %(process)d >>> %(message)s" + "%(name)s: %(asctime)s | %(levelname)s | %(filename)s:%(lineno)s | %(process)d >>> %(message)s", ) # file_handler = logging.FileHandler('log.txt') From aad5c140ddec8c365e3cd3f86a8cff14e50fb758 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 12:52:19 +0200 Subject: [PATCH 17/37] =?UTF-8?q?=E2=88=92#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rwx/log/__init__.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/rwx/log/__init__.py b/rwx/log/__init__.py index 4d28f82..b951ac9 100644 --- a/rwx/log/__init__.py +++ b/rwx/log/__init__.py @@ -1,22 +1,16 @@ import logging import sys - - def get_logger(name: str) -> logging.Logger: formatter = logging.Formatter( "%(name)s: %(asctime)s | %(levelname)s | %(filename)s:%(lineno)s | %(process)d >>> %(message)s", ) - - # file_handler = logging.FileHandler('log.txt') - # file_handler.setFormatter(formatter) - # file_handler.setLevel(logging.INFO) - + # out_handler = logging.StreamHandler(stream=sys.stdout) out_handler.setFormatter(formatter) out_handler.setLevel(logging.INFO) - + # logger = logging.getLogger(name) - # logger.addHandler(file_handler) logger.addHandler(out_handler) logger.setLevel(logging.INFO) + # return logger From 9349775193ac5f90364ce8287eb95748cd75fc19 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 15:23:05 +0200 Subject: [PATCH 18/37] log/stream --- rwx/log/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rwx/log/__init__.py b/rwx/log/__init__.py index b951ac9..a567492 100644 --- a/rwx/log/__init__.py +++ b/rwx/log/__init__.py @@ -1,6 +1,6 @@ import logging import sys -def get_logger(name: str) -> logging.Logger: +def get_file_logger(name: str) -> logging.Logger: formatter = logging.Formatter( "%(name)s: %(asctime)s | %(levelname)s | %(filename)s:%(lineno)s | %(process)d >>> %(message)s", ) @@ -14,3 +14,13 @@ def get_logger(name: str) -> logging.Logger: logger.setLevel(logging.INFO) # return logger +def get_stream_logger() -> logging.Logger: + out_handler = logging.StreamHandler(stream=sys.stdout) + out_handler.setLevel(logging.INFO) + # + logger = logging.getLogger() + logger.addHandler(out_handler) + logger.setLevel(logging.INFO) + # + return logger +stream = get_stream_logger() From adbdf47ef49c5963cea2c4a38fe1c26e603205b7 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 15:27:33 +0200 Subject: [PATCH 19/37] lint |None --- rwx/grub/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rwx/grub/__init__.py b/rwx/grub/__init__.py index 3a70ad4..7690a49 100644 --- a/rwx/grub/__init__.py +++ b/rwx/grub/__init__.py @@ -17,7 +17,7 @@ MODULES = { def make_image(image_format: str, image_path: str, modules: list[str], - memdisk_path: str, pubkey_path: str = None) -> None: + memdisk_path: str, pubkey_path: str | None = None) -> None: args = [ ("grub-mkimage",), ("--compress", COMPRESSION), From 88434db29aa09c7175cece250bb39d4df75e4035 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 15:31:15 +0200 Subject: [PATCH 20/37] lint fix --- rwx/__main__.py | 1 - rwx/cmd/__init__.py | 5 ++--- rwx/cmd/squashfs/__init__.py | 1 + rwx/deb/__init__.py | 1 + rwx/grub/__init__.py | 1 + rwx/log/__init__.py | 2 ++ rwx/prj/sphinx.py | 1 + 7 files changed, 8 insertions(+), 4 deletions(-) diff --git a/rwx/__main__.py b/rwx/__main__.py index 0f15b2e..a857803 100755 --- a/rwx/__main__.py +++ b/rwx/__main__.py @@ -4,7 +4,6 @@ import os import fs - if __name__ == "__main__": file_path = os.path.realpath(__file__) root_path = os.path.dirname(file_path) diff --git a/rwx/cmd/__init__.py b/rwx/cmd/__init__.py index 6ecb47c..de764fa 100644 --- a/rwx/cmd/__init__.py +++ b/rwx/cmd/__init__.py @@ -10,6 +10,5 @@ def need(command: str) -> None: package = "squashfs-tools" case _: package = None - if package: - if package not in packages: - packages.append(package) + if package and package not in packages: + packages.append(package) diff --git a/rwx/cmd/squashfs/__init__.py b/rwx/cmd/squashfs/__init__.py index 4f793ca..343461e 100644 --- a/rwx/cmd/squashfs/__init__.py +++ b/rwx/cmd/squashfs/__init__.py @@ -1,4 +1,5 @@ import ps + import rwx.cmd rwx.cmd.need("mksquashfs") diff --git a/rwx/deb/__init__.py b/rwx/deb/__init__.py index bfb8a2f..e9c6a9e 100644 --- a/rwx/deb/__init__.py +++ b/rwx/deb/__init__.py @@ -1,4 +1,5 @@ import cmd + import ps cmd.need("debootstrap") diff --git a/rwx/grub/__init__.py b/rwx/grub/__init__.py index 7690a49..57e313c 100644 --- a/rwx/grub/__init__.py +++ b/rwx/grub/__init__.py @@ -1,4 +1,5 @@ import cmd + import ps cmd.need("grub-mkimage") diff --git a/rwx/log/__init__.py b/rwx/log/__init__.py index a567492..3502ab5 100644 --- a/rwx/log/__init__.py +++ b/rwx/log/__init__.py @@ -1,5 +1,7 @@ import logging import sys + + def get_file_logger(name: str) -> logging.Logger: formatter = logging.Formatter( "%(name)s: %(asctime)s | %(levelname)s | %(filename)s:%(lineno)s | %(process)d >>> %(message)s", diff --git a/rwx/prj/sphinx.py b/rwx/prj/sphinx.py index a71bc35..ccb8d0f 100644 --- a/rwx/prj/sphinx.py +++ b/rwx/prj/sphinx.py @@ -1,4 +1,5 @@ from os import path + from sphinx.cmd.build import build_main from rwx.fs import wipe From a5ca3a60440d740a4d6b67e255c2d6c777a027c0 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 15:39:39 +0200 Subject: [PATCH 21/37] lint main --- rwx/__main__.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/rwx/__main__.py b/rwx/__main__.py index a857803..519fb8e 100755 --- a/rwx/__main__.py +++ b/rwx/__main__.py @@ -1,14 +1,11 @@ #! /usr/bin/env python3 - -import os - +from pathlib import Path import fs - if __name__ == "__main__": - file_path = os.path.realpath(__file__) - root_path = os.path.dirname(file_path) - directory_path = os.path.join(root_path, "tmp") - file_path = os.path.join(directory_path, "file") + file_path = Path(__file__).resolve() + root_path = file_path.parent + directory_path = root_path / "tmp" + file_path = directory_path / "file" fs.wipe(directory_path) fs.make_directory(directory_path) From df2537dd6dfcb50e58679e49f77a13113c664d81 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 15:43:59 +0200 Subject: [PATCH 22/37] main/imports --- rwx/__main__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rwx/__main__.py b/rwx/__main__.py index 519fb8e..ddeeba8 100755 --- a/rwx/__main__.py +++ b/rwx/__main__.py @@ -1,6 +1,8 @@ #! /usr/bin/env python3 from pathlib import Path + import fs + if __name__ == "__main__": file_path = Path(__file__).resolve() root_path = file_path.parent From d23bbdd7c91ca1ed463b95a7d597af755771dabe Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 10 Jun 2024 18:02:49 +0200 Subject: [PATCH 23/37] entry point --- rwx/__main__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rwx/__main__.py b/rwx/__main__.py index ddeeba8..f6276e4 100755 --- a/rwx/__main__.py +++ b/rwx/__main__.py @@ -1,4 +1,7 @@ #! /usr/bin/env python3 + +"""Entry point.""" + from pathlib import Path import fs From 2648c2e6ba21172942e7503f2001f15a27f17f35 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Wed, 12 Jun 2024 14:43:26 +0200 Subject: [PATCH 24/37] /.venv --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0800ae8..4909e08 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ __pycache__ /tmp +/.venv /.vscode /dist From 7d0ffb8a656260c229607d3df197344293ab3630 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Wed, 12 Jun 2024 14:45:30 +0200 Subject: [PATCH 25/37] ruff/lint --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ccd0aa1..a9f4af7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,5 +31,6 @@ requires-python = ">= 3.10" [tool.hatch.version] path = "rwx/__init__.py" -[tool.ruff] +[tool.ruff.lint] +ignore = ["COM812", "D203", "D213", "ISC001"] select = ["ALL"] From 0a035f2cd67855ccffb83bbd3ebf0a14a1cac52c Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Wed, 12 Jun 2024 14:46:34 +0200 Subject: [PATCH 26/37] ruff/format --- rwx/__init__.py | 1 + rwx/cmd/squashfs/__init__.py | 18 +++++++++++------- rwx/grub/__init__.py | 9 +++++++-- rwx/log/__init__.py | 4 ++++ rwx/prj/sphinx.py | 18 ++++++++++++------ 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/rwx/__init__.py b/rwx/__init__.py index a721b9a..a1c5ee6 100644 --- a/rwx/__init__.py +++ b/rwx/__init__.py @@ -1,2 +1,3 @@ """Read Write eXecute.""" + __version__ = "0.0.1" diff --git a/rwx/cmd/squashfs/__init__.py b/rwx/cmd/squashfs/__init__.py index 343461e..322186c 100644 --- a/rwx/cmd/squashfs/__init__.py +++ b/rwx/cmd/squashfs/__init__.py @@ -6,10 +6,14 @@ rwx.cmd.need("mksquashfs") def mksquashfs(input_root: str, output_file: str): - ps.run([ - "mksquashfs", - input_root, - output_file, - "-comp", "zstd", - "-Xcompression-level", str(18), - ]) + ps.run( + [ + "mksquashfs", + input_root, + output_file, + "-comp", + "zstd", + "-Xcompression-level", + str(18), + ] + ) diff --git a/rwx/grub/__init__.py b/rwx/grub/__init__.py index 57e313c..2b44e57 100644 --- a/rwx/grub/__init__.py +++ b/rwx/grub/__init__.py @@ -17,8 +17,13 @@ MODULES = { } -def make_image(image_format: str, image_path: str, modules: list[str], - memdisk_path: str, pubkey_path: str | None = None) -> None: +def make_image( + image_format: str, + image_path: str, + modules: list[str], + memdisk_path: str, + pubkey_path: str | None = None, +) -> None: args = [ ("grub-mkimage",), ("--compress", COMPRESSION), diff --git a/rwx/log/__init__.py b/rwx/log/__init__.py index 3502ab5..fcf01aa 100644 --- a/rwx/log/__init__.py +++ b/rwx/log/__init__.py @@ -16,6 +16,8 @@ def get_file_logger(name: str) -> logging.Logger: logger.setLevel(logging.INFO) # return logger + + def get_stream_logger() -> logging.Logger: out_handler = logging.StreamHandler(stream=sys.stdout) out_handler.setLevel(logging.INFO) @@ -25,4 +27,6 @@ def get_stream_logger() -> logging.Logger: logger.setLevel(logging.INFO) # return logger + + stream = get_stream_logger() diff --git a/rwx/prj/sphinx.py b/rwx/prj/sphinx.py index ccb8d0f..b09d8ee 100644 --- a/rwx/prj/sphinx.py +++ b/rwx/prj/sphinx.py @@ -15,12 +15,18 @@ class SphinxProject(Project): wipe(output_root) arguments: list[str] = [ "-E", - "-j", "2", - "-b", "html", - "-D", f"project={self.name}", - "-D", "master_doc={}".format("index"), - "-D", "html_theme={}".format("sphinx_rtd_theme"), - "-c", self.root, + "-j", + "2", + "-b", + "html", + "-D", + f"project={self.name}", + "-D", + "master_doc={}".format("index"), + "-D", + "html_theme={}".format("sphinx_rtd_theme"), + "-c", + self.root, # "-C", path.join(self.root, self.name), path.join(output_root, self.name), From 73dc9598b78436df12ff069da1063a285be412d4 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Wed, 12 Jun 2024 14:48:37 +0200 Subject: [PATCH 27/37] useless --- rwx/grub/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rwx/grub/__init__.py b/rwx/grub/__init__.py index 2b44e57..cd016ab 100644 --- a/rwx/grub/__init__.py +++ b/rwx/grub/__init__.py @@ -34,6 +34,6 @@ def make_image( if pubkey_path: args.append(("--pubkey", pubkey_path)) args.extend(modules) - if modules := MODULES.get(image_format, None): + if modules := MODULES.get(image_format): args.extend(modules) ps.run(*args) From 959107c245f3ede7ea0f728d7c6af6ae028cecaf Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Wed, 12 Jun 2024 14:52:55 +0200 Subject: [PATCH 28/37] run/check --- 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 5b50456..6471fff 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -14,7 +14,7 @@ def get_tuples_args(tuples) -> list[str]: def run(*tuples) -> subprocess.CompletedProcess: - return subprocess.run(get_tuples_args(tuples), capture_output=False) + return subprocess.run(get_tuples_args(tuples), capture_output=False, check=True) def run_line(*tuples, charset: str = txt.CHARSET) -> str: @@ -23,6 +23,6 @@ def run_line(*tuples, charset: str = txt.CHARSET) -> str: def run_lines(*tuples, charset: str = txt.CHARSET) -> list[str]: - process = subprocess.run(get_tuples_args(tuples), capture_output=True) + process = subprocess.run(get_tuples_args(tuples), capture_output=True, check=True) string = process.stdout.decode(charset) return string.rstrip().splitlines() From 4414a9a7120c1a9c4a5af211c082b181c65696b6 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Wed, 12 Jun 2024 14:54:59 +0200 Subject: [PATCH 29/37] ruff/line-length --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index a9f4af7..66a3933 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,9 @@ requires-python = ">= 3.10" [tool.hatch.version] path = "rwx/__init__.py" +[tool.ruff] +line-length = 80 + [tool.ruff.lint] ignore = ["COM812", "D203", "D213", "ISC001"] select = ["ALL"] From 3ce03d17c14161fb04c53fb0cae89b256db8debc Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Wed, 12 Jun 2024 14:55:37 +0200 Subject: [PATCH 30/37] fix --- rwx/ps/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index 6471fff..b66c21b 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -14,7 +14,9 @@ def get_tuples_args(tuples) -> list[str]: def run(*tuples) -> subprocess.CompletedProcess: - return subprocess.run(get_tuples_args(tuples), capture_output=False, check=True) + return subprocess.run( + get_tuples_args(tuples), capture_output=False, check=True + ) def run_line(*tuples, charset: str = txt.CHARSET) -> str: @@ -23,6 +25,8 @@ def run_line(*tuples, charset: str = txt.CHARSET) -> str: def run_lines(*tuples, charset: str = txt.CHARSET) -> list[str]: - process = subprocess.run(get_tuples_args(tuples), capture_output=True, check=True) + process = subprocess.run( + get_tuples_args(tuples), capture_output=True, check=True + ) string = process.stdout.decode(charset) return string.rstrip().splitlines() From 282e2ac7a1490bcdf748d6c66580c555f584bc0b Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 13 Jun 2024 10:16:53 +0200 Subject: [PATCH 31/37] log/level --- rwx/log/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rwx/log/__init__.py b/rwx/log/__init__.py index fcf01aa..50048e5 100644 --- a/rwx/log/__init__.py +++ b/rwx/log/__init__.py @@ -18,15 +18,15 @@ def get_file_logger(name: str) -> logging.Logger: return logger -def get_stream_logger() -> logging.Logger: +def get_stream_logger(level: int) -> logging.Logger: out_handler = logging.StreamHandler(stream=sys.stdout) - out_handler.setLevel(logging.INFO) + out_handler.setLevel(level) # logger = logging.getLogger() logger.addHandler(out_handler) - logger.setLevel(logging.INFO) + logger.setLevel(level) # return logger -stream = get_stream_logger() +stream = get_stream_logger(logging.INFO) From 519613eeeb0d2715f41165a2c6d74c125e5f4856 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Wed, 17 Jul 2024 19:10:36 +0200 Subject: [PATCH 32/37] sphinx/web --- rwx/prj/sphinx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rwx/prj/sphinx.py b/rwx/prj/sphinx.py index b09d8ee..3cef334 100644 --- a/rwx/prj/sphinx.py +++ b/rwx/prj/sphinx.py @@ -29,6 +29,6 @@ class SphinxProject(Project): self.root, # "-C", path.join(self.root, self.name), - path.join(output_root, self.name), + path.join(output_root, "web"), ] build_main(arguments) From 5361fbd9a06f6d97e880893a39dee8f6af20ea27 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 20 Aug 2024 14:14:03 +0200 Subject: [PATCH 33/37] 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 34/37] 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 35/37] 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 36/37] 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 37/37] 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