1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2021 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import sys 17import os 18import argparse 19sys.path.append( 20 os.path.dirname(os.path.dirname(os.path.dirname( 21 os.path.abspath(__file__))))) 22from scripts.util.file_utils import read_json_file, write_json_file # noqa: E402 23 24 25def get_src_parts(system_install_info_file): 26 parts_list = read_json_file(system_install_info_file) 27 if parts_list is None: 28 raise Exception("read file '{}' failed.".format(system_install_info_file)) 29 src_parts_info = {} 30 for _part_info in parts_list: 31 if 'is_source' not in _part_info: 32 raise Exception( 33 "read subsystem info error, missing key is_source.") 34 if _part_info.get('is_source') is True: 35 part_name = _part_info.get('part_name') 36 origin_part_name = _part_info.get('origin_part_name') 37 src_parts_info[part_name] = origin_part_name 38 return src_parts_info 39 40 41def get_sa_install_info(sa_info_file, src_parts_info): 42 sa_infos = read_json_file(sa_info_file) 43 if sa_infos is None: 44 raise Exception("read file '{}' failed.".format(sa_info_file)) 45 sa_install_infos = [] 46 for _sa_info in sa_infos: 47 _sa_info_part = _sa_info.get('part_name') 48 if _sa_info_part in src_parts_info: 49 sa_install_infos.append(_sa_info) 50 return sa_install_infos 51 52 53def main(): 54 parser = argparse.ArgumentParser() 55 parser.add_argument('--system-install-info-file', required=True) 56 parser.add_argument('--src-sa-info-file', required=False) 57 parser.add_argument('--src-sa-install-info-file', required=True) 58 args = parser.parse_args() 59 60 src_parts_info = get_src_parts(args.system_install_info_file) 61 sa_install_infos = get_sa_install_info(args.src_sa_info_file, 62 src_parts_info) 63 write_json_file(args.src_sa_install_info_file, sa_install_infos) 64 return 0 65 66 67if __name__ == '__main__': 68 sys.exit(main()) 69