RPM repository metadata parser.
For tools that use RepomdParser, see repo-tools repository.
This gem can parse repomd.xml, primary.xml and deltainfo.xml metadata files of the RPM repository,
providing a way to get access to the list of packages in the repo and the details of each individual package (name, size, checksum, etc.)
- Add
gem 'repomd_parser'line to your application's Gemfile; - Execute
bundle.
Alternatively, install as gem install repomd_parser.
Parses repomd.xml -- the main repository metadata file, which references other metadata files.
parse and parse_file methods return an array of RepomdParser::Reference.
File.open('repomd.xml') do |fh|
metadata_files = RepomdParser::RepomdXmlParser.new.parse(fh)
metadata_files.each do |metadata_file|
printf "type: %10s, location: %s\n", metadata_file.type, metadata_file.location
end
endmetadata_files = RepomdParser::RepomdXmlParser.new.parse_file('repomd.xml')
metadata_files.each do |metadata_file|
printf "type: %10s, location: %s\n", metadata_file.type, metadata_file.location
endParses primary.xml, which contains information about RPM packages in the repository.
parse and parse_file methods return an array of RepomdParser::Reference.
File.open('primary.xml') do |fh|
rpm_packages = RepomdParser::PrimaryXmlParser.new.parse(fh)
rpm_packages.each do |rpm|
printf "arch: %8s, location: %s\n", rpm.arch, rpm.location
end
endrpm_packages = RepomdParser::PrimaryXmlParser.new.parse_file('primary.xml')
rpm_packages.each do |rpm|
printf "arch: %8s, location: %s\n", rpm.arch, rpm.location
endParses deltainfo.xml, which contains information about delta-RPM packages in the repository.
parse and parse_file methods return an array of RepomdParser::Reference.
File.open('deltainfo.xml') do |fh|
rpm_packages = RepomdParser::DeltainfoXmlParser.new.parse(fh)
rpm_packages.each do |rpm|
printf "arch: %8s, location: %s\n", rpm.arch, rpm.location
end
endrpm_packages = RepomdParser::DeltainfoXmlParser.new.parse_file('deltainfo.xml')
rpm_packages.each do |rpm|
printf "arch: %8s, location: %s\n", rpm.arch, rpm.location
endThe gzip and Zstandard compression formats are supported. The parse_file
method automatically decompresses files based on the filename, e.g.:
rpm_packages = RepomdParser::PrimaryXmlParser.new.parse_file('primary.xml.gz')
rpm_packages.each do |rpm|
printf "arch: %8s, location: %s\n", rpm.arch, rpm.location
endThe RepomdParser.decompress_io helper is provided to handle
decompression of IO objects for use with the parse method:
filename = 'primary.xml.gz'
io = RepomdParser.decompress_io(File.open(filename), filename)
rpm_packages = RepomdParser::PrimaryXmlParser.new.parse(io)
rpm_packages.each do |rpm|
printf "arch: %8s, location: %s\n", rpm.arch, rpm.location
endRepresents a file referenced in the metadata file. Has the following accessors:
location, relative to the root of the repository.checksum_type, e.g. SHA1, SHA256, MD5.checksum.type, type of the file, e.g.:primary,:deltainfo,:rpm,:drpm.sizein bytes.arch.
RPM and DRPM files additionally have the following attributes:
name.version.release.build_time.
- File extension is used to determine file compression type (expected
extensions are
.gzand.zstfor gzip and Zstandard respectively)
After checking out the repo, run bundle install to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/ikapelyukhin/repomd-parser.