From 331f39e157f3c8ed97af144b9b9497beec71dc1f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 17 Oct 2023 10:01:56 +0200 Subject: [PATCH] =?UTF-8?q?main=20=E2=86=92=20init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + __init__.py | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++ __main__.py | 121 +++-------------------------------------------- doc.py | 18 +++---- esp.py | 7 +++ 5 files changed, 153 insertions(+), 127 deletions(-) create mode 100644 .gitignore create mode 100644 __init__.py mode change 100644 => 100755 __main__.py create mode 100644 esp.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cd165df --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__ +/.idea diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..69ed6b8 --- /dev/null +++ b/__init__.py @@ -0,0 +1,132 @@ +import os +import subprocess +import sys + +sys.path.append(os.path.dirname(os.path.dirname(__file__))) +import lsgm +import rwx.arg +import rwx.fs +import rwx.grub +import rwx.ps + +CHARSET = 'UTF-8' + +PGP = 'git@marc.beninca.link' + +MODULES = ( + ('regexp'), + ('memdisk', 'tar'), + ('search'), + ('part_gpt', 'part_msdos'), + ('btrfs', 'ext2', 'fat', 'iso9660', 'udf'), + ('exfat', 'hfs', 'hfspluscomp', 'ntfscomp'), + ('linux', 'loopback', 'squash4'), +# + ('at_keyboard', 'keylayouts', 'keystatus', 'read'), + ('halt', 'reboot'), + ('all_video', 'videoinfo'), + ('gfxterm_background', 'jpeg', 'png', 'tga'), +# + ('date', 'echo', 'eval', 'help', 'sleep', 'test', 'true'), + ('cpuid', 'lspci'), + ('cat', 'configfile', 'loadenv', 'progress', 'testspeed'), + ('hashsum', 'gcry_sha512', 'gcry_sha256'), + ('pgp', 'gcry_dsa', 'gcry_rsa'), +) + + +def build(esp_root: str, data_uuid: str=None) -> None: + esp_uuid = rwx.fs.get_path_uuid(esp_root) + # + memdisk_root = os.path.join(esp_root, 'memdisk') + efi_root = os.path.join(esp_root, 'efi') + efi_directory = os.path.join(efi_root, 'boot') + bios_root = os.path.join(esp_root, 'bios') + grub_root = os.path.join(esp_root, 'grub') + grub_env = os.path.join(esp_root, 'grub.env') + # + print(f''' +esp_root: {esp_root} +data_uuid: {data_uuid} +↓ +esp_uuid: {esp_uuid} +↓ +memdisk_root: {memdisk_root} +efi_root: {efi_root} +efi_directory: {efi_directory} +bios_root: {bios_root} +grub_root: {grub_root} +grub_env: {grub_env} +''', end=str()) + # + memdisk_directory = os.path.join(memdisk_root, 'boot', 'grub') + memdisk_file = os.path.join(memdisk_directory, 'grub.cfg') + memdisk_archive = os.path.join(memdisk_root, 'boot.tar') + # + print(f''' +memdisk_directory: {memdisk_directory} +memdisk_file: {memdisk_file} +memdisk_archive: {memdisk_archive} +''', end=str()) + # + rwx.fs.wipe(memdisk_root) + rwx.fs.make_directory(memdisk_directory) + rwx.fs.empty_file(memdisk_file) + # EFI + rwx.fs.wipe(efi_root) + rwx.fs.make_directory(efi_directory) + # BIOS + rwx.fs.wipe(bios_root) + rwx.fs.make_directory(bios_root) + # + rwx.fs.wipe(memdisk_root) + # GRUB + rwx.fs.wipe(grub_root) + # GRUB / environment + rwx.fs.write(grub_env, + rwx.grub.ENV_HEADER.ljust(rwx.grub.ENV_BYTES, rwx.grub.ENV_COMMENT)) + + +def __main__(): + esp() + + +def main(main_file: str) -> None: + function, _ = os.path.splitext(os.path.basename(main_file)) + getattr(lsgm, function)() + + +def doc(): + root = os.path.dirname(__file__) + file = os.path.join(root, 'todo') + subprocess.run([ + 'dot', + f'{file}.gv', + '-T', 'svg', + '-o', f'{file}.svg', + ]) + + +def esp(): + command, args = rwx.arg.split() + if args: + data, *args = args + else: + data = None + project_file = os.path.realpath(__file__) + project_root = os.path.dirname(project_file) + parent_root, project_name = os.path.split(project_root) + # + print(f''' +command: {command} +data: {data} +args: {args} +↓ +project_file: {project_file} +project_root: {project_root} +parent_root: {parent_root} +project_name: {project_name} +''', end=str()) + # + if project_name: + build(parent_root, data_uuid=data) diff --git a/__main__.py b/__main__.py old mode 100644 new mode 100755 index 8efc5be..ee6c888 --- a/__main__.py +++ b/__main__.py @@ -1,116 +1,7 @@ -#! /usr/bin/env python3 - -import os -import subprocess -import sys - -import rwx.arg -import rwx.fs -import rwx.grub -import rwx.ps - -CHARSET = 'UTF-8' - -PGP = 'git@marc.beninca.link' - -MODULES = ( - ('regexp'), - ('memdisk', 'tar'), - ('search'), - ('part_gpt', 'part_msdos'), - ('btrfs', 'ext2', 'fat', 'iso9660', 'udf'), - ('exfat', 'hfs', 'hfspluscomp', 'ntfscomp'), - ('linux', 'loopback', 'squash4'), -# - ('at_keyboard', 'keylayouts', 'keystatus', 'read'), - ('halt', 'reboot'), - ('all_video', 'videoinfo'), - ('gfxterm_background', 'jpeg', 'png', 'tga'), -# - ('date', 'echo', 'eval', 'help', 'sleep', 'test', 'true'), - ('cpuid', 'lspci'), - ('cat', 'configfile', 'loadenv', 'progress', 'testspeed'), - ('hashsum', 'gcry_sha512', 'gcry_sha256'), - ('pgp', 'gcry_dsa', 'gcry_rsa'), -) - - -def build(esp_root: str, data_uuid: str=None) -> None: - esp_uuid = rwx.fs.get_path_uuid(esp_root) - # - memdisk_root = os.path.join(esp_root, 'memdisk') - efi_root = os.path.join(esp_root, 'efi') - efi_directory = os.path.join(efi_root, 'boot') - bios_root = os.path.join(esp_root, 'bios') - grub_root = os.path.join(esp_root, 'grub') - grub_env = os.path.join(esp_root, 'grub.env') - # - print(f''' -esp_root: {esp_root} -data_uuid: {data_uuid} -↓ -esp_uuid: {esp_uuid} -↓ -memdisk_root: {memdisk_root} -efi_root: {efi_root} -efi_directory: {efi_directory} -bios_root: {bios_root} -grub_root: {grub_root} -grub_env: {grub_env} -''', end=str()) - # - memdisk_directory = os.path.join(memdisk_root, 'boot', 'grub') - memdisk_file = os.path.join(memdisk_directory, 'grub.cfg') - memdisk_archive = os.path.join(memdisk_root, 'boot.tar') - # - print(f''' -memdisk_directory: {memdisk_directory} -memdisk_file: {memdisk_file} -memdisk_archive: {memdisk_archive} -''', end=str()) - # - rwx.fs.wipe(memdisk_root) - rwx.fs.make_directory(memdisk_directory) - rwx.fs.empty_file(memdisk_file) - # EFI - rwx.fs.wipe(efi_root) - rwx.fs.make_directory(efi_directory) - # BIOS - rwx.fs.wipe(bios_root) - rwx.fs.make_directory(bios_root) - # - rwx.fs.wipe(memdisk_root) - # GRUB - rwx.fs.wipe(grub_root) - # GRUB / environment - rwx.fs.write(grub_env, - rwx.grub.ENV_HEADER.ljust(rwx.grub.ENV_BYTES, rwx.grub.ENV_COMMENT)) - - -def main() -> None: - command, args = rwx.arg.split() - if args: - data, *args = args - else: - data = None - project_file = os.path.realpath(__file__) - project_root = os.path.dirname(project_file) - parent_root, project_name = os.path.split(project_root) - # - print(f''' -command: {command} -data: {data} -args: {args} -↓ -project_file: {project_file} -project_root: {project_root} -parent_root: {parent_root} -project_name: {project_name} -''', end=str()) - # - if project_name: - build(parent_root, data_uuid=data) - - if __name__ == '__main__': - main() + import os + import sys + sys.path.append(os.path.dirname(os.path.dirname(__file__))) + # + import lsgm + lsgm.main(__file__) diff --git a/doc.py b/doc.py index 1aadd6c..ee6c888 100644 --- a/doc.py +++ b/doc.py @@ -1,13 +1,7 @@ -import os -import subprocess - - if __name__ == '__main__': - root = os.path.dirname(__file__) - file = os.path.join(root, 'todo') - subprocess.run([ - 'dot', - f'{file}.gv', - '-T', 'svg', - '-o', f'{file}.svg', - ]) + import os + import sys + sys.path.append(os.path.dirname(os.path.dirname(__file__))) + # + import lsgm + lsgm.main(__file__) diff --git a/esp.py b/esp.py new file mode 100644 index 0000000..ee6c888 --- /dev/null +++ b/esp.py @@ -0,0 +1,7 @@ +if __name__ == '__main__': + import os + import sys + sys.path.append(os.path.dirname(os.path.dirname(__file__))) + # + import lsgm + lsgm.main(__file__)