Kuang-che Wu | 875c89a | 2020-01-08 14:30:55 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Kuang-che Wu | 6e4beca | 2018-06-27 17:45:02 +0800 | [diff] [blame] | 2 | # -*- coding: utf-8 -*- |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 3 | # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | """Switcher for ChromeOS ARC container prebuilt. |
| 7 | |
| 8 | Typical usage: |
| 9 | $ bisect_android_build_id.py config switch ./switch_arc_prebuilt.py |
| 10 | |
Kuang-che Wu | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 11 | It is implemented by calling Android's push_to_device.py. |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 12 | """ |
| 13 | |
| 14 | from __future__ import print_function |
| 15 | import argparse |
| 16 | import logging |
Kuang-che Wu | d18cd5b | 2019-08-20 14:14:21 +0800 | [diff] [blame] | 17 | import sys |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 18 | |
| 19 | from bisect_kit import android_util |
| 20 | from bisect_kit import arc_util |
| 21 | from bisect_kit import cli |
| 22 | from bisect_kit import common |
| 23 | from bisect_kit import configure |
Kuang-che Wu | d18cd5b | 2019-08-20 14:14:21 +0800 | [diff] [blame] | 24 | from bisect_kit import cros_lab_util |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 25 | from bisect_kit import cros_util |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 26 | from bisect_kit import errors |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 27 | |
| 28 | logger = logging.getLogger(__name__) |
| 29 | |
| 30 | |
| 31 | def create_argument_parser(): |
Kuang-che Wu | d2d6e41 | 2021-01-28 16:26:41 +0800 | [diff] [blame] | 32 | parents = [common.common_argument_parser, common.session_optional_parser] |
| 33 | parser = argparse.ArgumentParser(description=__doc__, parents=parents) |
Kuang-che Wu | fe1e88a | 2019-09-10 21:52:25 +0800 | [diff] [blame] | 34 | cli.patching_argparser_exit(parser) |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 35 | parser.add_argument( |
Kuang-che Wu | 0ebbf7c | 2019-08-28 18:19:19 +0800 | [diff] [blame] | 36 | '--dut', |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 37 | type=cli.argtype_notempty, |
| 38 | metavar='DUT', |
| 39 | default=configure.get('DUT', '')) |
| 40 | parser.add_argument( |
| 41 | 'build_id', |
| 42 | nargs='?', |
| 43 | type=android_util.argtype_android_build_id, |
| 44 | metavar='ANDROID_BUILD_ID', |
| 45 | default=configure.get('ANDROID_BUILD_ID', '')) |
| 46 | parser.add_argument( |
| 47 | '--flavor', |
| 48 | metavar='ANDROID_FLAVOR', |
| 49 | default=configure.get('ANDROID_FLAVOR'), |
| 50 | help='example: cheets_x86-user') |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 51 | |
| 52 | return parser |
| 53 | |
| 54 | |
Kuang-che Wu | fe1e88a | 2019-09-10 21:52:25 +0800 | [diff] [blame] | 55 | @cli.fatal_error_handler |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 56 | def main(args=None): |
| 57 | common.init() |
| 58 | parser = create_argument_parser() |
| 59 | opts = parser.parse_args(args) |
| 60 | common.config_logging(opts) |
| 61 | |
| 62 | if not opts.flavor: |
| 63 | opts.flavor = arc_util.query_flavor(opts.dut) |
| 64 | assert opts.flavor |
| 65 | logger.info('use flavor=%s', opts.flavor) |
| 66 | |
Kuang-che Wu | d18cd5b | 2019-08-20 14:14:21 +0800 | [diff] [blame] | 67 | if not cros_util.is_good_dut(opts.dut): |
| 68 | logger.fatal('%r is not a good DUT', opts.dut) |
| 69 | if not cros_lab_util.repair(opts.dut): |
| 70 | sys.exit(cli.EXIT_CODE_FATAL) |
| 71 | |
Kuang-che Wu | 94ef56e | 2019-01-15 21:17:42 +0800 | [diff] [blame] | 72 | arc_util.push_prebuilt_to_device(opts.dut, opts.flavor, opts.build_id) |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 73 | |
| 74 | arc_version = cros_util.query_dut_lsb_release( |
| 75 | opts.dut).get('CHROMEOS_ARC_VERSION') |
Kuang-che Wu | 25fec6f | 2021-01-28 12:40:43 +0800 | [diff] [blame] | 76 | if arc_version and str(opts.build_id) in arc_version: |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 77 | logger.info('updated to "%s", done', arc_version) |
| 78 | else: |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 79 | raise errors.ExecutionFatalError( |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 80 | 'arc version is expected matching "%s" but actual "%s"' % |
| 81 | (opts.build_id, arc_version)) |
| 82 | |
| 83 | |
| 84 | if __name__ == '__main__': |
| 85 | main() |