Alex Klein | e66c64d | 2018-09-11 10:27:49 -0600 | [diff] [blame] | 1 | # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Update or initialize the chroot version. |
| 6 | |
| 7 | The chroot version hooks provide manually created update files to handle |
| 8 | tasks that need to be manually run. See also `update_chroot` for updating |
| 9 | the toolchain and some other packages on the chroot. The `update_chroot` script |
| 10 | also calls this script. The chroot version and installed package versions are |
| 11 | not strongly correlated. |
| 12 | """ |
| 13 | |
Alex Klein | e66c64d | 2018-09-11 10:27:49 -0600 | [diff] [blame] | 14 | from chromite.lib import commandline |
| 15 | from chromite.lib import cros_build_lib |
| 16 | from chromite.lib import cros_sdk_lib |
| 17 | |
| 18 | |
| 19 | def GetParser(): |
| 20 | """Build the ArgumentParser.""" |
| 21 | parser = commandline.ArgumentParser(description=__doc__) |
| 22 | parser.add_argument('-i', '--init-latest', |
| 23 | action='store_true', default=False, |
| 24 | help='Create the version file with the latest version ' |
| 25 | "if it doesn't exist.") |
| 26 | |
| 27 | return parser |
| 28 | |
| 29 | |
| 30 | def _ParseArgs(argv): |
| 31 | """Parse arguments.""" |
| 32 | parser = GetParser() |
| 33 | |
| 34 | opts = parser.parse_args(argv) |
| 35 | opts.Freeze() |
| 36 | |
| 37 | return opts |
| 38 | |
| 39 | |
| 40 | def main(argv): |
| 41 | """Main function.""" |
| 42 | cros_build_lib.AssertInsideChroot() |
| 43 | |
| 44 | opts = _ParseArgs(argv) |
| 45 | |
| 46 | if opts.init_latest: |
| 47 | cros_sdk_lib.InitLatestVersion() |
| 48 | else: |
| 49 | try: |
| 50 | cros_sdk_lib.RunChrootVersionHooks() |
| 51 | except cros_sdk_lib.Error as e: |
Mike Frysinger | 6b5c3cd | 2019-08-27 16:51:00 -0400 | [diff] [blame] | 52 | cros_build_lib.Die(e) |