chroot.cmd_chroot(): call image.cmd_inspect() for type='rootfs' and clean up
This commit is contained in:
parent
1d0a97560b
commit
ad966d6616
1 changed files with 44 additions and 38 deletions
|
@ -8,54 +8,60 @@ 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:
|
if not arch:
|
||||||
name = 'rootfs_' + arch
|
# TODO: importing packages.device.get_profile_device() causes import loop:
|
||||||
else:
|
# arch = get_profile_device().arch
|
||||||
raise Exception('"rootfs" without args not yet implemented, sorry!')
|
arch = config.runtime.arch
|
||||||
# TODO: name = config.get_profile()[...]
|
assert arch
|
||||||
chroot_path = get_chroot_path(name)
|
if type == 'base':
|
||||||
if not os.path.exists(chroot_path):
|
chroot = get_base_chroot(arch)
|
||||||
raise Exception(f"rootfs {name} doesn't exist")
|
if not os.path.exists(chroot.get_path('/bin')):
|
||||||
|
chroot.initialize()
|
||||||
|
chroot.initialized = True
|
||||||
|
elif type == 'build':
|
||||||
|
build_chroot: BuildChroot = get_build_chroot(arch, activate=True)
|
||||||
|
chroot = build_chroot # type safety
|
||||||
|
if not os.path.exists(build_chroot.get_path('/bin')):
|
||||||
|
build_chroot.initialize()
|
||||||
|
build_chroot.initialized = True
|
||||||
|
build_chroot.mount_pkgbuilds()
|
||||||
|
build_chroot.mount_chroots()
|
||||||
|
assert arch and config.runtime.arch
|
||||||
|
if config.file.build.crossdirect and enable_crossdirect and arch != config.runtime.arch:
|
||||||
|
build_chroot.mount_crossdirect()
|
||||||
else:
|
else:
|
||||||
if not arch:
|
raise Exception('Really weird bug')
|
||||||
# TODO: arch = config.get_profile()[...]
|
|
||||||
arch = 'aarch64'
|
|
||||||
if type == 'base':
|
|
||||||
chroot = get_base_chroot(arch)
|
|
||||||
if not os.path.exists(chroot.get_path('/bin')):
|
|
||||||
chroot.initialize()
|
|
||||||
chroot.initialized = True
|
|
||||||
elif type == 'build':
|
|
||||||
build_chroot: BuildChroot = get_build_chroot(arch, activate=True)
|
|
||||||
chroot = build_chroot # type safety
|
|
||||||
if not os.path.exists(build_chroot.get_path('/bin')):
|
|
||||||
build_chroot.initialize()
|
|
||||||
build_chroot.initialized = True
|
|
||||||
build_chroot.mount_pkgbuilds()
|
|
||||||
build_chroot.mount_chroots()
|
|
||||||
assert arch and config.runtime.arch
|
|
||||||
if config.file.build.crossdirect and enable_crossdirect and arch != config.runtime.arch:
|
|
||||||
build_chroot.mount_crossdirect()
|
|
||||||
else:
|
|
||||||
raise Exception('Really weird bug')
|
|
||||||
|
|
||||||
chroot.mount_packages()
|
chroot.mount_packages()
|
||||||
chroot.activate()
|
chroot.activate()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue