Andrew Lamb | 16f02bf | 2019-11-04 14:44:34 -0700 | [diff] [blame] | 1 | # Copyright 2019 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 | """A CLI to do the replication described by a ReplicationConfig proto.""" |
| 6 | |
Mike Frysinger | 2c02406 | 2021-05-22 15:43:22 -0400 | [diff] [blame] | 7 | from chromite.third_party.google.protobuf import json_format |
Andrew Lamb | 16f02bf | 2019-11-04 14:44:34 -0700 | [diff] [blame] | 8 | |
| 9 | from chromite.api.gen.config import replication_config_pb2 |
| 10 | from chromite.lib import commandline |
| 11 | from chromite.lib import osutils |
| 12 | from chromite.lib import replication_lib |
| 13 | |
| 14 | |
| 15 | def GetParser(): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 16 | """Creates the argparse parser.""" |
| 17 | parser = commandline.ArgumentParser(description=__doc__) |
| 18 | subparsers = parser.add_subparsers() |
Andrew Lamb | 16f02bf | 2019-11-04 14:44:34 -0700 | [diff] [blame] | 19 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 20 | run_subparser = subparsers.add_parser("run", help="Run a ReplicationConfig") |
| 21 | run_subparser.add_argument( |
| 22 | "replication_config", help="Path to the ReplicationConfig JSONPB" |
| 23 | ) |
| 24 | run_subparser.set_defaults(func=Run) |
Andrew Lamb | 16f02bf | 2019-11-04 14:44:34 -0700 | [diff] [blame] | 25 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 26 | return parser |
Andrew Lamb | 16f02bf | 2019-11-04 14:44:34 -0700 | [diff] [blame] | 27 | |
| 28 | |
| 29 | def Run(options): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 30 | """Runs the replication described by a PrelicationConfig proto.""" |
| 31 | replication_config = json_format.Parse( |
| 32 | osutils.ReadFile(options.replication_config), |
| 33 | replication_config_pb2.ReplicationConfig(), |
| 34 | ) |
Andrew Lamb | 16f02bf | 2019-11-04 14:44:34 -0700 | [diff] [blame] | 35 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 36 | replication_lib.Replicate(replication_config) |
Andrew Lamb | 16f02bf | 2019-11-04 14:44:34 -0700 | [diff] [blame] | 37 | |
| 38 | |
| 39 | def main(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 40 | parser = GetParser() |
| 41 | options = parser.parse_args(argv) |
| 42 | options.Freeze() |
Andrew Lamb | 16f02bf | 2019-11-04 14:44:34 -0700 | [diff] [blame] | 43 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 44 | options.func(options) |