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 argparse 18import os 19 20sys.path.append( 21 os.path.dirname(os.path.dirname(os.path.dirname( 22 os.path.abspath(__file__))))) 23from scripts.util.file_utils import read_json_file, write_json_file # noqa: E402 24 25 26def subsystem_list(all_subsystem_info_file: str, curr_subsystem_name_list_file: str): 27 curr_subsystem_list = [] 28 all_subsystem_info = read_json_file(all_subsystem_info_file) 29 if all_subsystem_info is None: 30 raise Exception( 31 "read file '{}' failed.".format(all_subsystem_info_file)) 32 curr_subsystem_name_list = read_json_file(curr_subsystem_name_list_file) 33 if curr_subsystem_name_list is None: 34 raise Exception( 35 "read file '{}' failed.".format(curr_subsystem_name_list_file)) 36 for _subsystem_name in curr_subsystem_name_list: 37 if _subsystem_name not in all_subsystem_info: 38 continue 39 else: 40 curr_subsystem_list.append(all_subsystem_info.get(_subsystem_name)) 41 return curr_subsystem_list 42 43 44def main(): 45 parser = argparse.ArgumentParser() 46 parser.add_argument('--target-platform-parts', required=True) 47 parser.add_argument('--parts-install-info-file', required=True) 48 parser.add_argument('--current-platform', required=True) 49 args = parser.parse_args() 50 51 curr_subsystem_list = subsystem_list(args.all_subsystem_info_file, 52 args.target_platform_subsystem) 53 platform_out_dir = os.path.dirname(args.system_install_info_file) 54 if not os.path.exists(platform_out_dir): 55 os.makedirs(platform_out_dir, exist_ok=True) 56 write_json_file(args.system_install_info_file, curr_subsystem_list) 57 return 0 58 59 60if __name__ == '__main__': 61 sys.exit(main()) 62