From 5592763c2b93f3795660051b7315ba11b39dfdf8 Mon Sep 17 00:00:00 2001 From: Bodong YANG Date: Mon, 25 Dec 2023 03:55:38 +0000 Subject: [PATCH] tools.images_packer: implement subcommand handler for build_cache_src --- tools/images_packer/__main__.py | 56 +++++++++++++++++++++++++++------ tools/images_packer/builder.py | 2 +- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/tools/images_packer/__main__.py b/tools/images_packer/__main__.py index a42e8361a..a313fdfda 100644 --- a/tools/images_packer/__main__.py +++ b/tools/images_packer/__main__.py @@ -54,11 +54,6 @@ def main_build_offline_ota_image_bundle(args: argparse.Namespace): - # ------ args check ------ # - if not (args.output or args.write_to): - print("ERR: at least one export option should be specified") - sys.exit(errno.EINVAL) - # ------ parse input image options ------ # image_metas = [] image_files = {} @@ -81,6 +76,52 @@ def main_build_offline_ota_image_bundle(args: argparse.Namespace): print("ERR: at least one valid image should be given, abort") sys.exit(errno.EINVAL) + # ------ build image ------ # + with tempfile.TemporaryDirectory(prefix="offline_OTA_image_builder") as workdir: + build( + image_metas, + image_files, + workdir=workdir, + output=args.output, + ) + + +def main_build_external_cache_src(args: argparse.Namespace): + # ------ args check ------ # + if not (args.output or args.write_to): + logger.error("ERR: at least one export option should be specified") + sys.exit(errno.EINVAL) + + # ------ parse args ------ # + image_metas: list[ImageMetadata] = [] + image_files: dict[str, Path] = {} + count = 0 + + # retrieves images from --image arg + for _image_fpath in args.image: + count_str = str(count) + image_metas.append(ImageMetadata(ecu_id=count_str)) + image_files[count_str] = _image_fpath + count += 1 + + # retrieves images from --image-dir arg + _image_store_dpath = Path(args.image_dir) + if not _image_store_dpath.is_dir(): + logger.error( + f"ERR: specified ={_image_store_dpath} doesn't exist, abort" + ) + sys.exit(errno.EINVAL) + + for _image_fpath in _image_store_dpath.glob("*"): + count_str = str(count) + image_metas.append(ImageMetadata(ecu_id=count_str)) + image_files[count_str] = _image_fpath + count += 1 + + if not image_metas: + print("ERR: at least one valid image should be given, abort") + sys.exit(errno.EINVAL) + # ------ parse export options ------ # output_fpath, write_to_dev = args.output, args.write_to @@ -109,14 +150,9 @@ def main_build_offline_ota_image_bundle(args: argparse.Namespace): image_files, workdir=workdir, output=output_fpath, - write_to_dev=write_to_dev, ) -def main_build_external_cache_src(args: argparse.Namespace): - pass - - # # ------ subcommands definition ------ # # diff --git a/tools/images_packer/builder.py b/tools/images_packer/builder.py index 42c77d7f5..b30b25261 100644 --- a/tools/images_packer/builder.py +++ b/tools/images_packer/builder.py @@ -174,7 +174,7 @@ def build( *, workdir: StrPath, output: Optional[StrPath], - write_to_dev: Optional[StrPath], + write_to_dev: Optional[StrPath] = None, ): _start_time = time.time() logger.info(f"job started at {int(_start_time)}")