1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2021-2022 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 os 17import sys 18import optparse 19import json 20import re 21 22 23def copy_files(options): 24 with open(options.remove) as f: 25 remove_dict = json.load(f) 26 if options.name in remove_dict: 27 rm_name = remove_dict[options.name] 28 if 'base' in rm_name: 29 file_list = rm_name['base'] 30 else: 31 file_list = [] 32 for file in os.listdir(options.input): 33 src = os.path.join(options.input, file) 34 if os.path.isfile(src) and ( 35 not 'global_remove' in rm_name or ( 36 'global_remove' in rm_name and ( 37 not file in rm_name['global_remove']))): 38 format_src = format_path(src) 39 if options.ispublic == 'true': 40 if not 'sdk_build_public_remove' in rm_name: 41 file_list.append(format_src) 42 else: 43 if not file in rm_name['sdk_build_public_remove']: 44 file_list.append(format_src) 45 else: 46 file_list.append(format_src) 47 else: 48 file_list = [] 49 for file in os.listdir(options.input): 50 src = os.path.join(options.input, file) 51 if os.path.isfile(src): 52 format_src = format_path(src) 53 file_list.append(format_src) 54 return file_list 55 56 57def format_path(filepath): 58 return re.sub(r'.*(?=api/)', '', filepath); 59 60 61def parse_args(args): 62 parser = optparse.OptionParser() 63 parser.add_option('--input', help='d.ts document input path') 64 parser.add_option('--remove', help='d.ts to be remove path') 65 parser.add_option('--ispublic', help='whether or not sdk build public') 66 parser.add_option('--name', help='module label name') 67 options, _ = parser.parse_args(args) 68 return options 69 70 71def main(argv): 72 options = parse_args(argv) 73 result = copy_files(options) 74 print(json.dumps(result)) 75 return 0 76 77 78if __name__ == "__main__": 79 sys.exit(main(sys.argv)) 80