From 5f6772eb3936068180f6c7cd592be8afdeb35c0f Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Mon, 14 Feb 2022 19:32:04 +0100 Subject: [PATCH] add size_extra_mb to profiles, use in cmd_image_build() --- config.py | 13 ++++++++++++- image.py | 7 ++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index 805a414..5921e5e 100644 --- a/config.py +++ b/config.py @@ -21,6 +21,7 @@ PROFILE_DEFAULTS: Profile = { 'hostname': 'kupfer', 'username': 'kupfer', 'password': None, + 'size_extra_mb': "0", } PROFILE_EMPTY: Profile = {key: None for key in PROFILE_DEFAULTS.keys()} @@ -105,7 +106,13 @@ def resolve_profile( if 'parent' in sparse and (parent_name := sparse['parent']): parent = resolve_profile(name=parent_name, sparse_profiles=sparse_profiles, resolved=resolved, _visited=_visited)[parent_name] full = parent | sparse - + # add up size_extra_mb + if 'size_extra_mb' in sparse: + size = sparse['size_extra_mb'] + if isinstance(size, str) and size.startswith('+'): + full['size_extra_mb'] = int(parent.get('size_extra_mb', 0)) + int(size.lstrip('+')) + else: + full['size_extra_mb'] = int(sparse['size_extra_mb']) # join our includes with parent's includes = set(parent.get('pkgs_include', []) + sparse.get('pkgs_include', [])) if 'pkgs_exclude' in sparse: @@ -126,6 +133,8 @@ def resolve_profile( if type(value) == list: full[key] = [] + full['size_extra_mb'] = int(full['size_extra_mb'] or 0) + resolved[name] = full return resolved @@ -330,6 +339,8 @@ class ConfigStateHolder: if merge: new = deepcopy(self.file['profiles'][name]) + logging.debug(f'new: {new}') + logging.debug(f'profile: {profile}') new |= profile if prune: diff --git a/image.py b/image.py index ef7936e..4f85b02 100644 --- a/image.py +++ b/image.py @@ -347,11 +347,12 @@ def cmd_build(profile_name: str = None, build_pkgs: bool = True, block_target: s enforce_wrap() profile = config.get_profile(profile_name) device, flavour = get_device_and_flavour(profile_name) + size_extra_mb = profile["size_extra_mb"] # TODO: PARSE DEVICE ARCH AND SECTOR SIZE arch = 'aarch64' sector_size = 4096 - rootfs_size_gb = FLAVOURS[flavour].get('size', 2) + rootfs_size_mb = FLAVOURS[flavour].get('size', 2) * 1000 build_enable_qemu_binfmt(arch) @@ -371,7 +372,7 @@ def cmd_build(profile_name: str = None, build_pkgs: bool = True, block_target: s os.makedirs(os.path.dirname(image_path), exist_ok=True) logging.info(f'Creating new file at {image_path}') - create_img_file(image_path, f"{rootfs_size_gb}G") + create_img_file(image_path, f"{rootfs_size_mb + size_extra_mb}M") loop_device = losetup_rootfs_image(image_path, sector_size) @@ -387,7 +388,7 @@ def cmd_build(profile_name: str = None, build_pkgs: bool = True, block_target: s else: logging.info('Creating per-partition image files') boot_dev = create_img_file(get_image_path(device, flavour, 'boot'), IMG_FILE_BOOT_DEFAULT_SIZE) - root_dev = create_img_file(get_image_path(device, flavour, 'root'), f'{rootfs_size_gb * 1000 - 200}M') + root_dev = create_img_file(get_image_path(device, flavour, 'root'), f'{rootfs_size_mb + size_extra_mb - 200}M') create_boot_fs(boot_dev, sector_size) create_root_fs(root_dev, sector_size)