RPM2(3)
πΈ NAME
okay so this is the RPM2(3) page from User Contributed Perl Documentation, and it's here to explain RPM2: Perl bindings for the RPM Package Manager API. That's the whole vibe: Perl + RPM, bestie π.
β¨ SYNOPSIS
Here's the code, unchanged, because we do not mess with code in this house:
use RPM2;
my $db = RPM2->open_rpm_db();
my $i = $db->find_all_iter();
print "The following packages are installed (aka, 'rpm -qa'):\n";
while (my $pkg = $i->next) {
print $pkg->as_nvre, "\n";
}
$i = $db->find_by_name_iter("kernel");
print "The following kernels are installed (aka, 'rpm -q kernel'):\n";
while (my $pkg = $i->next) {
print $pkg->as_nvre, " ", int($pkg->size()/1024), "k\n";
}
$i = $db->find_by_provides_iter("kernel");
print "The following packages provide 'kernel' (aka, 'rpm -q --whatprovides kernel'):\n";
while (my $pkg = $i->next) {
print $pkg->as_nvre, " ", int($pkg->size()/1024), "k\n";
}
print "The following packages are installed (aka, 'rpm -qa' once more):\n";
foreach my $pkg ($db->find_by_file("/bin/sh")) {
print $pkg->as_nvre, "\n";
}
my $pkg = RPM2->open_package("/tmp/XFree86-4.1.0-15.src.rpm");
print "Package opened: ", $pkg->as_nvre(), ", is source: ", $pkg->is_source_package, "\n";
π DESCRIPTION
The RPM2 module gives you an object-oriented interface to query both the installed RPM database and files on the filesystem. It's giving "talk to rpmdb and random rpm files without crying" energy β¨.
π CLASS METHODS
Pretty much all use of the class starts here. There are three main entrypoints into the package:
- through the database of installed rpms (aka the rpmdb),
- through a file on the filesystem (such as
kernel-2.4.9-31.src.rpmorkernel-2.4.9-31.i386.rpm), - or via an rpm transaction.
You can have multiple RPM databases open at once, as well as running multiple queries on each. That being said, if you expect to run a transaction to install or erase some rpms, you will need to cause any RPM2::DB and RPM2::PackageIterator objects to go out of scope. For instance:
$db = RPM2->open_rpm_db();
$i = $db->find_by_name("vim");
$t = create_transaction();
while($pkg = $i->next()) {
$t->add_erase($pkg);
}
$t->run();
β οΈ That would end up in a dead lock waiting for$db, and$i(theRPM2::DBandRPM2::PackageIterator) objects to release their read lock on the database. The correct way of handling this then would be to do the following before running the transaction:
$db = undef;
$i = undef;
That is to explicitly cause the RPM2::DB and RPM2::PackageIterator objects to go out of scope. Slay, but like, responsibly π
.
open_rpm_db(-path => "/path/to/db")β as it sounds, it opens the RPM database and returns it as an object. The path to the database (i.e.-path) is optional.open_package("foo-1.1-14.noarch.rpm")β opens a specific package (RPM or SRPM). Returns a Header object.create_transaction(RPM2->vsf_default)β creates anRPM2::Transaction. This can be used to install and remove packages. It also exposes the dependency ordering functionality. It takes as an optional argument verify signature flags. The following flags are available:RPM2->vsf_defaultβ you don't ever have to specify this, but you could if you wanted to do so. This will check headers, not require a files payload, and support all the various hash and signature formats that rpm supports.RPM2->vsf_nohdrchkβ don't check the header.RPM2->vsf_needpayloadβ require that a files payload be part of the RPM (Chip is this right?).RPM2->vsf_nosha1headerRPM2->vsf_nomd5headerRPM2->vsf_nodsaheaderRPM2->vsf_norsaheaderRPM2->vsf_nosha1RPM2->vsf_nomd5RPM2->vsf_nodsaRPM2->vsf_norsa
ποΈ RPM DB object methods
find_all_iter()β returns an iterator object that iterates over the entire database.find_all()β returns a list of all of the results of thefind_all_iter()method.find_by_file_iter($filename)β returns an iterator that returns all packages that contain a given file.find_by_file($filename)β ditto, except it just returns the list.find_by_name_iter($package_name)β you get the idea. This one is for iterating by package name.find_by_name($package_name)β ditto, except it returns a list.find_by_provides_iter($provides_string)β this one iterates over provides.find_by_provides($provides_string)β ditto, except it returns a list.find_by_requires_iter($requires_string)β this one iterates over requires.find_by_requires($requires_string)β ditto, except it returns a list.
π¦ RPM Database Iterator Methods
Once you have a database iterator, then you simply need to step through all the different package headers in the result set via the iterator.
next()β return the next package header in the result set.expand_iter()β return the list of all the package headers in the result set of the iterator.
π RPM Header object methods
In addition to the following methods, all tags have simple accessors; $hdr->epoch() is equivalent to $hdr->tag('epoch').
The <=> and cmp operators can be used to compare versions of two packages.
$hdr->tag($tagname)β returns the value of the tag$tagname.$hdr->tagformat($format)βTODO.$hdr->is_source_package()β returns a true value if the package is a source package, false otherwise.$hdr->filename()β returns the filename of the package.$hdr->offset()β returns the rpm database offset for the package.$hdr->as_nvre()β returns a string formatted like:
epoch:name-version-release
If epoch is undefined for this package, it and the leading colon are omitted.
$hdr->files()βTODO.$hdr->changelog()β returns a list of hash refs containing the change log data of the package. The hash keys represent individual change log entries, and their keys are:"time"(the time of the changelog entry),"name"(the"name", ie. often the email address of the author of the entry), and"text"(the text of the entry).
π₯ Transaction object methods
Transactions are what allow you to install, upgrade, and remove rpms. Transactions are created, have elements added to them (i.e. package headers) and are run. When run, the updates to the system and the rpm database are treated as one "transaction" which is assigned a transaction id. This can be queried in install packages as the INSTALLTID, and for repackaged packages they have the REMOVETID set.
add_install($pkg, $upgrade)β adds a package to a transaction for installation. If you want this to be done as a package upgrade, then be sure to set the second optional parameter to1. It will return0on failure and1on success. Note, this should be obvious, but the package header must come from an rpm file, not from the RPM database.add_erase($pkg)β adds a package to a transaction for erasure. The package header should come from the database (i.e. via an iterator) and not an rpm file.element_count()β returns the number of elements in a transaction (this is the sum of the install and erase elements).close_db()β closes the rpm database. This is needed for some ordering of transactions for non-install purposes.check()β verify that the dependencies for this transaction are met. Returns0on failure and1on success.order()β order the elements in dependency order.elements()β return a list of elements as they are presently ordered. Note, this returns theNEVR's not the package headers.run()β run the transaction. This will automatically check for dependency satisfaction, and order the transaction.
π§ TODO
- Make package installation and removal better (-;.
- Signature validation.
β HISTORY
0.01Initial release.0.68RPM 4.6 Support.0.69RPM 4.9 Support.
π AUTHORS
RPM2 was originally written by Chip Turner <cturner@pattern.net> and contributions were made by numerous authors. It is currently maintained by Lubomir Rintel <lkundrak@v3.sk>.
The source code is kept in a Git repository at <https://github.com/lkundrak/perl-RPM2.git>.
π΅οΈ BUGS
Report the bugs (and feature requests) at <http://rt.cpan.org/Public/Bug/Report.html?Queue=RPM2>. Alternatively, you can report a bug by sending mail to <bug-RPM2@rt.cpan.org>.
π LICENSE
This module is free software and is licensed under the same terms as Perl itself.
π SEE ALSO
perl. The original RPM module.
that's the whole page, bestie π β signed off by perl v5.32.1, dated 2023-01-20, from the RPM2(3) page π«Άβ¨
π¦ where this page comes from
- epel 9: perl-RPM2 1.4-22.el9 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms