misc_rbtools/command_line/rpm_package_changelog_pull.rb

23 lines
852 B
Ruby
Raw Permalink Normal View History

2020-10-09 14:44:03 -05:00
#!/usr/bin/env ruby
# this program will lookup an rpm pkg and create a json of the changes
require 'pry'
require 'json'
require 'digest'
pkgname = ARGV[0]
# gives us an array of hashes where each element looks like [{:date => date, :name => name}]
rpm_name_and_date_query= `rpm -q --qf '[date:%{CHANGELOGTIME:day}\nname:%{CHANGELOGNAME}\n]' #{pkgname}`.split("\n").each_slice(2).map {|s| s.map {|r| r.split(":")}.to_h}
# we add in the ascii code for record separator in our query to split this afterwards so we get an array of each changelog item
split_char = '&#030'
rpm_text_query = `rpm -q --qf '[%{CHANGELOGTEXT}#{split_char}]' #{pkgname}`.split(split_char)
hashed_changes = rpm_text_query.map {|changetext| hash = Digest::SHA2.hexdigest changetext; {"checksum" => hash} }
results = rpm_name_and_date_query.zip(hashed_changes)
binding.pry