#!/usr/bin/env ruby require 'json' require 'zlib' require 'xmlsimple' require 'active_support/core_ext/hash' spec = 'less' primary_xml_gz = Dir.entries('repodata').select { |file| file.match 'primary.xml.gz' }[0] primary_xml_content = Zlib::GzipReader.open("repodata/#{primary_xml_gz}").read doc = XmlSimple.xml_in(primary_xml_content) rpms_list = doc['package'] spec_rpm_list = [] rpms_list.each do |rpm_info| rpm_href = rpm_info['location'][0]['href'].split('/')[-1] src_rpm = if rpm_href.match? '.src.rpm' rpm_href else rpm_info['format'].first['sourcerpm'][0] end if src_rpm.match? "^#{spec}-[^-]+-[^-]+.rpm$" spec_rpm_list.append(rpm_href) end end puts spec_rpm_list #puts JSON.pretty_generate rpms_list