blob: 7af0955bd7c71dd94bd556b552a09f763184aa4f [file] [log] [blame]
Kuang-che Wu708310b2018-03-28 17:24:34 +08001#!/usr/bin/env python2
Kuang-che Wu6e4beca2018-06-27 17:45:02 +08002# -*- coding: utf-8 -*-
Kuang-che Wu708310b2018-03-28 17:24:34 +08003# 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
8Typical usage:
9 $ bisect_android_build_id.py config switch ./switch_arc_prebuilt.py
10
Kuang-che Wuacb6efd2018-04-25 18:52:58 +080011It is implemented by calling Android's push_to_device.py.
Kuang-che Wu708310b2018-03-28 17:24:34 +080012"""
13
14from __future__ import print_function
15import argparse
16import logging
17
18from bisect_kit import android_util
19from bisect_kit import arc_util
20from bisect_kit import cli
21from bisect_kit import common
22from bisect_kit import configure
Kuang-che Wu708310b2018-03-28 17:24:34 +080023from bisect_kit import cros_util
Kuang-che Wue121fae2018-11-09 16:18:39 +080024from bisect_kit import errors
Kuang-che Wu708310b2018-03-28 17:24:34 +080025
26logger = logging.getLogger(__name__)
27
28
29def create_argument_parser():
30 parser = argparse.ArgumentParser(description=__doc__)
31 common.add_common_arguments(parser)
32 parser.add_argument(
33 'dut',
34 nargs='?',
35 type=cli.argtype_notempty,
36 metavar='DUT',
37 default=configure.get('DUT', ''))
38 parser.add_argument(
39 'build_id',
40 nargs='?',
41 type=android_util.argtype_android_build_id,
42 metavar='ANDROID_BUILD_ID',
43 default=configure.get('ANDROID_BUILD_ID', ''))
44 parser.add_argument(
45 '--flavor',
46 metavar='ANDROID_FLAVOR',
47 default=configure.get('ANDROID_FLAVOR'),
48 help='example: cheets_x86-user')
Kuang-che Wu708310b2018-03-28 17:24:34 +080049
50 return parser
51
52
53def main(args=None):
54 common.init()
55 parser = create_argument_parser()
56 opts = parser.parse_args(args)
57 common.config_logging(opts)
58
59 if not opts.flavor:
60 opts.flavor = arc_util.query_flavor(opts.dut)
61 assert opts.flavor
62 logger.info('use flavor=%s', opts.flavor)
63
Kuang-che Wu94ef56e2019-01-15 21:17:42 +080064 arc_util.push_prebuilt_to_device(opts.dut, opts.flavor, opts.build_id)
Kuang-che Wu708310b2018-03-28 17:24:34 +080065
66 arc_version = cros_util.query_dut_lsb_release(
67 opts.dut).get('CHROMEOS_ARC_VERSION')
68 if str(opts.build_id) in arc_version:
69 logger.info('updated to "%s", done', arc_version)
70 else:
Kuang-che Wue121fae2018-11-09 16:18:39 +080071 raise errors.ExecutionFatalError(
Kuang-che Wu708310b2018-03-28 17:24:34 +080072 'arc version is expected matching "%s" but actual "%s"' %
73 (opts.build_id, arc_version))
74
75
76if __name__ == '__main__':
77 main()