diff --git a/Earthfile b/Earthfile index c6ab04f6..8593e11f 100644 --- a/Earthfile +++ b/Earthfile @@ -33,7 +33,7 @@ setup: RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null # Install repos file generator script requirements. - RUN apt-get install -y python3-rosinstall-generator ruby + RUN apt-get install -y python3-rosinstall-generator repos-file: FROM +setup @@ -48,7 +48,7 @@ repos-file: --outfile ros2.repos \ --packages spaceros-pkgs.txt \ --excluded-packages excluded-pkgs.txt - RUN --no-cache ruby scripts/merge-repos.rb + RUN --no-cache python3 scripts/merge-repos.py # Save the generated .repos file SAVE ARTIFACT ros2.repos AS LOCAL ros2.repos diff --git a/scripts/merge-repos.py b/scripts/merge-repos.py new file mode 100644 index 00000000..7d01a1a9 --- /dev/null +++ b/scripts/merge-repos.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +import yaml + +# Load YAML repos files +with open('ros2.repos', 'r') as ros2_file: + ros2 = yaml.safe_load(ros2_file) + +with open('spaceros.repos', 'r') as spaceros_file: + spaceros = yaml.safe_load(spaceros_file) + +# Merge repos +for repo, data in spaceros['repositories'].items(): + ros2['repositories'][repo] = data + +# Sort repositories and create a new ordered dictionary +sorted_repositories = {repo: ros2['repositories'][repo] for repo in sorted(ros2['repositories'].keys())} +ros2['repositories'] = sorted_repositories + +# Write the updated YAML back to file +with open('ros2.repos', 'w') as ros2_file: + yaml.dump(ros2, ros2_file, default_flow_style=False, explicit_start=True) diff --git a/scripts/merge-repos.rb b/scripts/merge-repos.rb deleted file mode 100644 index e4cd9859..00000000 --- a/scripts/merge-repos.rb +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env ruby - - -require "yaml" - -ros2 = YAML.load_file "ros2.repos" -spaceros = YAML.load_file "spaceros.repos" - - -spaceros["repositories"].each do |repo, data| - ros2["repositories"][repo] = data -end - -# Create a new hash so values can be inserted in sort-order. -repositories = Hash.new -ros2["repositories"].keys.sort.each do |repo| - repositories[repo] = ros2["repositories"][repo] -end -ros2["repositories"] = repositories - - -File.write("ros2.repos", YAML.dump(ros2))