chroot/: fix class vars vs instance vars

looking at you, Chroot.active_mounts = []
This commit is contained in:
InsanePrawn 2022-03-03 16:54:43 +01:00
parent 179434729b
commit 9ff6f24489
5 changed files with 38 additions and 25 deletions

View file

@ -22,8 +22,8 @@ class AbstractChroot(Protocol):
copy_base: bool
initialized: bool = False
active: bool = False
active_mounts: list[str] = []
extra_repos: Mapping[str, RepoInfo] = {}
active_mounts: list[str]
extra_repos: Mapping[str, RepoInfo]
base_packages: list[str] = ['base']
def __init__(
@ -91,12 +91,13 @@ class Chroot(AbstractChroot):
if copy_base is None:
logging.debug(f'{name}: copy_base is none!')
copy_base = (name == base_chroot_name(arch))
self.active_mounts = list[str]()
self.name = name
self.arch = arch
self.path = path_override or os.path.join(config.get_path('chroots'), name)
self.copy_base = copy_base
self.extra_repos = deepcopy(extra_repos)
self.base_packages = base_packages
self.base_packages = base_packages.copy()
if initialize:
self.initialize()
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,
activate: bool = False,
fail_if_exists: bool = False,
extra_repos: Optional[Mapping[str, RepoInfo]] = None,
default: Chroot = None,
) -> Chroot:
global chroots
@ -350,6 +352,8 @@ def get_chroot(
elif fail_if_exists:
raise Exception(f'chroot {name} already exists')
chroot = chroots[name]
if extra_repos is not None:
chroot.extra_repos = dict(extra_repos) # copy to new dict
if initialize:
chroot.initialize()
if activate:

View file

@ -43,11 +43,9 @@ class BaseChroot(Chroot):
self.initialized = True
def get_base_chroot(arch: Arch, **kwargs) -> BaseChroot:
def get_base_chroot(arch: Arch) -> BaseChroot:
name = base_chroot_name(arch)
default = BaseChroot(name, arch, initialize=False, copy_base=False)
if kwargs.pop('initialize', False):
logging.debug('get_base_chroot: Had to remove "initialize" from args. This indicates a bug.')
chroot = get_chroot(name, **kwargs, initialize=False, default=default)
assert (isinstance(chroot, BaseChroot))
default = BaseChroot(name, arch, copy_base=False, initialize=False)
chroot = get_chroot(name, initialize=False, default=default)
assert isinstance(chroot, BaseChroot)
return chroot

View file

@ -143,7 +143,6 @@ def get_build_chroot(arch: Arch, add_kupfer_repos: bool = True, **kwargs) -> Bui
raise Exception('extra_repos!')
repos = get_kupfer_local(arch).repos if add_kupfer_repos else {}
default = BuildChroot(name, arch, initialize=False, copy_base=True, extra_repos=repos)
chroot = get_chroot(name, **kwargs, default=default)
chroot.extra_repos = repos
assert (isinstance(chroot, BuildChroot))
chroot = get_chroot(name, **kwargs, extra_repos=repos, default=default)
assert isinstance(chroot, BuildChroot)
return chroot

View file

@ -2,7 +2,9 @@ import atexit
import os
from constants import Arch, BASE_PACKAGES
from distro.distro import get_kupfer_local, get_kupfer_https
from utils import check_findmnt
from typing import Optional
from .base import BaseChroot
from .build import BuildChroot
@ -44,11 +46,15 @@ def get_device_chroot(
flavour: str,
arch: Arch,
packages: list[str] = BASE_PACKAGES,
extra_repos={},
use_local_repos: bool = True,
extra_repos: Optional[dict] = None,
**kwargs,
) -> DeviceChroot:
name = f'rootfs_{device}-{flavour}'
default = DeviceChroot(name, arch, initialize=False, copy_base=False, base_packages=packages, extra_repos=extra_repos)
chroot = get_chroot(name, **kwargs, default=default)
assert (isinstance(chroot, DeviceChroot))
repos = dict(get_kupfer_local(arch).repos if use_local_repos else get_kupfer_https(arch).repos)
repos.update(extra_repos or {})
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

View file

@ -10,9 +10,9 @@ from subprocess import run, CompletedProcess
from typing import Optional
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 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 ssh import copy_ssh_keys
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')
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'
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)
@ -362,10 +371,7 @@ def cmd_build(profile_name: str = None, build_pkgs: bool = True, block_target: s
build_enable_qemu_binfmt(arch)
packages_dir = config.get_package_dir(arch)
if os.path.exists(os.path.join(packages_dir, 'main')):
extra_repos = get_kupfer_local(arch).repos
else:
extra_repos = get_kupfer_https(arch).repos
use_local_repos = os.path.exists(os.path.join(packages_dir, 'main'))
packages = BASE_PACKAGES + DEVICES[device] + FLAVOURS[flavour]['packages'] + profile['pkgs_include']
if build_pkgs:
@ -406,7 +412,7 @@ def cmd_build(profile_name: str = None, build_pkgs: bool = True, block_target: s
flavour,
arch,
packages,
extra_repos,
use_local_repos,
profile,
)