Created
March 20, 2023 21:47
-
-
Save op-ct/dd927ad0cd47cacb697411e48038dcd6 to your computer and use it in GitHub Desktop.
Quick & dirty RELENG check to fix/check for discrepancies between simp.spec deps and simp/simp_core's metadata.json
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
#!/opt/puppetlabs/bolt/bin/ruby | |
def get_rpm_spec_core(rpm_spec) | |
rpm_spec_core = { | |
requires: [], | |
obsoletes: [], | |
} | |
rpm_spec.select!{ |x| x =~ /^(Requires:|Obsoletes:|# Core SIMP Requirements|# SIMP Extras)/ } | |
in_core = false | |
rpm_spec.each do |x| | |
x.chomp! | |
break if x =~ /^# SIMP Extras/ | |
in_core = true if x =~ /^# Core SIMP Req/ | |
next unless x =~ /^(Requires|Obsoletes):/ | |
y = x.split(/: +/) | |
y[0] = y.first.downcase.to_sym | |
next unless y.last =~ /^pupmod-/ | |
next unless in_core || y.first =~ /^obsoletes/ | |
z = y.last.gsub(/, pupmod-[a-z0-9_-]+/,'').split(/ /,2) | |
pup_slash = z.first.gsub(/pupmod-([^-]+)-([^- ])/,'\1/\2') | |
rpm_spec_core[y.first] << { | |
"name" => pup_slash, | |
"version_requirement" => z.last, | |
} | |
end | |
rpm_spec_core | |
end | |
rpm_spec = File.readlines('src/assets/simp/build/simp.spec') | |
rpm_spec_core = get_rpm_spec_core(rpm_spec) | |
require 'json' | |
#m1 = JSON.parse(File.read('x.json')) | |
m1 = rpm_spec_core[:requires] | |
m2 = JSON.parse(File.read('metadata.json'))['dependencies'] | |
md = JSON.parse(File.read('metadata.json')) | |
required={ | |
missing: [], | |
match: [], | |
mismatch: [], | |
obsoleted: [], | |
} | |
m1.each do |x| | |
m2a = m2.select{|a| a['name'] == x['name'] } | |
if m2a.empty? | |
required[:missing] << x | |
elsif m2a == [x] | |
required[:match] << x | |
else | |
required[:mismatch] << x | |
end | |
end | |
rpm_spec_core[:obsoletes].each do |obsolete| | |
m2a = m2.select{|a| a['name'] == obsolete['name'] } | |
next if m2a.empty? | |
if m2a == [obsolete] | |
required[:obsoletes] << obsoletes + { 'md_pup_entry' => m2a } | |
end | |
end | |
require 'yaml' | |
File.open("required_pupmod_rpms.yaml", 'w'){|f| f.puts required.to_yaml } | |
m2new = m2.dup | |
required[:mismatch].each do |mm| | |
m2new.reject!{|x| x['name'] == mm['name'] } | |
m2new << mm | |
end | |
md['dependencies']=m2new | |
File.open("metadata.new.json", 'w'){|f| f.puts JSON.pretty_generate(md) } | |
require 'pry'; binding.pry | |
puts 'FINIS' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment