Lann Martin | 10f3ee9 | 2018-08-22 15:48:10 -0600 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2018 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 | """Sync a repo checkout to the given manifest file.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | import os |
| 11 | |
| 12 | from chromite.lib import commandline |
| 13 | from chromite.lib import repo_util |
| 14 | |
| 15 | |
| 16 | def GetParser(): |
| 17 | """Creates the argparse parser.""" |
| 18 | parser = commandline.ArgumentParser(description=__doc__) |
| 19 | parser.add_argument('manifest', type='path', |
| 20 | help='The manifest file to sync to.') |
| 21 | parser.add_argument('--repo-root', type='path', default='.', |
| 22 | help='Path to the repo root to sync.') |
| 23 | parser.add_argument('--copy-repo', type='path', |
| 24 | help='Path to an existing repo root; the .repo dir ' |
| 25 | 'there will be copied to the target repo root, ' |
| 26 | 'which must not be within an existing root.') |
| 27 | return parser |
| 28 | |
| 29 | |
| 30 | def main(argv): |
| 31 | parser = GetParser() |
| 32 | options = parser.parse_args(argv) |
| 33 | options.Freeze() |
| 34 | |
| 35 | # Assert manifest exists. |
| 36 | os.stat(options.manifest) |
| 37 | |
| 38 | if options.copy_repo: |
| 39 | copy_repo = repo_util.Repository(options.copy_repo) |
| 40 | copy_repo.Copy(options.repo_root) |
| 41 | |
| 42 | repo = repo_util.Repository(options.repo_root) |
| 43 | |
| 44 | repo.Sync(manifest_path=options.manifest) |