chroot/: fix class vars vs instance vars
looking at you, Chroot.active_mounts = []
This commit is contained in:
parent
179434729b
commit
9ff6f24489
5 changed files with 38 additions and 25 deletions
|
@ -22,8 +22,8 @@ class AbstractChroot(Protocol):
|
||||||
copy_base: bool
|
copy_base: bool
|
||||||
initialized: bool = False
|
initialized: bool = False
|
||||||
active: bool = False
|
active: bool = False
|
||||||
active_mounts: list[str] = []
|
active_mounts: list[str]
|
||||||
extra_repos: Mapping[str, RepoInfo] = {}
|
extra_repos: Mapping[str, RepoInfo]
|
||||||
base_packages: list[str] = ['base']
|
base_packages: list[str] = ['base']
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -91,12 +91,13 @@ class Chroot(AbstractChroot):
|
||||||
if copy_base is None:
|
if copy_base is None:
|
||||||
logging.debug(f'{name}: copy_base is none!')
|
logging.debug(f'{name}: copy_base is none!')
|
||||||
copy_base = (name == base_chroot_name(arch))
|
copy_base = (name == base_chroot_name(arch))
|
||||||
|
self.active_mounts = list[str]()
|
||||||
self.name = name
|
self.name = name
|
||||||
self.arch = arch
|
self.arch = arch
|
||||||
self.path = path_override or os.path.join(config.get_path('chroots'), name)
|
self.path = path_override or os.path.join(config.get_path('chroots'), name)
|
||||||
self.copy_base = copy_base
|
self.copy_base = copy_base
|
||||||
self.extra_repos = deepcopy(extra_repos)
|
self.extra_repos = deepcopy(extra_repos)
|
||||||
self.base_packages = base_packages
|
self.base_packages = base_packages.copy()
|
||||||
if initialize:
|
if initialize:
|
||||||
self.initialize()
|
self.initialize()
|
||||||
if self.name.startswith(BASE_CHROOT_PREFIX) and set(get_kupfer_local(self.arch).repos).intersection(set(self.extra_repos)):
|
if self.name.startswith(BASE_CHROOT_PREFIX) and set(get_kupfer_local(self.arch).repos).intersection(set(self.extra_repos)):
|
||||||
|
@ -341,6 +342,7 @@ def get_chroot(
|
||||||
initialize: bool = False,
|
initialize: bool = False,
|
||||||
activate: bool = False,
|
activate: bool = False,
|
||||||
fail_if_exists: bool = False,
|
fail_if_exists: bool = False,
|
||||||
|
extra_repos: Optional[Mapping[str, RepoInfo]] = None,
|
||||||
default: Chroot = None,
|
default: Chroot = None,
|
||||||
) -> Chroot:
|
) -> Chroot:
|
||||||
global chroots
|
global chroots
|
||||||
|
@ -350,6 +352,8 @@ def get_chroot(
|
||||||
elif fail_if_exists:
|
elif fail_if_exists:
|
||||||
raise Exception(f'chroot {name} already exists')
|
raise Exception(f'chroot {name} already exists')
|
||||||
chroot = chroots[name]
|
chroot = chroots[name]
|
||||||
|
if extra_repos is not None:
|
||||||
|
chroot.extra_repos = dict(extra_repos) # copy to new dict
|
||||||
if initialize:
|
if initialize:
|
||||||
chroot.initialize()
|
chroot.initialize()
|
||||||
if activate:
|
if activate:
|
||||||
|
|
|
@ -43,11 +43,9 @@ class BaseChroot(Chroot):
|
||||||
self.initialized = True
|
self.initialized = True
|
||||||
|
|
||||||
|
|
||||||
def get_base_chroot(arch: Arch, **kwargs) -> BaseChroot:
|
def get_base_chroot(arch: Arch) -> BaseChroot:
|
||||||
name = base_chroot_name(arch)
|
name = base_chroot_name(arch)
|
||||||
default = BaseChroot(name, arch, initialize=False, copy_base=False)
|
default = BaseChroot(name, arch, copy_base=False, initialize=False)
|
||||||
if kwargs.pop('initialize', False):
|
chroot = get_chroot(name, initialize=False, default=default)
|
||||||
logging.debug('get_base_chroot: Had to remove "initialize" from args. This indicates a bug.')
|
assert isinstance(chroot, BaseChroot)
|
||||||
chroot = get_chroot(name, **kwargs, initialize=False, default=default)
|
|
||||||
assert (isinstance(chroot, BaseChroot))
|
|
||||||
return chroot
|
return chroot
|
||||||
|
|
|
@ -143,7 +143,6 @@ def get_build_chroot(arch: Arch, add_kupfer_repos: bool = True, **kwargs) -> Bui
|
||||||
raise Exception('extra_repos!')
|
raise Exception('extra_repos!')
|
||||||
repos = get_kupfer_local(arch).repos if add_kupfer_repos else {}
|
repos = get_kupfer_local(arch).repos if add_kupfer_repos else {}
|
||||||
default = BuildChroot(name, arch, initialize=False, copy_base=True, extra_repos=repos)
|
default = BuildChroot(name, arch, initialize=False, copy_base=True, extra_repos=repos)
|
||||||
chroot = get_chroot(name, **kwargs, default=default)
|
chroot = get_chroot(name, **kwargs, extra_repos=repos, default=default)
|
||||||
chroot.extra_repos = repos
|
assert isinstance(chroot, BuildChroot)
|
||||||
assert (isinstance(chroot, BuildChroot))
|
|
||||||
return chroot
|
return chroot
|
||||||
|
|
|
@ -2,7 +2,9 @@ import atexit
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from constants import Arch, BASE_PACKAGES
|
from constants import Arch, BASE_PACKAGES
|
||||||
|
from distro.distro import get_kupfer_local, get_kupfer_https
|
||||||
from utils import check_findmnt
|
from utils import check_findmnt
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from .base import BaseChroot
|
from .base import BaseChroot
|
||||||
from .build import BuildChroot
|
from .build import BuildChroot
|
||||||
|
@ -44,11 +46,15 @@ def get_device_chroot(
|
||||||
flavour: str,
|
flavour: str,
|
||||||
arch: Arch,
|
arch: Arch,
|
||||||
packages: list[str] = BASE_PACKAGES,
|
packages: list[str] = BASE_PACKAGES,
|
||||||
extra_repos={},
|
use_local_repos: bool = True,
|
||||||
|
extra_repos: Optional[dict] = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> DeviceChroot:
|
) -> DeviceChroot:
|
||||||
name = f'rootfs_{device}-{flavour}'
|
name = f'rootfs_{device}-{flavour}'
|
||||||
default = DeviceChroot(name, arch, initialize=False, copy_base=False, base_packages=packages, extra_repos=extra_repos)
|
repos = dict(get_kupfer_local(arch).repos if use_local_repos else get_kupfer_https(arch).repos)
|
||||||
chroot = get_chroot(name, **kwargs, default=default)
|
repos.update(extra_repos or {})
|
||||||
assert (isinstance(chroot, DeviceChroot))
|
|
||||||
|
default = DeviceChroot(name, arch, initialize=False, copy_base=False, base_packages=packages, extra_repos=repos)
|
||||||
|
chroot = get_chroot(name, **kwargs, extra_repos=repos, default=default)
|
||||||
|
assert isinstance(chroot, DeviceChroot)
|
||||||
return chroot
|
return chroot
|
||||||
|
|
24
image.py
24
image.py
|
@ -10,9 +10,9 @@ from subprocess import run, CompletedProcess
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from chroot.device import DeviceChroot, get_device_chroot
|
from chroot.device import DeviceChroot, get_device_chroot
|
||||||
from constants import BASE_PACKAGES, DEVICES, FLAVOURS
|
from constants import Arch, BASE_PACKAGES, DEVICES, FLAVOURS
|
||||||
from config import config, Profile
|
from config import config, Profile
|
||||||
from distro.distro import get_base_distro, get_kupfer_https, get_kupfer_local
|
from distro.distro import get_base_distro, get_kupfer_https
|
||||||
from packages import build_enable_qemu_binfmt, discover_packages, build_packages
|
from packages import build_enable_qemu_binfmt, discover_packages, build_packages
|
||||||
from ssh import copy_ssh_keys
|
from ssh import copy_ssh_keys
|
||||||
from wrapper import enforce_wrap
|
from wrapper import enforce_wrap
|
||||||
|
@ -296,10 +296,19 @@ def create_boot_fs(device: str, blocksize: int):
|
||||||
create_filesystem(device, blocksize=blocksize, label='kupfer_boot', fstype='ext2')
|
create_filesystem(device, blocksize=blocksize, label='kupfer_boot', fstype='ext2')
|
||||||
|
|
||||||
|
|
||||||
def install_rootfs(rootfs_device: str, bootfs_device: str, device, flavour, arch, packages, extra_repos, profile):
|
def install_rootfs(
|
||||||
|
rootfs_device: str,
|
||||||
|
bootfs_device: str,
|
||||||
|
device: str,
|
||||||
|
flavour: str,
|
||||||
|
arch: Arch,
|
||||||
|
packages: list[str],
|
||||||
|
use_local_repos: bool,
|
||||||
|
profile: Profile,
|
||||||
|
):
|
||||||
user = profile['username'] or 'kupfer'
|
user = profile['username'] or 'kupfer'
|
||||||
post_cmds = FLAVOURS[flavour].get('post_cmds', [])
|
post_cmds = FLAVOURS[flavour].get('post_cmds', [])
|
||||||
chroot = get_device_chroot(device=device, flavour=flavour, arch=arch, packages=packages, extra_repos=extra_repos)
|
chroot = get_device_chroot(device=device, flavour=flavour, arch=arch, packages=packages, use_local_repos=use_local_repos)
|
||||||
|
|
||||||
mount_chroot(rootfs_device, bootfs_device, chroot)
|
mount_chroot(rootfs_device, bootfs_device, chroot)
|
||||||
|
|
||||||
|
@ -362,10 +371,7 @@ def cmd_build(profile_name: str = None, build_pkgs: bool = True, block_target: s
|
||||||
build_enable_qemu_binfmt(arch)
|
build_enable_qemu_binfmt(arch)
|
||||||
|
|
||||||
packages_dir = config.get_package_dir(arch)
|
packages_dir = config.get_package_dir(arch)
|
||||||
if os.path.exists(os.path.join(packages_dir, 'main')):
|
use_local_repos = os.path.exists(os.path.join(packages_dir, 'main'))
|
||||||
extra_repos = get_kupfer_local(arch).repos
|
|
||||||
else:
|
|
||||||
extra_repos = get_kupfer_https(arch).repos
|
|
||||||
packages = BASE_PACKAGES + DEVICES[device] + FLAVOURS[flavour]['packages'] + profile['pkgs_include']
|
packages = BASE_PACKAGES + DEVICES[device] + FLAVOURS[flavour]['packages'] + profile['pkgs_include']
|
||||||
|
|
||||||
if build_pkgs:
|
if build_pkgs:
|
||||||
|
@ -406,7 +412,7 @@ def cmd_build(profile_name: str = None, build_pkgs: bool = True, block_target: s
|
||||||
flavour,
|
flavour,
|
||||||
arch,
|
arch,
|
||||||
packages,
|
packages,
|
||||||
extra_repos,
|
use_local_repos,
|
||||||
profile,
|
profile,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue