The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

URPM - Perl module to manipulate RPM files

SYNOPSIS

    use URPM;

    # using the local RPM database
    my $db = URPM::DB::open();
    $db->traverse(sub {
        my ($package) = @_; # this is a URPM::Package object
        print $package->filename, "\n";
        # ...
    });

    # loading and parsing a synthesis file
    my $urpm = new URPM;
    $urpm->parse_synthesis("synthesis.sample.cz");
    $urpm->traverse(sub {
        # retrieve all packages from the dependency list
        # ...
    });

DESCRIPTION

The URPM module allows you to manipulate RPM files, RPM header files and hdlist files and manage them in memory. It is notably used by the urpmi utility. It provides four classes : URPM, URPM::DB, URPM::Package, and URPM::Transaction.

The URPM class

URPM->new()

The constructor creates a new, empty URPM object. It's a blessed hash that contains two fields:

depslist is an arrayref containing the list of depending packages (which are URPM::Package objects).

provides is an hashref containing as keys the list of items provided by the URPM object.

If the constructor is called with the arguments nofatal => 1, various fatal error messages are suppressed (file not found in parse_hdlist() and parse_synthesis()).

URPM::read_config_files()

Force the re-reading of the RPM configuration files.

URPM::list_rpm_tag()

Returns a hash containing the key/id values of known rpm tags.

URPM::ranges_overlap($range1, $range2 [, $nopromoteepoch])

This utility function compares two version ranges, in order to calculate dependencies properly. The ranges have roughly the form

    [<|<=|==|=>|>] [epoch:]version[-release]

where epoch, version and release are RPM-style version numbers.

If the optional parameter $nopromoteepoch is true, and if the 2nd range has no epoch while the first one has one, then the 2nd range is assumed to have an epoch == 0.

$urpm->parse_synthesis($file, [ callback => sub {...} ])

This method gets the depslist and the provides from a synthesis file and adds them to the URPM object.

$urpm->parse_hdlist($file, %options)

This method loads rpm informations from rpm headers contained in an hdlist file and adds them to the URPM object. Allowed options are

    packing => 0 / 1
    callback => sub { ... }
    keep_all_tags => 0 / 1

The return value is a two-element array containing the first and the last id parsed.

$urpm->parse_rpms($files, %options)

This method loads rpm informations from rpm headers and adds them to the URPM object. The return value is a two-element array containing the first and the last id parsed.

$urpm->parse_rpm($file, %options)

This method gets the depslist and the provides from an RPM file and adds them to the URPM object. Allowed options are

    packing => 0 / 1
    keep_all_tags => 0 / 1
    callback => sub { ... }
$urpm->search($name, %options)

Search an RPM by name or by part of name in the list of RPMs represented by this $urpm. The behaviour of the search is influenced by several options:

    strict_name => 0 / 1
    strict_fullname => 0 / 1
    src => 0 / 1
$urpm->traverse($callback)

Executes the callback for each package in the depslist, passing a URPM::Package object as argument the callback.

$urpm->traverse_tag($tag, $names, $callback)

$tag may be one of name, whatprovides, whatrequires, whatconflicts, group, triggeredby, or path. $names is a reference to an array, holding the acceptable values of the said tag for the searched variables. Then, $callback is called for each matching package in the depslist.

URPM::verify_rpm($file, %options)

Verifies an RPM file. Recognized options are:

    db => $urpm_db
    nopgp => 0 / 1
    nogpg => 0 / 1
    nomd5 => 0 / 1
    norsa => 0 / 1
    nodsa => 0 / 1
    nodigests => 0 / 1
    tmp_filename => '...'
    nosignatures => 0 / 1 (equivalent to nopgp = nogpg = norsa = nodsa = 1)
$urpm->import_pubkey(%options)
    db => $urpm_db
    root => '...'
    block => '...'
    filename => '...'

The URPM::DB class

open($prefix, $write_perm)

Returns a new URPM::DB object pointing on the local RPM database.

$prefix defaults to "" and indicates the RPM DB root directory prefix if any. (See the --root option to rpm(1)).

$write_perm is a boolean that defaults to false, and that indicates whether the RPM DB should be open in read/write mode.

rebuild($prefix)

Rebuilds the RPM database (like rpm --rebuilddb). $prefix defaults to "".

$db->traverse($callback)

Executes the specified callback (a code reference) for each package in the DB, passing a URPM::Package object as argument the callback.

$db->traverse_tag($tag,$names,$callback)

$tag may be one of name, whatprovides, whatrequires, whatconflicts, group, triggeredby, or path. $names is a reference to an array, holding the acceptable values of the said tag for the searched variables. Then, $callback is called for each matching package in the DB.

$db->create_transaction($prefix)

Creates and returns a new transaction (an URPM::Transaction object) on the specified DB. For $prefix, cf open.

The URPM::Package class

Most methods of URPM::Package are accessors for the various properties of an RPM package.

$package->arch()

Gives the package architecture

$package->build_header($fileno)

Writes the rpm header to the specified file ($fileno being an integer).

$package->build_info($fileno, [$provides_files])

Writes a line of information in a synthesis file.

$package->buildarchs()
$package->buildhost()
$package->buildtime()
$package->changelog_name()
$package->changelog_text()
$package->changelog_time()
$package->compare($evr)
$package->compare_pkg($other_pkg)
$package->conf_files()
$package->conflicts()
$package->conflicts_nosense()
$package->description()
$package->distribution()
$package->epoch()
$package->excludearchs()
$package->exclusivearchs()
$package->filename()

The rpm's file name.

$package->files()

List of files in this rpm.

$package->files_flags()
$package->files_gid()
$package->files_group()
$package->files_md5sum()
$package->files_mode()
$package->files_mtime()
$package->files_owner()
$package->files_size()
$package->files_uid()
$package->flag($name)
$package->flag_available()
$package->flag_base()
$package->flag_disable_obsolete()
$package->flag_installed()
$package->flag_requested()
$package->flag_required()
$package->flag_selected()
$package->flag_skip()
$package->flag_upgrade()
$package->free_header()
$package->fullname()

Returns a 4 element list: name, version, release and architecture in an array context. Returns a string NAME-VERSION-RELEASE.ARCH in scalar context.

$package->get_tag($tagid)

Returns an array containing values of $tagid. $tagid is the numerical value of rpm tags. See rpmlib.h.

$package->queryformat($format)

Querying the package like rpm --queryformat do.

The function calls directly the rpmlib, then use header informations, so it silently failed if you use synthesis instead of hdlist/rpm/header files or rpmdb.

$package->get_tag_modifiers($tagid)

Return an array of human readable view of tag values. $tagid is the numerical value of rpm tags.

$package->group()
$package->header_filename()
$package->id()
$package->is_arch_compat()
$package->license()
$package->name()

The rpm's bare name.

$package->obsoletes()
$package->obsoletes_nosense()
$package->obsoletes_overlap($s, [$nopromoteepoch,] [$direction])
$package->os()
$package->pack_header()
$package->packager()
$package->payload_format()
$package->provides()
$package->provides_nosense()
$package->provides_overlap($s, [$nopromoteepoch,] [$direction])
$package->rate()
$package->release()
$package->requires()
$package->requires_nosense()
$package->rflags()
$package->set_flag($name, $value)
$package->set_flag_base($value)
$package->set_flag_disable_obsolete($value)
$package->set_flag_installed($value)
$package->set_flag_requested($value)
$package->set_flag_required($value)
$package->set_flag_skip($value)
$package->set_flag_upgrade($value)
$package->set_id($id)
$package->set_rate($rate)
$package->set_rflags(...)
$package->size()
$package->sourcerpm()
$package->summary()
$package->update_header($filename, ...)
$package->upgrade_files()
$package->url()
$package->vendor()
$package->version()

The URPM::Transaction class

$trans->set_script_fd($fileno)

Sets the transaction output filehandle.

$trans->add($pkg, %options)

Adds a package to be installed to the transaction represented by $trans. $pkg is an URPM::Package object.

Options are:

    update => 0 / 1 : indicates whether this is an upgrade
    excludepath => [ ... ]
$trans->remove($name)

Adds a package to be erased to the transaction represented by $trans. $name is the name of the package.

$trans->check(%options)

Checks that all dependencies can be resolved in this transaction.

Options are:

    translate_message => 0 / 1 (currently ignored.)

In list context, returns an array of problems (an empty array indicates success).

$trans->order()

Determines package order in a transaction set according to dependencies. In list context, returns an array of problems (an empty array indicates success).

$trans->run($data, %options)

Runs the transaction.

$data is an arbitrary user-provided piece of data to be passed to callbacks.

Recognized options are:

    callback_close  => sub { ... }
    callback_inst   => sub { ... }
    callback_open   => sub { ... }
    callback_trans  => sub { ... }
    callback_uninst => sub { ... }
    delta => used for progress callbacks (trans, uninst, inst)
    excludedocs => 0 / 1
    force => 0 / 1
    nosize => 0 / 1
    noscripts => 0 / 1
    oldpackage => 0 / 1
    test => 0 / 1
    translate_message => 1

They roughly correspond to command-line options to rpm(1).

Macro handling functions

loadmacrosfile($filename)

Load the specified macro file. Sets $! if the file can't be read.

expand($name)

Expands the specified macro.

add_macro($macro_definition)
add_macro_noexpand($macro_definition)

Define a macro. For example,

    URPM::add_macro("vendor Mandrakesoft");
    my $vendor = URPM::expand("%vendor");

The 'noexpand' version doesn't expand literal newline characters in the macro definition.

del_macro($name)

Delete a macro.

resetmacros()

Destroys macros.

setVerbosity($level)

Sets rpm verbosity level. $level is an integer between 2 (RPMMESS_CRIT) and 7 (RPMMESS_DEBUG).

rpmErrorString()
rpmErrorWriteTo($fd)

COPYRIGHT

Copyright 2002-2005 Mandrakesoft

Original author: François Pons

Current maintainer: Rafael Garcia-Suarez <rgarciasuarez@mandriva.com>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.