blob: 95f8a787cd600c12f2846fcbb005492cf2a012bc [file] [log] [blame]
Andrew Lamb16f02bf2019-11-04 14:44:34 -07001# 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 Lamb16f02bf2019-11-04 14:44:34 -07007from google.protobuf import json_format
8
9from chromite.api.gen.config import replication_config_pb2
10from chromite.lib import commandline
11from chromite.lib import osutils
12from chromite.lib import replication_lib
13
14
15def 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
28def 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
38def main(argv):
39 parser = GetParser()
40 options = parser.parse_args(argv)
Andrew Lambfc2fd0f2019-11-17 10:04:30 -070041 options.Freeze()
Andrew Lamb16f02bf2019-11-04 14:44:34 -070042
43 options.func(options)