From 6964d595c1d50d4e3603c51f9d29a39414cbda78 Mon Sep 17 00:00:00 2001 From: lixinyu Date: Wed, 14 Aug 2024 16:31:48 +0800 Subject: [PATCH] parse_template: fix the bug * fix the bug that throws an exception when a key is not present in the dictionary variable Signed-off-by: lixinyu --- src/oebuild/parse_template.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/oebuild/parse_template.py b/src/oebuild/parse_template.py index 7f4cd18..0860a58 100644 --- a/src/oebuild/parse_template.py +++ b/src/oebuild/parse_template.py @@ -279,11 +279,13 @@ class ParseTemplate: parse repo json object to OebuildRepo ''' repo_cict = {} - print(repos) for name, repo in repos.items(): - repo_cict[name] = RepoParam( - remote_url=repo['url'], - version=repo['refspec']) + try: + repo_cict[name] = RepoParam( + remote_url=repo['url'], + version=repo['refspec']) + except AttributeError: + repo_cict[name] = "" return repo_cict @@ -302,18 +304,18 @@ def get_docker_param_dict(docker_image, dir_list): parameters = oebuild_const.DEFAULT_CONTAINER_PARAMS volumns = [] volumns.append("/dev/net/tun:/dev/net/tun") - if dir_list['src_dir'] is not None: + if 'src_dir' in dir_list and dir_list['src_dir'] is not None: volumns.append(dir_list['src_dir'] + ':' + oebuild_const.CONTAINER_SRC) - if dir_list['compile_dir'] is not None: + if 'compile_dir' in dir_list and dir_list['compile_dir'] is not None: volumns.append(dir_list['compile_dir'] + ":" + os.path.join( oebuild_const.CONTAINER_BUILD, os.path.basename(dir_list['compile_dir']))) - if dir_list['toolchain_dir'] is not None: + if 'toolchain_dir' in dir_list and dir_list['toolchain_dir'] is not None: volumns.append(dir_list['toolchain_dir'] + ":" + oebuild_const.NATIVE_GCC_MAP) - if dir_list['llvm_toolchain_dir'] is not None: + if 'llvm_toolchain_dir' in dir_list and dir_list['llvm_toolchain_dir'] is not None: volumns.append(dir_list['llvm_toolchain_dir'] + ":" + oebuild_const.NATIVE_LLVM_MAP) - if dir_list['sstate_mirrors'] is not None: + if 'sstate_mirrors' in dir_list and dir_list['sstate_mirrors'] is not None: volumns.append(dir_list['sstate_mirrors'] + ":" + oebuild_const.SSTATE_MIRRORS) - if dir_list['sstate_dir'] is not None: + if 'sstate_dir' in dir_list and dir_list['sstate_dir'] is not None: volumns.append(dir_list['sstate_dir'] + ":" + oebuild_const.SSTATE_DIR) docker_param = {} -- Gitee