pmbootstrap qemu: tweak resize_image messages (MR 2008)

Replace "rootfs" with generic image, because the function will be used
for a second storage too. Refer to IMAGE_SIZE, as it is shown in the
help output.
This commit is contained in:
Oliver Smith 2020-12-14 19:15:03 +01:00 committed by Martijn Braam
parent dd61d57b0e
commit 61f5c20ebb
No known key found for this signature in database
GPG Key ID: C4280ACB000B060F
1 changed files with 8 additions and 6 deletions

View File

@ -185,11 +185,12 @@ def command_qemu(args, arch, img_path):
def resize_image(args, img_size_new, img_path):
"""
Truncates the rootfs to a specific size. The value must be larger than the
current image size, and it must be specified in MiB or GiB units (powers of 1024).
Truncates an image to a specific size. The value must be larger than the
current image size, and it must be specified in MiB or GiB units (powers of
1024).
:param img_size_new: new image size in M or G
:param img_path: the path to the rootfs
:param img_path: the path to the image
"""
# Current image size in bytes
img_size = os.path.getsize(img_path)
@ -197,7 +198,8 @@ def resize_image(args, img_size_new, img_path):
# Make sure we have at least 1 integer followed by either M or G
pattern = re.compile("^[0-9]+[M|G]$")
if not pattern.match(img_size_new):
raise RuntimeError("You must specify the rootfs size in [M]iB or [G]iB, e.g. 2048M or 2G")
raise RuntimeError("IMAGE_SIZE must be in [M]iB or [G]iB, e.g. 2048M"
" or 2G")
# Remove M or G and convert to bytes
img_size_new_bytes = int(img_size_new[:-1]) * 1024 * 1024
@ -207,7 +209,7 @@ def resize_image(args, img_size_new, img_path):
img_size_new_bytes = img_size_new_bytes * 1024
if (img_size_new_bytes >= img_size):
logging.info("Setting the rootfs size to " + img_size_new)
logging.info(f"Resize image to {img_size_new}: {img_path}")
pmb.helpers.run.root(args, ["truncate", "-s", img_size_new, img_path])
else:
# Convert to human-readable format
@ -217,7 +219,7 @@ def resize_image(args, img_size_new, img_path):
# this example, they would need to use a size greater then 1280M instead.
img_size_str = str(round(img_size / 1024 / 1024)) + "M"
raise RuntimeError("The rootfs size must be " + img_size_str + " or greater")
raise RuntimeError(f"IMAGE_SIZE must be {img_size_str} or greater")
def sigterm_handler(number, frame):