blob: 7b9ad562cb68c781054ee7976ece87193b9a6874 [file] [log] [blame]
Alec Thileniusbdff6702018-12-06 11:40:24 -07001# -*- coding: utf-8 -*-
2# Copyright 2018 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Find a project path from this chromiumos checkouts manifest file.
7
8Uses both a project name and a branch name to search the manifest file for a
9matching path entry, printing the path to stdout if found and raising an
10exception if no match can be found.
11"""
12
13from __future__ import print_function
14
15from chromite.lib import commandline
16from chromite.lib import repo_manifest
17from chromite.lib import repo_util
18
19
20def get_parser():
21 """Creates the argparse parser.
22
23 Returns:
24 commandline.ArgumentParser: The argument parser.
25 """
26 parser = commandline.ArgumentParser(description=__doc__)
27 parser.add_argument('--manifest-file', type='path',
28 help='File path to a manifest to search.')
29 parser.add_argument('--project', required=True,
30 help='The project to search for.')
31 parser.add_argument('--branch', default='master',
32 help='The branch to search for.')
33 return parser
34
35
36
37def main(argv):
38 parser = get_parser()
39 options = parser.parse_args(argv)
40 options.Freeze()
41 if options.manifest_file:
42 manifest = repo_manifest.Manifest.FromFile(options.manifest_file)
43 else:
44 manifest = repo_util.Repository.MustFind(__file__).Manifest()
45 print(manifest.GetUniqueProject(options.project, options.branch).Path())