1#!/usr/bin/env python3 2# Copyright (C) 2024 The Android Open Source Project 3# 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# 16# Licensed under the Apache License, Version 2.0 (the "License"); 17# you may not use this file except in compliance with the License. 18# You may obtain a copy of the License at 19# 20# http://www.apache.org/licenses/LICENSE-2.0 21# 22# Unless required by applicable law or agreed to in writing, software 23# distributed under the License is distributed on an "AS IS" BASIS, 24# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25# See the License for the specific language governing permissions and 26# limitations under the License. 27 28import argparse 29import sys 30import parse_input_file 31import parse_output_file 32import add_to_file 33from datetime import datetime 34if sys.version_info[0] != 3: 35 print("Must use python 3") 36 sys.exit(1) 37 38COPYRIGHT_STR = """ Copyright (C) %s The Android Open Source Project 39Licensed under the Apache License, Version 2.0 (the "License"); 40you may not use this file except in compliance with the License. 41You may obtain a copy of the License at 42 http://www.apache.org/licenses/LICENSE-2.0 43Unless required by applicable law or agreed to in writing, software 44distributed under the License is distributed on an "AS IS" BASIS, 45WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 46See the License for the specific language governing permissions and 47limitations under the License.""" % (datetime.today().strftime("%Y")) 48 49""" 50Script used to automatically add the intents that match the filterPattern to the outputFile. 51""" 52def main(): 53 parser = argparse.ArgumentParser(description='Auto adding Intents.') 54 required_args = parser.add_argument_group('required arguments') 55 required_args.add_argument('-i', '--inputFile', nargs='+', help='Input file path (absolute or relative to cwd)', required=True) 56 required_args.add_argument('-o', '--outputFile', help='Output file path (absolute or relative to cwd)', required=True) 57 required_args.add_argument('-p', '--filterPattern', default='', help='Input file path (absolute or relative to cwd)', required=True) 58 optional_args = parser.add_argument_group('optional arguments') 59 optional_args.add_argument('-f', '--formatFile', default='', help='The file contains the format for the filtered strings when added to the output file') 60 optional_args.add_argument('-t', '--targetStringFile', default='', help='This file contains the target string after which the new content will be inserted.') 61 optional_args.add_argument('-e', '--excludeHiddenIntents', action=argparse.BooleanOptionalAction, help='whether to exclude hidden apis.') 62 args = parser.parse_args() 63 64 new_strings = filter_new_strings(args) 65 if (len(new_strings) != 0): 66 add_new_strings(args, new_strings) 67 68def filter_new_strings(args): 69 filtered_strings = [] 70 for file in args.inputFile: 71 filtered_strings.extend(parse_input_file.filter_javadoc_fields( 72 file, args.filterPattern, args.excludeHiddenIntents)) 73 74 current_strings = parse_output_file.filter_intent_actions(args.outputFile) 75 new_strings = sorted(set(filtered_strings) - set(current_strings)) 76 return new_strings 77 78def add_new_strings(args, new_strings): 79 add_to_file.insert_after_string(args.outputFile, args.targetStringFile, new_strings, args.formatFile) 80 81if __name__ == '__main__': 82 main() 83