binfmt: move to own module, add cmd_register(), cmd_unregister() to cli

This commit is contained in:
InsanePrawn 2022-12-22 02:14:56 +01:00 committed by Prawn
parent 46507f8dbe
commit c86ce577d1
6 changed files with 25 additions and 1 deletions

0
binfmt/__init__.py Normal file
View file

21
binfmt/cli.py Normal file
View file

@ -0,0 +1,21 @@
import click
from constants import Arch, ARCHES
from .binfmt import binfmt_unregister
cmd_binfmt = click.Group('binfmt', help='Manage qemu binfmt for executing foreign architecture binaries')
arch_arg = click.argument('arch', type=click.Choice(ARCHES))
@cmd_binfmt.command('register', help='Register a binfmt handler with the kernel')
@arch_arg
def cmd_register(arch: Arch, disable_chroot: bool = False):
from packages.build import build_enable_qemu_binfmt
build_enable_qemu_binfmt(arch)
@cmd_binfmt.command('unregister', help='Unregister a binfmt handler from the kernel')
@arch_arg
def cmd_unregister(arch: Arch):
binfmt_unregister(arch)

View file

@ -11,6 +11,7 @@ only used to trigger builds of the submodule docs!
:template: command.rst
:recursive:
binfmt
cache
chroot
config

View file

@ -11,6 +11,7 @@ from logger import color_option, logging, quiet_option, setup_logging, verbose_o
from wrapper import get_wrapper_type, enforce_wrap, nowrapper_option
from progressbar import progress_bars_option
from binfmt.cli import cmd_binfmt
from config.cli import config, config_option, cmd_config
from packages.cli import cmd_packages
from flavours.cli import cmd_flavours
@ -77,6 +78,7 @@ def main():
exit(1)
cli.add_command(cmd_binfmt)
cli.add_command(cmd_cache)
cli.add_command(cmd_chroot)
cli.add_command(cmd_config)

View file

@ -9,7 +9,7 @@ from copy import deepcopy
from urllib.error import HTTPError
from typing import Iterable, Iterator, Optional
from binfmt import register as binfmt_register
from binfmt.binfmt import binfmt_register
from constants import CROSSDIRECT_PKGS, QEMU_BINFMT_PKGS, GCC_HOSTSPECS, ARCHES, Arch, CHROOT_PATHS, MAKEPKG_CMD
from config.state import config
from exec.cmd import run_cmd, run_root_cmd