Created
May 3, 2023 13:00
-
-
Save Yadunund/a333361145026073f16931fa69a13e14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (c) 2023, Yadunund Vijay | |
# All rights reserved. | |
# | |
# Redistribution and use in source and binary forms, with or without | |
# modification, are permitted provided that the following conditions are met: | |
# | |
# * Redistributions of source code must retain the above copyright | |
# notice, this list of conditions and the following disclaimer. | |
# * Redistributions in binary form must reproduce the above copyright | |
# notice, this list of conditions and the following disclaimer in the | |
# documentation and/or other materials provided with the distribution. | |
# * Neither the name of the Willow Garage, Inc. nor the names of its | |
# contributors may be used to endorse or promote products derived from | |
# this software without specific prior written permission. | |
# | |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
# POSSIBILITY OF SUCH DAMAGE. | |
import argparse | |
import os | |
import sys | |
import yaml | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-r', '--repos', type=str, help='Path to repos.yaml file', required=True) | |
parser.add_argument('-D', '--distribution', type=str, help='Path to distribution.yaml file', required=True) | |
parser.add_argument('-d', '--distro', type=str, help='The ROS 2 distro codename', default='iron', required=True) | |
args = parser.parse_args() | |
with open(args.repos, 'r') as f: | |
repos_yaml = yaml.safe_load(f) | |
core_repos = [] | |
for repo in repos_yaml['repositories']: | |
repo_dict = repos_yaml['repositories'][repo] | |
if repo_dict["version"] == args.distro: | |
core_repos.append(repo.split('/')[-1]) | |
print(f"{len(core_repos)} core pkgs with branch {args.distro}: {core_repos}") | |
updated_pkgs = [] | |
distro_yaml = {} | |
with open(args.distribution, 'r') as f: | |
distro_yaml = yaml.safe_load(f) | |
for repo in distro_yaml['repositories']: | |
repo_dict = distro_yaml['repositories'][repo] | |
if repo not in core_repos: | |
print(f"Package '{repo}' is not a core pkg, skipping") | |
continue | |
if not 'source' in repo_dict: | |
print(f"Package '{repo}' has no source entry, skipping") | |
continue | |
curr_version = repo_dict['source']['version'] | |
print(f"Current version of {repo} is {curr_version}") | |
if curr_version != args.distro: | |
print(f"Package {repo} has source version {repo_dict['source']['version']} which does not match {args.distro}") | |
repo_dict['source']['version'] = args.distro | |
if not 'doc' in repo_dict: | |
print(f"Package '{repo}' has no doc entry, skipping") | |
continue | |
doc_version = repo_dict['doc']['version'] | |
print(f"Current doc version of {repo} is {doc_version}") | |
if doc_version != args.distro: | |
print(f"Package {repo} has source version {repo_dict['source']['version']} which does not match {args.distro}") | |
repo_dict['doc']['version'] = args.distro | |
updated_pkgs.append(repo) | |
print(f"Versions of {len(updated_pkgs)} core pkgs were updated to {args.distro}: {updated_pkgs}") | |
with (open("distribution.yaml", 'w') as f): | |
yaml.dump(distro_yaml, f) | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment