blob: 36048634ad47867d31bf7ec46b26462aa6feee4a [file] [log] [blame]
Alec Thileniusbdff6702018-12-06 11:40:24 -07001# 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
7Uses both a project name and a branch name to search the manifest file for a
8matching path entry, printing the path to stdout if found and raising an
9exception if no match can be found.
10"""
11
Alec Thileniusbdff6702018-12-06 11:40:24 -070012from chromite.lib import commandline
Alec Thileniusbdff6702018-12-06 11:40:24 -070013from chromite.lib import repo_util
Mike Frysingerbf347822022-03-28 19:58:37 -040014from chromite.utils import repo_manifest
Alec Thileniusbdff6702018-12-06 11:40:24 -070015
16
Alec Thileniusbdff6702018-12-06 11:40:24 -070017def get_parser():
Alex Klein1699fab2022-09-08 08:46:06 -060018 """Creates the argparse parser.
Alec Thileniusbdff6702018-12-06 11:40:24 -070019
Alex Klein1699fab2022-09-08 08:46:06 -060020 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 Thileniusbdff6702018-12-06 11:40:24 -070036
37
38def main(argv):
Alex Klein1699fab2022-09-08 08:46:06 -060039 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())