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 | |
Andrew Lamb | 16f02bf | 2019-11-04 14:44:34 -0700 | [diff] [blame] | 7 | from google.protobuf import json_format |
| 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(): |
| 16 | """Creates the argparse parser.""" |
| 17 | parser = commandline.ArgumentParser(description=__doc__) |
| 18 | subparsers = parser.add_subparsers() |
| 19 | |
| 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 | run_subparser.set_defaults(func=Run) |
| 24 | |
| 25 | return parser |
| 26 | |
| 27 | |
| 28 | def Run(options): |
| 29 | """Runs the replication described by a PrelicationConfig proto.""" |
| 30 | replication_config = json_format.Parse( |
| 31 | osutils.ReadFile(options.replication_config), |
| 32 | replication_config_pb2.ReplicationConfig(), |
| 33 | ) |
| 34 | |
| 35 | replication_lib.Replicate(replication_config) |
| 36 | |
| 37 | |
| 38 | def main(argv): |
| 39 | parser = GetParser() |
| 40 | options = parser.parse_args(argv) |
Andrew Lamb | fc2fd0f | 2019-11-17 10:04:30 -0700 | [diff] [blame] | 41 | options.Freeze() |
Andrew Lamb | 16f02bf | 2019-11-04 14:44:34 -0700 | [diff] [blame] | 42 | |
| 43 | options.func(options) |