Alec Thilenius | bdff670 | 2018-12-06 11:40:24 -0700 | [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 | """Find a project path from this chromiumos checkouts manifest file. |
| 7 | |
| 8 | Uses both a project name and a branch name to search the manifest file for a |
| 9 | matching path entry, printing the path to stdout if found and raising an |
| 10 | exception if no match can be found. |
| 11 | """ |
| 12 | |
| 13 | from __future__ import print_function |
| 14 | |
| 15 | from chromite.lib import commandline |
| 16 | from chromite.lib import repo_manifest |
| 17 | from chromite.lib import repo_util |
| 18 | |
| 19 | |
| 20 | def get_parser(): |
| 21 | """Creates the argparse parser. |
| 22 | |
| 23 | Returns: |
| 24 | commandline.ArgumentParser: The argument parser. |
| 25 | """ |
| 26 | parser = commandline.ArgumentParser(description=__doc__) |
| 27 | parser.add_argument('--manifest-file', type='path', |
| 28 | help='File path to a manifest to search.') |
| 29 | parser.add_argument('--project', required=True, |
| 30 | help='The project to search for.') |
| 31 | parser.add_argument('--branch', default='master', |
| 32 | help='The branch to search for.') |
| 33 | return parser |
| 34 | |
| 35 | |
| 36 | |
| 37 | def main(argv): |
| 38 | parser = get_parser() |
| 39 | options = parser.parse_args(argv) |
| 40 | options.Freeze() |
| 41 | if options.manifest_file: |
| 42 | manifest = repo_manifest.Manifest.FromFile(options.manifest_file) |
| 43 | else: |
| 44 | manifest = repo_util.Repository.MustFind(__file__).Manifest() |
| 45 | print(manifest.GetUniqueProject(options.project, options.branch).Path()) |