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