1#!/usr/bin/env python3 2# 3# Copyright 2024 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17"""Command line utility for running Android workflows and productivity tools.""" 18 19import argparse 20import logging 21import os 22import sys 23 24from tools.update import Update 25 26logger = logging.getLogger(__name__) 27os.environ['PYTHONUNBUFFERED'] = '1' # No latency for output. 28 29 30tools_map = { 31 'update': Update, 32} 33 34 35def run(): 36 """Entry point for tool.""" 37 parser = argparse.ArgumentParser( 38 description='A runs tools and workflows for local Android development', 39 formatter_class=argparse.RawDescriptionHelpFormatter, 40 ) 41 subparsers = parser.add_subparsers(dest='tool') 42 for _, tool_class in tools_map.items(): 43 tool_class.add_parser(subparsers) 44 45 args = parser.parse_args() 46 47 # Tool 48 if not args.tool: 49 print('Error: Please specify a tool (eg. update)') 50 parser.print_help() 51 return 1 52 tool_name = args.tool.lower() 53 tool = tools_map[tool_name](args) 54 return tool.main() 55 56 57if __name__ == '__main__': 58 logging.basicConfig( 59 level=logging.ERROR, 60 handlers=[ 61 logging.FileHandler(f"{os.environ.get('OUT', '/tmp')}/a_tool.log"), 62 logging.StreamHandler(sys.stderr), 63 ], 64 ) 65 run() 66