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 ##############################################################################
19 """Object representing a repo listed in the release file.
21 Includes eq, hash, and ne methods so set comparisons work
24 def __init__(self, repo=None, ref=None, version=None):
27 self.version = version
31 return "%s %s %s" % (self.repo, self.ref, self.version)
33 return "%s %s" % (self.repo, self.ref)
34 return "%s" % self.repo
36 def __eq__(self, obj):
37 if isinstance(obj, Repo):
38 return ((self.repo == obj.repo) and
39 (self.ref == obj.ref) and
40 (self.version == obj.version))
43 def __ne__(self, obj):
44 return (not self.__eq__(obj))
47 return hash(self.__repr__())
51 """Given a release yamlfile list the repos it contains"""
53 parser = argparse.ArgumentParser()
54 parser.add_argument('--file', '-f',
55 type=argparse.FileType('r'),
57 parser.add_argument('--names', '-n',
60 help="Only print the names of repos, "
62 parser.add_argument('--release', '-r',
65 "SHAs for the specified release")
66 parser.add_argument('--branches', '-b',
69 help="Print Branch info")
71 args = parser.parse_args()
73 project = yaml.safe_load(args.file)
76 list_branches(project, args)
78 list_repos(project, args)
81 def list_repos(project, args):
82 """List repositories in the project file"""
84 lookup = project.get('releases', [])
86 if 'releases' not in project:
90 repo, ref = next(iter(item['location'].items()))
93 elif args.release and item['version'] == args.release:
94 repos.add(Repo(repo, ref))
95 elif not args.release:
96 repos.add(Repo(repo, item['version'], ref))
101 def list_branches(project, args):
102 """List branches in the project file"""
104 lookup = project.get('branches', [])
106 if 'branches' not in project:
110 repo, ref = next(iter(item['location'].items()))
112 repos.add(Repo(repo))
113 elif args.release and item['name'] == args.release:
114 repos.add(Repo(repo, ref))
115 elif not args.release:
116 repos.add(Repo(repo, item['name'], ref))
120 if __name__ == "__main__":