chroot: clean up the copy_base instance var mess

This commit is contained in:
InsanePrawn 2022-09-27 05:55:50 +02:00
parent 8a31a98946
commit 746e42a4f6
4 changed files with 13 additions and 9 deletions

View file

@ -4,7 +4,7 @@ import os
import subprocess import subprocess
from copy import deepcopy from copy import deepcopy
from shlex import quote as shell_quote from shlex import quote as shell_quote
from typing import Protocol, Union, Optional, Mapping from typing import ClassVar, Protocol, Union, Optional, Mapping
from uuid import uuid4 from uuid import uuid4
from config import config from config import config
@ -78,6 +78,9 @@ class AbstractChroot(Protocol):
class Chroot(AbstractChroot): class Chroot(AbstractChroot):
_copy_base: ClassVar[bool] = False
copy_base: bool
def __repr__(self): def __repr__(self):
return f'Chroot({self.name})' return f'Chroot({self.name})'
@ -101,7 +104,7 @@ class Chroot(AbstractChroot):
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 if copy_base is not None else self._copy_base
self.extra_repos = deepcopy(extra_repos) self.extra_repos = deepcopy(extra_repos)
self.base_packages = base_packages.copy() self.base_packages = base_packages.copy()
if initialize: if initialize:

View file

@ -3,6 +3,7 @@ import os
from glob import glob from glob import glob
from shutil import rmtree from shutil import rmtree
from typing import ClassVar
from constants import Arch from constants import Arch
from exec.cmd import run_root_cmd from exec.cmd import run_root_cmd
@ -15,7 +16,7 @@ from .helpers import base_chroot_name
class BaseChroot(Chroot): class BaseChroot(Chroot):
copy_base: bool = False _copy_base: ClassVar[bool] = False
def create_rootfs(self, reset, pacman_conf_target, active_previously): def create_rootfs(self, reset, pacman_conf_target, active_previously):
if reset: if reset:

View file

@ -2,7 +2,7 @@ import logging
import os import os
import subprocess import subprocess
from glob import glob from glob import glob
from typing import Optional from typing import ClassVar, Optional
from config import config from config import config
from constants import Arch, GCC_HOSTSPECS, CROSSDIRECT_PKGS, CHROOT_PATHS from constants import Arch, GCC_HOSTSPECS, CROSSDIRECT_PKGS, CHROOT_PATHS
@ -17,7 +17,7 @@ from .base import get_base_chroot
class BuildChroot(Chroot): class BuildChroot(Chroot):
copy_base: bool = True _copy_base: ClassVar[bool] = True
def create_rootfs(self, reset: bool, pacman_conf_target: str, active_previously: bool): def create_rootfs(self, reset: bool, pacman_conf_target: str, active_previously: bool):
makedir(config.get_path('chroots')) makedir(config.get_path('chroots'))
@ -164,7 +164,7 @@ def get_build_chroot(arch: Arch, add_kupfer_repos: bool = True, **kwargs) -> Bui
if 'extra_repos' in kwargs: if 'extra_repos' in kwargs:
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 {}
args = dict(arch=arch, initialize=False, copy_base=True, extra_repos=repos) args = dict(arch=arch)
chroot = get_chroot(name, **kwargs, extra_repos=repos, chroot_class=BuildChroot, chroot_args=args) chroot = get_chroot(name, **kwargs, extra_repos=repos, chroot_class=BuildChroot, chroot_args=args)
assert isinstance(chroot, BuildChroot) assert isinstance(chroot, BuildChroot)
return chroot return chroot

View file

@ -1,7 +1,7 @@
import atexit import atexit
import os import os
from typing import Optional from typing import ClassVar, Optional
from config import config from config import config
from constants import Arch, BASE_PACKAGES from constants import Arch, BASE_PACKAGES
@ -17,7 +17,7 @@ from .abstract import get_chroot
class DeviceChroot(BuildChroot): class DeviceChroot(BuildChroot):
copy_base: bool = False _copy_base: ClassVar[bool] = False
def create_rootfs(self, reset, pacman_conf_target, active_previously): def create_rootfs(self, reset, pacman_conf_target, active_previously):
clss = BuildChroot if self.copy_base else BaseChroot clss = BuildChroot if self.copy_base else BaseChroot
@ -65,7 +65,7 @@ def get_device_chroot(
repos.update(extra_repos or {}) repos.update(extra_repos or {})
args = dict(arch=arch, initialize=False, copy_base=False, base_packages=packages, extra_repos=repos) args = dict(arch=arch, base_packages=packages, extra_repos=repos)
chroot = get_chroot(name, **kwargs, extra_repos=repos, chroot_class=DeviceChroot, chroot_args=args) chroot = get_chroot(name, **kwargs, extra_repos=repos, chroot_class=DeviceChroot, chroot_args=args)
assert isinstance(chroot, DeviceChroot) assert isinstance(chroot, DeviceChroot)
return chroot return chroot