chroot.cmd_chroot(): call image.cmd_inspect() for type='rootfs' and clean up

This commit is contained in:
InsanePrawn 2022-09-04 06:45:35 +02:00
parent 1d0a97560b
commit ad966d6616

View file

@ -8,36 +8,42 @@ from wrapper import enforce_wrap
from .abstract import Chroot from .abstract import Chroot
from .base import get_base_chroot from .base import get_base_chroot
from .build import get_build_chroot, BuildChroot from .build import get_build_chroot, BuildChroot
from .helpers import get_chroot_path
# export Chroot class # export Chroot class
Chroot = Chroot Chroot = Chroot
CHROOT_TYPES = ['base', 'build', 'rootfs']
@click.command('chroot') @click.command('chroot')
@click.argument('type', required=False, default='build') @click.argument('type', required=False, type=click.Choice(CHROOT_TYPES), default='build')
@click.argument('arch', required=False, default=None) @click.argument(
def cmd_chroot(type: str = 'build', arch: str = None, enable_crossdirect=True): 'name',
"""Open a shell in a chroot""" required=False,
chroot_path = '' default=None,
if type not in ['base', 'build', 'rootfs']: )
raise Exception('Unknown chroot type: ' + type) @click.pass_context
def cmd_chroot(ctx: click.Context, type: str = 'build', name: str = None, enable_crossdirect=True):
"""Open a shell in a chroot. For rootfs NAME is a profile name, for others the architecture (e.g. aarch64)."""
if type not in CHROOT_TYPES:
raise Exception(f'Unknown chroot type: "{type}"')
if type == 'rootfs':
from image import cmd_inspect
assert isinstance(cmd_inspect, click.Command)
ctx.invoke(cmd_inspect, profile=name, shell=True)
return
enforce_wrap() enforce_wrap()
chroot: Chroot chroot: Chroot
if type == 'rootfs': arch = name
if arch:
name = 'rootfs_' + arch
else:
raise Exception('"rootfs" without args not yet implemented, sorry!')
# TODO: name = config.get_profile()[...]
chroot_path = get_chroot_path(name)
if not os.path.exists(chroot_path):
raise Exception(f"rootfs {name} doesn't exist")
else:
if not arch: if not arch:
# TODO: arch = config.get_profile()[...] # TODO: importing packages.device.get_profile_device() causes import loop:
arch = 'aarch64' # arch = get_profile_device().arch
arch = config.runtime.arch
assert arch
if type == 'base': if type == 'base':
chroot = get_base_chroot(arch) chroot = get_base_chroot(arch)
if not os.path.exists(chroot.get_path('/bin')): if not os.path.exists(chroot.get_path('/bin')):