Added a find_project_path script, updated repo_manifest lib
Updated the repo_manifest.Manifest.GetUniqueProject method to also
optionally search branches. Added a find_project_path script that
will call this method from the command line on either an explicit
manifest file path, or search for the manifest.
Bug: 904930
Change-Id: I558e4685aba7c71dd0cabb0e130cd245a28bcb52
Reviewed-on: https://chromium-review.googlesource.com/1366217
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Alec Thilenius <athilenius@google.com>
Reviewed-by: Lann Martin <lannm@chromium.org>
diff --git a/scripts/find_project_path.py b/scripts/find_project_path.py
new file mode 100644
index 0000000..7b9ad56
--- /dev/null
+++ b/scripts/find_project_path.py
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+# Copyright 2018 The Chromium OS Authors. All rights reserved.
+# 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 __future__ import print_function
+
+from chromite.lib import commandline
+from chromite.lib import repo_manifest
+from chromite.lib import repo_util
+
+
+def get_parser():
+ """Creates the argparse parser.
+
+ Returns:
+ commandline.ArgumentParser: The argument parser.
+ """
+ parser = commandline.ArgumentParser(description=__doc__)
+ parser.add_argument('--manifest-file', type='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):
+ 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())