Commit b1e985c1 authored by rgaudin's avatar rgaudin
Browse files

--shrink option (default to yes on cli and gui) to reduce image file size...

--shrink option (default to yes on cli and gui) to reduce image file size *after* creation to minimum required
parent 16ccd0e1
2.0.4
* Speed up improvements for Wikifundi
* Updated kiwix-serve to 0.9.0
* Image file shrunk after creation
2.0.3
* Added --root for CLI on linux to use losetup instead of udisks (for docker)
......
......@@ -131,9 +131,11 @@ class Emulator:
def get_image_size(self):
return get_qemu_image_size(self._image, self._logger)
def resize_image(self, size):
def resize_image(self, size, shrink=False):
subprocess_pretty_check_call(
[qemu_img_exe_path, "resize", "-f", "raw", self._image, "{}".format(size)],
[qemu_img_exe_path, "resize"]
+ (["--shrink"] if shrink else [])
+ ["-f", "raw", self._image, "{}".format(size)],
self._logger,
)
......
......@@ -159,6 +159,7 @@ defaults = {
"kalite": [],
"wikifundi": [],
"zim_install": [],
"shrink": "yes",
}
parser = argparse.ArgumentParser(
......@@ -198,6 +199,7 @@ parser.add_argument(
help="use a JSON config file to set parameters (superseeds cli parameters)",
)
parser.add_argument("--filename", help="Output file name (without suffix)")
parser.add_argument("--shrink", help="Shrink image file", choices=["yes", "no"])
parser.add_argument("--ram", help="Max RAM for QEMU", default="2G")
parser.add_argument("--sdcard", help="Device to copy image to")
parser.add_argument(
......@@ -385,6 +387,7 @@ try:
admin_account=admin_account,
build_dir=args.build_dir,
filename=args.filename,
shrink=args.shrink == "yes",
qemu_ram=args.ram,
)
except Exception:
......
......@@ -1845,6 +1845,7 @@ class Application:
done_callback=lambda error: GLib.idle_add(
self.installation_done, error
),
shrink=True,
)
self.component.window.hide()
......
......@@ -5,6 +5,7 @@ import os
import sys
import time
import json
import math
import shutil
import traceback
from datetime import datetime
......@@ -12,6 +13,7 @@ from datetime import datetime
import data
from backend import qemu
from util import (
ONE_GB,
human_readable_size,
get_cache,
ensure_zip_exfat_compatible,
......@@ -26,6 +28,7 @@ from backend.content import (
isremote,
get_content_cache,
get_alien_content,
get_required_image_size,
)
from backend.download import download_content, unzip_file
from backend.mount import (
......@@ -64,6 +67,7 @@ def run_installation(
build_dir=".",
filename=None,
qemu_ram="2G",
shrink=False,
):
logger.start(bool(sd_card))
......@@ -265,8 +269,9 @@ def run_installation(
# Resize image
logger.step(
"Resizing image file to {s}".format(
s=human_readable_size(emulator.get_image_size())
"Resizing image file from {s1} to {s2}".format(
s1=human_readable_size(emulator.get_image_size()),
s2=human_readable_size(size),
)
)
if size < emulator.get_image_size():
......@@ -340,6 +345,18 @@ def run_installation(
logger.step("Re-run ansiblecube for move-content")
ansiblecube.run_phase_two(emulation, extra_vars, secret_keys)
if shrink:
logger.step("Shrink size of physical image file")
# calculate physical size of image
required_image_size = get_required_image_size(collection)
if required_image_size + ONE_GB >= size:
# less than 1GB difference, don't bother
pass
else:
# set physical size to required + margin
physical_size = math.ceil(required_image_size / ONE_GB) * ONE_GB
emulator.resize_image(physical_size, shrink=True)
# wait for QEMU to release file (windows mostly)
logger.succ("Image creation successful.")
time.sleep(20)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment