Merge "updated auto.yaml with 6.1.0 commit"
[releng.git] / releases / scripts / repos.py
1 #!/usr/bin/env python2
2 # SPDX-License-Identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018 The Linux Foundation and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 """
11 List Release Repos
12 """
13
14 import argparse
15 import yaml
16
17
18 def main():
19     """Given a release yamlfile list the repos it contains"""
20
21     parser = argparse.ArgumentParser()
22     parser.add_argument('--file', '-f',
23                         type=argparse.FileType('r'),
24                         required=True)
25     parser.add_argument('--names', '-n',
26                         action='store_true',
27                         default=False,
28                         help="Only print the names of repos, "
29                              "not their SHAs")
30     parser.add_argument('--release', '-r',
31                         type=str,
32                         help="Only print"
33                              "SHAs for the specified release")
34     args = parser.parse_args()
35
36     project = yaml.safe_load(args.file)
37
38     list_repos(project, args)
39
40
41 def list_repos(project, args):
42     """List repositories in the project file"""
43
44     lookup = project.get('releases', [])
45     if 'releases' not in project:
46         exit(0)
47
48     for item in lookup:
49         repo, ref = next(iter(item['location'].items()))
50         if args.names:
51             print(repo)
52         elif args.release and item['version'] == args.release:
53             print("%s %s" % (repo, ref))
54         elif not args.release:
55             # Print all releases
56             print("%s %s %s" % (repo, item['version'], ref))
57
58
59 if __name__ == "__main__":
60     main()