diff options
author | Ondřej Šmalec <o.smalec@partner.samsung.com> | 2020-02-04 15:30:48 +0100 |
---|---|---|
committer | Ondřej Šmalec <o.smalec@partner.samsung.com> | 2020-02-13 18:35:31 +0000 |
commit | d8b17a1fe40bdc1fb1df0a70be6e92cdbc5ce09c (patch) | |
tree | 0c7d29fab23225a725af904a69abd9bb66274d5a /build | |
parent | 6ac532c0d6cd76dd5fef7cee280fdc1f43ea9222 (diff) |
Adding checksum of packages into package.info
Function to add checksum of created packges
to package.info
Modified --add-metadata parameter to handle
more parameters in format key=value
Issue-ID: OOM-2288
Signed-off-by: Ondřej Šmalec <o.smalec@partner.samsung.com>
Change-Id: I29114c4566fdfd9643ab5c60951ee65f5680d2fe
Diffstat (limited to 'build')
-rwxr-xr-x | build/package.py | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/build/package.py b/build/package.py index c0ca47a5..82fbba34 100755 --- a/build/package.py +++ b/build/package.py @@ -28,6 +28,7 @@ import glob import json import sys import os +import hashlib import tarfile import git @@ -82,20 +83,41 @@ def create_package_info_file(output_file, repository_list, tag, metadata): build_info = { 'Build_info': { 'build_date': datetime.now().strftime('%Y-%m-%d_%H-%M'), - 'Version': tag + 'Version': tag, + 'Packages': {} } } for repository in repository_list: build_info['Build_info'][ repository.config_reader().get_value('remote "origin"', 'url')] = repository.head.commit.hexsha - if len(metadata) != 0: - build_info['Build_info'][metadata[0]] = metadata[1] + if metadata: + for meta in metadata: + build_info['Build_info'].update(meta) with open(output_file, 'w') as outfile: json.dump(build_info, outfile, indent=4) +def add_checksum_info(output_dir): + """ + Add checksum information into package.info file + :param output_dir: directory where are packages + """ + tar_files = ['resources_package.tar', 'aux_package.tar', 'sw_package.tar'] + for tar_file in tar_files: + try: + data = os.path.join(output_dir, tar_file) + cksum = hashlib.md5(open(data, 'rb').read()).hexdigest() + with open(os.path.join(output_dir, 'package.info'), 'r') as f: + json_data = json.load(f) + json_data['Build_info']['Packages'].update({tar_file: cksum}) + with open(os.path.join(output_dir, 'package.info'), 'w') as f: + json.dump(json_data, f, indent=4) + except FileNotFoundError: + pass + + def create_package(tar_content, file_name): """ Creates packages @@ -109,6 +131,20 @@ def create_package(tar_content, file_name): output_tar_file.add(src, dst) +def metadata_validation(param): + """ + Validation of metadata parameters + :param param: parameter to be checked needs to be in format key=value + """ + try: + key, value = param.split('=') + assert (key and value) + return {key: value} + except (ValueError, AssertionError): + msg = "%r is not a valid parameter. Needs to be in format key=value" % param + raise argparse.ArgumentTypeError(msg) + + def build_offline_deliverables(build_version, application_repository_url, application_repository_reference, @@ -224,6 +260,7 @@ def build_offline_deliverables(build_version, aux_package_tar_path = os.path.join(output_dir, 'aux_package.tar') create_package(aux_content, aux_package_tar_path) + add_checksum_info(output_dir) shutil.rmtree(application_dir) @@ -265,8 +302,8 @@ def run_cli(): help='overwrite files in output directory') parser.add_argument('--debug', action='store_true', default=False, help='Turn on debug output') - parser.add_argument('--add-metadata', nargs=2, - help='additional metadata added into package.info, format: key value', default=[]) + parser.add_argument('--add-metadata', nargs="+", type=metadata_validation, + help='additional metadata added into package.info, format: key=value') args = parser.parse_args() if args.debug: |