SEARCH
NEW RPMS
DIRECTORIES
ABOUT
FAQ
VARIOUS
BLOG
DONATE


YUM REPOSITORY

 
 

RPM

Section: User Contributed Perl Documentation (3)
Updated: 2007-05-28
Index 

NAME

RPM - Perl bindings for the RPM Package Manager API 

SYNOPSIS

  use RPM;

  my $db = RPM->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 = RPM->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 RPM module provides an object-oriented interface to querying boththe installed RPM database as well as files on the filesystem. 

CLASS METHODS

Pretty much all use of the class starts here. There are three mainentrypoints into the package --- either through the database ofinstalled rpms (aka the rpmdb), through a file on the filesystem(such as kernel-2.4.9-31.src.rpm or kernel-2.4.9-31.i386.rpm, or viaan rpm transaction.

You can have multiple RPM databases open at once, as well as runningmultiple queries on each. That being said if you expect to run a transactionto install or erase some rpms, you will need to cause any RPM::DB and RPM::PackageIterator objects to go out of scope. For instance:

        $db = RPM->open_rpm_db();        $i  = $db->find_by_name("vim");        $t  = create_transaction();        while($pkg = $i->next()) {           $t->add_erase($pkg);        }        $t->run();

Would end up in a dead lock waiting for $db, and $i (the RPM::DB and RPM::PackageIterator) objects to releaase 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 RPM::DB and RPM::PackageIterator objects togo out of scope.

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(RPM->vsf_default)
Creates an RPM::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:
RPM->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 thevarious hash and signature formats that rpm supports.
RPM->vsf_nohdrchk
Don't check the header.
RPM->vsf_needpayload
Require that a files payload be part of the RPM (Chip is this right?).
RPM->vsf_nosha1header
RPM->vsf_nomd5header
RPM->vsf_nodsaheader
RPM->vsf_norsaheader
RPM->vsf_nosha1
RPM->vsf_nomd5
RPM->vsf_nodsa
RPM->vsf_norsa
 

RPM DB object methods

find_all_iter()
Returns an iterator object that iterates over the entire database.
find_all()
Returns an list of all of the results of the find_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 a database iterator, then you simply need to stepthrough all the different package headers in the result set via theiterator.
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. oftenthe email address of the author of the entry), and "text" (the text of theentry).
 

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 ran. When run the updates to the system and the rpm database aretreated as on ``transaction'' which is assigned a transaction id. This canbe queried in install packages as the INSTALLTID, and for repackaged packagesthey have the REMOVETID set.
add_install($pkg, $upgrade)
Adds a package to a transaction for installation. If you want this tobe done as a package upgrade, then be sure to set the second optionalparameter to 1. It will return 0 on failure and 1 on 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 shouldcome 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 theinstall and erase elements.
close_db()
Closes the rpm database. This is needed for some ordering oftransactions for non-install purposes.
check()
Verify that the dependencies for this transaction are met. Returns0 on failure and 1 on success.
order()
Order the elements in dependency order.
elements()
Return a list of elements as they are presently ordered. Note, thisreturns the NEVR's not the package headers.
run()
Run the transaction. This will automatically check for dependencysatisfaction, and order the transaction.
 

TODO

Make package installation and removal better (-;.

Signature validation. 

HISTORY

0.01 Initial release
 

AUTHOR

Chip Turner <cturnerAATTredhat.com> 

SEE ALSO

perl.The original RPM module.


 

Index

NAME
SYNOPSIS
DESCRIPTION
CLASS METHODS
RPM DB object methods
RPM Database Iterator Methods
RPM Header object methods
Transaction object methods
TODO
HISTORY
AUTHOR
SEE ALSO

This document was created byman2html,using the manual pages.