#!/usr/bin/env ruby require 'json' require 'zlib' require 'xmlsimple' require 'active_support/core_ext/hash' specs_to_delete = ['kata-micro-kernel'] puts "Specs to delete: #{specs_to_delete}" repo_path = ARGV[0] action = ARGV[1] || '' primary_xml_gz = Dir.entries("#{repo_path}/current/repodata").select { |file| file.match 'primary.xml.gz' }[0] primary_xml_content = Zlib::GzipReader.open("#{repo_path}/current/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 for spec in specs_to_delete if src_rpm.match? "^#{spec}-[^-]+-[^-]+.rpm$" spec_rpm_list.append(rpm_href) end end end puts spec_rpm_list if action == 'd' for rpm in spec_rpm_list %x(rm -f #{repo_path}/current/Packages/#{rpm}) end else exit end #puts JSON.pretty_generate rpms_list