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(): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 18 | """Creates the argparse parser. |
Alec Thilenius | bdff670 | 2018-12-06 11:40:24 -0700 | [diff] [blame] | 19 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 20 | Returns: |
| 21 | commandline.ArgumentParser: The argument parser. |
| 22 | """ |
| 23 | parser = commandline.ArgumentParser(description=__doc__) |
| 24 | parser.add_argument( |
| 25 | "--manifest-file", |
| 26 | type="path", |
| 27 | help="File path to a manifest to search.", |
| 28 | ) |
| 29 | parser.add_argument( |
| 30 | "--project", required=True, help="The project to search for." |
| 31 | ) |
| 32 | parser.add_argument( |
| 33 | "--branch", default="master", help="The branch to search for." |
| 34 | ) |
| 35 | return parser |
Alec Thilenius | bdff670 | 2018-12-06 11:40:24 -0700 | [diff] [blame] | 36 | |
| 37 | |
| 38 | def main(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame^] | 39 | parser = get_parser() |
| 40 | options = parser.parse_args(argv) |
| 41 | options.Freeze() |
| 42 | if options.manifest_file: |
| 43 | manifest = repo_manifest.Manifest.FromFile(options.manifest_file) |
| 44 | else: |
| 45 | manifest = repo_util.Repository.MustFind(__file__).Manifest() |
| 46 | print(manifest.GetUniqueProject(options.project, options.branch).Path()) |