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