Compare commits
21 commits
5776c49059
...
a5ca3a6044
Author | SHA1 | Date | |
---|---|---|---|
a5ca3a6044 | |||
88434db29a | |||
adbdf47ef4 | |||
9349775193 | |||
aad5c140dd | |||
c702283696 | |||
b44b6bd4d4 | |||
fc3e191dc1 | |||
e84417c077 | |||
517da87ffb | |||
bf5a8a65d7 | |||
67b8d4c981 | |||
470d7aa1e9 | |||
592023d214 | |||
c7db231dc2 | |||
a4f49d6ac0 | |||
fdbd850d23 | |||
b197a15689 | |||
5666177582 | |||
4ab0a575b7 | |||
b969aa886e |
14 changed files with 98 additions and 88 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,4 +1,4 @@
|
||||||
__pycache__
|
__pycache__
|
||||||
/tmp
|
/tmp
|
||||||
/.idea
|
/.vscode
|
||||||
/dist
|
/dist
|
||||||
|
|
|
@ -1,32 +1,35 @@
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ['hatchling']
|
requires = ["hatchling"]
|
||||||
build-backend = 'hatchling.build'
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
authors = [
|
authors = [
|
||||||
{ name = 'Marc Beninca', email = 'git@marc.beninca.link' },
|
{ name = "Marc Beninca", email = "git@marc.beninca.link" },
|
||||||
]
|
]
|
||||||
maintainers = [
|
maintainers = [
|
||||||
{ name = 'Marc Beninca', email = 'git@marc.beninca.link' },
|
{ name = "Marc Beninca", email = "git@marc.beninca.link" },
|
||||||
]
|
]
|
||||||
classifiers = [
|
classifiers = [
|
||||||
'Programming Language :: Python :: 3',
|
"Programming Language :: Python :: 3",
|
||||||
'License :: OSI Approved :: GNU Affero General Public License v3',
|
"License :: OSI Approved :: GNU Affero General Public License v3",
|
||||||
'Operating System :: OS Independent',
|
"Operating System :: OS Independent",
|
||||||
]
|
]
|
||||||
dependencies = []
|
dependencies = []
|
||||||
description = 'Read Write eXecute'
|
description = "Read Write eXecute"
|
||||||
dynamic = ['version']
|
dynamic = ["version"]
|
||||||
keywords = []
|
keywords = []
|
||||||
license-files = { paths = ['license.md'] }
|
license-files = { paths = ["license.md"] }
|
||||||
name = 'rwx'
|
name = "rwx"
|
||||||
readme = 'readme.md'
|
readme = "readme.md"
|
||||||
requires-python = '>= 3.10'
|
requires-python = ">= 3.10"
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
# command = 'package.module:function'
|
# command = "package.module:function"
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
|
|
||||||
[tool.hatch.version]
|
[tool.hatch.version]
|
||||||
path = 'rwx/__init__.py'
|
path = "rwx/__init__.py"
|
||||||
|
|
||||||
|
[tool.ruff]
|
||||||
|
select = ["ALL"]
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
__version__ = '0.0.1'
|
"""Read Write eXecute."""
|
||||||
|
__version__ = "0.0.1"
|
||||||
|
|
|
@ -1,18 +1,14 @@
|
||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
|
from pathlib import Path
|
||||||
import os
|
|
||||||
|
|
||||||
import fs
|
import fs
|
||||||
|
if __name__ == "__main__":
|
||||||
|
file_path = Path(__file__).resolve()
|
||||||
if __name__ == '__main__':
|
root_path = file_path.parent
|
||||||
file_path = os.path.realpath(__file__)
|
directory_path = root_path / "tmp"
|
||||||
root_path = os.path.dirname(file_path)
|
file_path = directory_path / "file"
|
||||||
directory_path = os.path.join(root_path, 'tmp')
|
|
||||||
file_path = os.path.join(directory_path, 'file')
|
|
||||||
|
|
||||||
fs.wipe(directory_path)
|
fs.wipe(directory_path)
|
||||||
fs.make_directory(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.empty_file(file_path)
|
||||||
fs.write(file_path, 'Martine écrit moins.')
|
fs.write(file_path, "Martine écrit moins.")
|
||||||
|
|
|
@ -4,12 +4,11 @@ packages: list[str] = []
|
||||||
|
|
||||||
def need(command: str) -> None:
|
def need(command: str) -> None:
|
||||||
match command:
|
match command:
|
||||||
case 'debootstrap':
|
case "debootstrap":
|
||||||
package = 'debootstrap'
|
package = "debootstrap"
|
||||||
case 'mksquashfs' | 'unsquashfs':
|
case "mksquashfs" | "unsquashfs":
|
||||||
package = 'squashfs-tools'
|
package = "squashfs-tools"
|
||||||
case _:
|
case _:
|
||||||
package = None
|
package = None
|
||||||
if package:
|
if package and package not in packages:
|
||||||
if package not in packages:
|
packages.append(package)
|
||||||
packages.append(package)
|
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
import ps
|
import ps
|
||||||
|
|
||||||
import rwx.cmd
|
import rwx.cmd
|
||||||
|
|
||||||
rwx.cmd.need('mksquashfs')
|
rwx.cmd.need("mksquashfs")
|
||||||
|
|
||||||
|
|
||||||
def mksquashfs(input_root: str, output_file: str):
|
def mksquashfs(input_root: str, output_file: str):
|
||||||
ps.run([
|
ps.run([
|
||||||
'mksquashfs',
|
"mksquashfs",
|
||||||
input_root,
|
input_root,
|
||||||
output_file,
|
output_file,
|
||||||
'-comp', 'zstd',
|
"-comp", "zstd",
|
||||||
'-Xcompression-level', str(18),
|
"-Xcompression-level", str(18),
|
||||||
])
|
])
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
import cmd
|
import cmd
|
||||||
|
|
||||||
import ps
|
import ps
|
||||||
|
|
||||||
cmd.need('debootstrap')
|
cmd.need("debootstrap")
|
||||||
|
|
||||||
BOOTSTRAP_ARCHITECTURE = 'amd64'
|
BOOTSTRAP_ARCHITECTURE = "amd64"
|
||||||
BOOTSTRAP_VARIANT = 'minbase'
|
BOOTSTRAP_VARIANT = "minbase"
|
||||||
|
|
||||||
|
|
||||||
def bootstrap(root_path: str, suite: str, mirror_location: str):
|
def bootstrap(root_path: str, suite: str, mirror_location: str):
|
||||||
command = [
|
command = [
|
||||||
('debootstrap',),
|
("debootstrap",),
|
||||||
('--arch', BOOTSTRAP_ARCHITECTURE),
|
("--arch", BOOTSTRAP_ARCHITECTURE),
|
||||||
('--variant', BOOTSTRAP_VARIANT),
|
("--variant", BOOTSTRAP_VARIANT),
|
||||||
(suite,),
|
(suite,),
|
||||||
(root_path,),
|
(root_path,),
|
||||||
(mirror_location,),
|
(mirror_location,),
|
||||||
]
|
]
|
||||||
completed_process = ps.run(command)
|
return ps.run(command)
|
||||||
return completed_process
|
|
||||||
|
|
2
rwx/err/__init__.py
Normal file
2
rwx/err/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
class Exception(Exception):
|
||||||
|
pass
|
|
@ -3,34 +3,34 @@ import shutil
|
||||||
|
|
||||||
from rwx import ps
|
from rwx import ps
|
||||||
|
|
||||||
CHARSET = 'UTF-8'
|
CHARSET = "UTF-8"
|
||||||
|
|
||||||
|
|
||||||
def create_image(file_path: str, size_bytes: int):
|
def create_image(file_path: str, size_bytes: int):
|
||||||
ps.run(
|
ps.run(
|
||||||
('qemu-img', 'create'),
|
("qemu-img", "create"),
|
||||||
('-f', 'qcow2'),
|
("-f", "qcow2"),
|
||||||
(file_path, size_bytes),
|
(file_path, size_bytes),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def empty_file(path: str):
|
def empty_file(path: str):
|
||||||
write(path, str())
|
write(path, "")
|
||||||
|
|
||||||
|
|
||||||
def get_mount_uuid(path: str):
|
def get_mount_uuid(path: str):
|
||||||
return ps.run_line(
|
return ps.run_line(
|
||||||
('findmnt',),
|
("findmnt",),
|
||||||
('--noheadings',),
|
("--noheadings",),
|
||||||
('--output', 'UUID'),
|
("--output", "UUID"),
|
||||||
(path,),
|
(path,),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_path_mount(path: str):
|
def get_path_mount(path: str):
|
||||||
return ps.run_line(
|
return ps.run_line(
|
||||||
('stat',),
|
("stat",),
|
||||||
('--format', '%m'),
|
("--format", "%m"),
|
||||||
(path,),
|
(path,),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ def make_directory(path: str):
|
||||||
|
|
||||||
|
|
||||||
def read_file(file_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()
|
return file_object.read()
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,5 +66,5 @@ def wipe(path: str):
|
||||||
|
|
||||||
|
|
||||||
def write(file_path: str, text: str, charset=CHARSET):
|
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))
|
file_object.write(text.encode(charset))
|
||||||
|
|
|
@ -1,32 +1,33 @@
|
||||||
import cmd
|
import cmd
|
||||||
|
|
||||||
import ps
|
import ps
|
||||||
|
|
||||||
cmd.need('grub-mkimage')
|
cmd.need("grub-mkimage")
|
||||||
|
|
||||||
COMPRESSION = 'xz'
|
COMPRESSION = "xz"
|
||||||
ENV_BYTES = 1024
|
ENV_BYTES = 1024
|
||||||
ENV_COMMENT = '#'
|
ENV_COMMENT = "#"
|
||||||
ENV_HEADER = f'''{ENV_COMMENT} GRUB Environment Block
|
ENV_HEADER = f"""{ENV_COMMENT} GRUB Environment Block
|
||||||
'''
|
"""
|
||||||
MODULES = {
|
MODULES = {
|
||||||
'i386-pc': [
|
"i386-pc": [
|
||||||
('biosdisk',),
|
("biosdisk",),
|
||||||
('ntldr',),
|
("ntldr",),
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def make_image(image_format: str, image_path: str, modules: list[str],
|
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 = [
|
args = [
|
||||||
('grub-mkimage',),
|
("grub-mkimage",),
|
||||||
('--compress', COMPRESSION),
|
("--compress", COMPRESSION),
|
||||||
('--format', image_format),
|
("--format", image_format),
|
||||||
('--output', image_path),
|
("--output", image_path),
|
||||||
('--memdisk', memdisk_path),
|
("--memdisk", memdisk_path),
|
||||||
]
|
]
|
||||||
if pubkey_path:
|
if pubkey_path:
|
||||||
args.append(('--pubkey', pubkey_path))
|
args.append(("--pubkey", pubkey_path))
|
||||||
args.extend(modules)
|
args.extend(modules)
|
||||||
if modules := MODULES.get(image_format, None):
|
if modules := MODULES.get(image_format, None):
|
||||||
args.extend(modules)
|
args.extend(modules)
|
||||||
|
|
|
@ -2,21 +2,27 @@ import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def get_logger(name: str) -> logging.Logger:
|
def get_file_logger(name: str) -> logging.Logger:
|
||||||
formatter = logging.Formatter(
|
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')
|
|
||||||
# file_handler.setFormatter(formatter)
|
|
||||||
# file_handler.setLevel(logging.INFO)
|
|
||||||
|
|
||||||
out_handler = logging.StreamHandler(stream=sys.stdout)
|
out_handler = logging.StreamHandler(stream=sys.stdout)
|
||||||
out_handler.setFormatter(formatter)
|
out_handler.setFormatter(formatter)
|
||||||
out_handler.setLevel(logging.INFO)
|
out_handler.setLevel(logging.INFO)
|
||||||
|
#
|
||||||
logger = logging.getLogger(name)
|
logger = logging.getLogger(name)
|
||||||
# logger.addHandler(file_handler)
|
|
||||||
logger.addHandler(out_handler)
|
logger.addHandler(out_handler)
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
|
#
|
||||||
return logger
|
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()
|
||||||
|
|
|
@ -2,7 +2,7 @@ from os import path
|
||||||
|
|
||||||
|
|
||||||
class Project:
|
class Project:
|
||||||
def __init__(self, file_path: str):
|
def __init__(self, file_path: str) -> None:
|
||||||
self.file: str = path.realpath(file_path)
|
self.file: str = path.realpath(file_path)
|
||||||
self.root: str = path.dirname(self.file)
|
self.root: str = path.dirname(self.file)
|
||||||
self.name: str = path.basename(self.root)
|
self.name: str = path.basename(self.root)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
from sphinx.cmd.build import build_main
|
from sphinx.cmd.build import build_main
|
||||||
|
|
||||||
from rwx.fs import wipe
|
from rwx.fs import wipe
|
||||||
|
@ -6,11 +7,11 @@ from rwx.prj import Project
|
||||||
|
|
||||||
|
|
||||||
class SphinxProject(Project):
|
class SphinxProject(Project):
|
||||||
def __init__(self, file_path: str):
|
def __init__(self, file_path: str) -> None:
|
||||||
super().__init__(file_path)
|
super().__init__(file_path)
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
output_root: str = path.join(self.root, 'out')
|
output_root: str = path.join(self.root, "out")
|
||||||
wipe(output_root)
|
wipe(output_root)
|
||||||
arguments: list[str] = [
|
arguments: list[str] = [
|
||||||
"-E",
|
"-E",
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
CHARSET = 'UTF-8'
|
CHARSET = "UTF-8"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue