blob: 602aa16ab28a6d6e7e7ee25414799347312be328 [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
Mike Frysinger2c024062021-05-22 15:43:22 -04007from chromite.third_party.google.protobuf import json_format
Andrew Lamb16f02bf2019-11-04 14:44:34 -07008
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():
Alex Klein1699fab2022-09-08 08:46:06 -060016 """Creates the argparse parser."""
17 parser = commandline.ArgumentParser(description=__doc__)
18 subparsers = parser.add_subparsers()
Andrew Lamb16f02bf2019-11-04 14:44:34 -070019
Alex Klein1699fab2022-09-08 08:46:06 -060020 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 Lamb16f02bf2019-11-04 14:44:34 -070025
Alex Klein1699fab2022-09-08 08:46:06 -060026 return parser
Andrew Lamb16f02bf2019-11-04 14:44:34 -070027
28
29def Run(options):
Alex Klein1699fab2022-09-08 08:46:06 -060030 """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 Lamb16f02bf2019-11-04 14:44:34 -070035
Alex Klein1699fab2022-09-08 08:46:06 -060036 replication_lib.Replicate(replication_config)
Andrew Lamb16f02bf2019-11-04 14:44:34 -070037
38
39def main(argv):
Alex Klein1699fab2022-09-08 08:46:06 -060040 parser = GetParser()
41 options = parser.parse_args(argv)
42 options.Freeze()
Andrew Lamb16f02bf2019-11-04 14:44:34 -070043
Alex Klein1699fab2022-09-08 08:46:06 -060044 options.func(options)