blob: a7fa68be04e2220a8a768500375ba9cb2aae3939 [file] [log] [blame]
# Copyright 2018 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Find a project path from this chromiumos checkouts manifest file.
Uses both a project name and a branch name to search the manifest file for a
matching path entry, printing the path to stdout if found and raising an
exception if no match can be found.
"""
from chromite.lib import commandline
from chromite.lib import repo_util
from chromite.utils import repo_manifest
def get_parser():
"""Creates the argparse parser.
Returns:
commandline.ArgumentParser: The argument parser.
"""
parser = commandline.ArgumentParser(description=__doc__)
parser.add_argument(
"--manifest-file",
type="str_path",
help="File path to a manifest to search.",
)
parser.add_argument(
"--project", required=True, help="The project to search for."
)
parser.add_argument(
"--branch", default="master", help="The branch to search for."
)
return parser
def main(argv) -> None:
parser = get_parser()
options = parser.parse_args(argv)
options.Freeze()
if options.manifest_file:
manifest = repo_manifest.Manifest.FromFile(options.manifest_file)
else:
manifest = repo_util.Repository.MustFind(__file__).Manifest()
print(manifest.GetUniqueProject(options.project, options.branch).Path())