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