Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame^] | 1 | #!/usr/bin/env python2 |
| 2 | # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | """Switcher for ChromeOS prebuilt""" |
| 6 | |
| 7 | from __future__ import print_function |
| 8 | import argparse |
| 9 | import logging |
| 10 | import os |
| 11 | |
| 12 | from bisect_kit import cli |
| 13 | from bisect_kit import common |
| 14 | from bisect_kit import configure |
| 15 | from bisect_kit import cros_util |
| 16 | |
| 17 | logger = logging.getLogger(__name__) |
| 18 | |
| 19 | |
| 20 | def create_argument_parser(): |
| 21 | parser = argparse.ArgumentParser(description=__doc__) |
| 22 | common.add_common_arguments(parser) |
| 23 | parser.add_argument( |
| 24 | 'dut', |
| 25 | nargs='?', |
| 26 | type=cli.argtype_notempty, |
| 27 | metavar='DUT', |
| 28 | default=configure.get('DUT', '')) |
| 29 | parser.add_argument( |
| 30 | 'version', |
| 31 | nargs='?', |
| 32 | type=cros_util.argtype_cros_version, |
| 33 | metavar='CROS_VERSION', |
| 34 | default=configure.get('CROS_VERSION', ''), |
| 35 | help='ChromeOS version number, short (10162.0.0) or full (R64-10162.0.0)') |
| 36 | parser.add_argument( |
| 37 | '--board', |
| 38 | metavar='BOARD', |
| 39 | default=configure.get('BOARD', ''), |
| 40 | help='ChromeOS board name') |
| 41 | parser.add_argument( |
| 42 | '--clobber-stateful', |
| 43 | action='store_true', |
| 44 | help='Clobber stateful partition when performing update') |
| 45 | parser.add_argument( |
| 46 | '--no-disable-rootfs-verification', |
| 47 | dest='disable_rootfs_verification', |
| 48 | action='store_false', |
| 49 | help="Don't disable rootfs verification after update is completed") |
| 50 | parser.add_argument( |
| 51 | '--default_chromeos_root', |
| 52 | type=cli.argtype_dir_path, |
| 53 | default=configure.get('DEFAULT_CHROMEOS_ROOT', |
| 54 | os.path.expanduser('~/chromiunos')), |
| 55 | help='Default chromeos tree to run "cros flash" (default: %(default)s)') |
| 56 | |
| 57 | return parser |
| 58 | |
| 59 | |
| 60 | def main(args=None): |
| 61 | common.init() |
| 62 | parser = create_argument_parser() |
| 63 | opts = parser.parse_args(args) |
| 64 | common.config_logging(opts) |
| 65 | |
| 66 | assert cros_util.is_dut(opts.dut) |
| 67 | board = opts.board or cros_util.query_dut_board(opts.dut) |
| 68 | |
| 69 | cros_util.cros_flash( |
| 70 | opts.default_chromeos_root, |
| 71 | opts.dut, |
| 72 | board, |
| 73 | opts.version, |
| 74 | clobber_stateful=opts.clobber_stateful, |
| 75 | disable_rootfs_verification=opts.disable_rootfs_verification) |
| 76 | |
| 77 | |
| 78 | if __name__ == '__main__': |
| 79 | main() |