Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
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(): |
| 32 | parser = argparse.ArgumentParser(description=__doc__) |
| 33 | common.add_common_arguments(parser) |
| 34 | parser.add_argument( |
Kuang-che Wu | 0ebbf7c | 2019-08-28 18:19:19 +0800 | [diff] [blame] | 35 | '--dut', |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 36 | type=cli.argtype_notempty, |
| 37 | metavar='DUT', |
| 38 | default=configure.get('DUT', '')) |
| 39 | parser.add_argument( |
| 40 | 'build_id', |
| 41 | nargs='?', |
| 42 | type=android_util.argtype_android_build_id, |
| 43 | metavar='ANDROID_BUILD_ID', |
| 44 | default=configure.get('ANDROID_BUILD_ID', '')) |
| 45 | parser.add_argument( |
| 46 | '--flavor', |
| 47 | metavar='ANDROID_FLAVOR', |
| 48 | default=configure.get('ANDROID_FLAVOR'), |
| 49 | help='example: cheets_x86-user') |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 50 | |
| 51 | return parser |
| 52 | |
| 53 | |
| 54 | def main(args=None): |
| 55 | common.init() |
| 56 | parser = create_argument_parser() |
| 57 | opts = parser.parse_args(args) |
| 58 | common.config_logging(opts) |
| 59 | |
| 60 | if not opts.flavor: |
| 61 | opts.flavor = arc_util.query_flavor(opts.dut) |
| 62 | assert opts.flavor |
| 63 | logger.info('use flavor=%s', opts.flavor) |
| 64 | |
Kuang-che Wu | d18cd5b | 2019-08-20 14:14:21 +0800 | [diff] [blame] | 65 | if not cros_util.is_good_dut(opts.dut): |
| 66 | logger.fatal('%r is not a good DUT', opts.dut) |
| 67 | if not cros_lab_util.repair(opts.dut): |
| 68 | sys.exit(cli.EXIT_CODE_FATAL) |
| 69 | |
Kuang-che Wu | 94ef56e | 2019-01-15 21:17:42 +0800 | [diff] [blame] | 70 | 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] | 71 | |
| 72 | arc_version = cros_util.query_dut_lsb_release( |
| 73 | opts.dut).get('CHROMEOS_ARC_VERSION') |
| 74 | if str(opts.build_id) in arc_version: |
| 75 | logger.info('updated to "%s", done', arc_version) |
| 76 | else: |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 77 | raise errors.ExecutionFatalError( |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 78 | 'arc version is expected matching "%s" but actual "%s"' % |
| 79 | (opts.build_id, arc_version)) |
| 80 | |
| 81 | |
| 82 | if __name__ == '__main__': |
| 83 | main() |