blob: f9d708319b874aa6a189570129b2654eb0202b7f [file] [log] [blame]
Andrew Lamb16f02bf2019-11-04 14:44:34 -07001# -*- 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
8from __future__ import print_function
9
10from google.protobuf import json_format
11
12from chromite.api.gen.config import replication_config_pb2
13from chromite.lib import commandline
14from chromite.lib import osutils
15from chromite.lib import replication_lib
16
17
18def 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
31def 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
41def main(argv):
42 parser = GetParser()
43 options = parser.parse_args(argv)
44
45 options.func(options)