diff --git a/chroot/abstract.py b/chroot/abstract.py index 93e8fcc..e57d3e2 100644 --- a/chroot/abstract.py +++ b/chroot/abstract.py @@ -395,16 +395,18 @@ chroots: dict[str, Chroot] = {} def get_chroot( name: str, + chroot_class: type[Chroot], + chroot_args: dict, initialize: bool = False, activate: bool = False, fail_if_exists: bool = False, extra_repos: Optional[Mapping[str, RepoInfo]] = None, - default: Chroot = None, ) -> Chroot: global chroots - if default and name not in chroots: - logging.debug(f'Adding chroot {name} to chroot map: {default.uuid}') - chroots[name] = default + if name not in chroots: + chroot = chroot_class(name, **chroot_args) + logging.debug(f'Adding chroot {name} to chroot map: {chroot.uuid}') + chroots[name] = chroot else: existing = chroots[name] if fail_if_exists: diff --git a/chroot/base.py b/chroot/base.py index 5d8f482..87dc2c4 100644 --- a/chroot/base.py +++ b/chroot/base.py @@ -48,7 +48,7 @@ class BaseChroot(Chroot): def get_base_chroot(arch: Arch) -> BaseChroot: name = base_chroot_name(arch) - default = BaseChroot(name, arch, copy_base=False, initialize=False) - chroot = get_chroot(name, initialize=False, default=default) + args = dict(arch=arch, copy_base=False, initialize=False) + chroot = get_chroot(name, initialize=False, chroot_class=BaseChroot, chroot_args=args) assert isinstance(chroot, BaseChroot) return chroot diff --git a/chroot/build.py b/chroot/build.py index aaf9968..27d1a6a 100644 --- a/chroot/build.py +++ b/chroot/build.py @@ -164,7 +164,7 @@ def get_build_chroot(arch: Arch, add_kupfer_repos: bool = True, **kwargs) -> Bui if 'extra_repos' in kwargs: 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, extra_repos=repos, default=default) + args = dict(arch=arch, initialize=False, copy_base=True, extra_repos=repos) + chroot = get_chroot(name, **kwargs, extra_repos=repos, chroot_class=BuildChroot, chroot_args=args) assert isinstance(chroot, BuildChroot) return chroot diff --git a/chroot/device.py b/chroot/device.py index 02897a2..14fd4d8 100644 --- a/chroot/device.py +++ b/chroot/device.py @@ -65,7 +65,7 @@ def get_device_chroot( 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) + args = dict(arch=arch, initialize=False, copy_base=False, base_packages=packages, extra_repos=repos) + chroot = get_chroot(name, **kwargs, extra_repos=repos, chroot_class=DeviceChroot, chroot_args=args) assert isinstance(chroot, DeviceChroot) return chroot