Skip to content

Commit

Permalink
tools.images_packer: implement subcommand handler for build_cache_src
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodong-Yang committed Dec 25, 2023
1 parent 02c4399 commit 5592763
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
56 changes: 46 additions & 10 deletions tools/images_packer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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_FILES_DIR>={_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

Expand Down Expand Up @@ -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 ------ #
#
Expand Down
2 changes: 1 addition & 1 deletion tools/images_packer/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}")
Expand Down

0 comments on commit 5592763

Please sign in to comment.