URPM

Section: User Contributed Perl Documentation (3)
Updated: 2018-09-18
Page Index
 

NAME

URPM - Manipulate RPM files and headers  

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->name, "\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

Initialization
URPM->new()
The constructor creates a new, empty URPM object. It's a blessed hash that contains three fields:
depslist is an arrayref containing the list of depending packages (which are "URPM::Package" objects).
obsoletes is an hashref containing as keys the list of property names obsoleted by the URPM object.
provides is an hashref containing as keys the list of property names provided by the URPM object. The associated value is true if the property is versioned.

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.

Loading packages data

$urpm->{depslist} is loaded when parsing sources (synthesis, hdlists or a plain rpm file).

$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.

Callback signature is callback("URPM", "URPM::Package").

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

$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

Callback signature is callback("URPM", "URPM::Package").

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 { ... }

If "keep_all_tags" isn't specified, URPM will drop all memory-consuming tags (notably changelogs, filelists, scriptlets).

Callback signature is callback(URPM::Package).

Searching packages

URPM::ranges_overlap($range1, $range2)
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.

$urpm->packages_providing($name)
Returns a list of "URPM::Package" providing <$name>
$urpm->packages_by_name($name)
Returns a list of "URPM::Package" corresponding to the wanted <$name>
$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 only match short name (N) => 0 / 1
strict_fullname only match fullname (NVRA) (fast) => 0 / 1
src => look only for srpms => 0 / 1

Debuging

These are used when faking a URPM::DB: $urpm can be used as-a $db

$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.

Callback signature is callback(URPM::Package).

$urpm->traverse_tag_find($tag,$name,$callback)
Quite similar to "traverse_tag", but stops when $callback returns true.

(also note that only one $name is handled)

Callback signature is callback(URPM::Package).

Checking packages

URPM::verify_rpm($file, %options)
Verifies an RPM file. Returns 0 on failure, 1 on success. Recognized options are:

    nodigests => 0 / 1
    nosignatures => 0 / 1

URPM::verify_signature($file)
Verifies the signature of an RPM file. Returns a string that will contain ``OK'' or ``NOT OK'' as well as a description of the found key (if successful) or of the error (if signature verification failed.)
$urpm->import_pubkey(%options)
Imports a key in the RPM database.

    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 (or "undef" on failure).

$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 "".
verify($prefix)
Verify the RPM database (like "rpmdb --verify"). $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.

Returns the number of packages seen (all).

$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.

Callback signature is callback(URPM::Package).

Returns the number of packages seen (all those that matched provided names).

$db->traverse_tag_find($tag,$name,$callback)
Quite similar to "traverse_tag", but stops when $callback returns true.

(also note that only one $name is handled)

Callback signature is callback(URPM::Package).

Returns whether callback returned true once.

$db->create_transaction()
Creates and returns a new transaction (an "URPM::Transaction" object) on the specified DB.
 

The URPM::Package class

Getting a URPM::Package object

URPM::Package objects are usually retrieved from $urpm->{depslist} after having loaded either the RPM DB and/or synthesis files.

It's also possible to get such an object with:

URPM::spec2srcheader($specfile)
Returns a URPM::Package object containing the header of the source rpm produced by the evaluation of the specfile whose path is given as argument. All dependencies stored in this header are exactly the one needed to build the specfile.
URPM::stream2header($fp)
Returns a URPM::Package object containing the header read from $fp.

Methods

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()
Full conflicts tags
$package->conflicts_nosense()
Just the conflicted package name. This is only used when faking a URPM::DB: $urpm can be used as-a $db
$package->description()
$package->dirnames()
$package->distribution()
$package->epoch()
$package->EVR()
$package->excludearchs()
$package->exclusivearchs()
$package->filelinktos()
$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->id()
$package->installtid()
$package->is_arch_compat()
Returns whether this package is compatible with the current machine's architecture. 0 means not compatible. The lower the result is, the preferred the package is.
$package->license()
$package->name()
The rpm's bare name.
$package->obsoletes()
Full obsoletes tags
$package->obsoletes_nosense()
Just the obsoleted package name.
$package->obsoletes_overlap($s)
$package->os()
$package->pack_header()
If a header is associated with the package, fill the package fields from the header's tags (NEVRA, requires/recommends/obsoletes/conflicts/provides/summary) then free the header

It's useful when traversing the rpm DB, if one wants to keep around a package from the DB else the info would not be available outside the traverse_*() function.

It's also useful when creating a URPM_Package from a package file in order to shrink memory footprint.

$package->packager()
$package->payload_format()
$package->provides()
Full provides tags
$package->provides_nosense()
Just the provided package name.
$package->provides_overlap($s)
$package->rate()
$package->release()
$package->requires()
$package->recommends()
Full requires tags
$package->requires_nosense()
Just the required package name.
$package->recommends_nosense()
$package->rflags()
$package->filesize()
Size of the rpm file (ie the rpm header + cpio body)
$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->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. It's usually the $urpm object.

Recognized options are:

    callback_close  => sub { ... }
    callback_elem   => sub { ... }
    callback_error  => sub { ... }
    callback_inst   => sub { ... }
    callback_open   => sub { ... }
    callback_trans  => sub { ... }
    callback_uninst => sub { ... }
    callback_verify => sub { ... }
    delta => used for progress callbacks (trans, uninst, inst)
    excludedocs => 0 / 1
    force => 0 / 1
    ignorearch => 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).

'callback_open' signature is ($data, $cb_type, $pkg_id). It _must_ return a file handler for the asked package.

'callback_close' signature is ($data, $cb_type, $pkg_id). It is called just before URPM close the fd for the installed package.

$cb_type is one of 'open' or 'close'.

Other Callbacks signature is callback($data, $cb_type, $pkg_id, $subtype, $amout, $total)

$cb_type is one of 'elem', 'error', 'inst', 'trans' or 'uninst'. $subtype can be 'start', 'progress' or 'stop'. For 'error', it can be 'cpio', 'script' or 'unpack'.

The purpose of those callbacks is to report progress (the two last parameters ($amount & $total) enable to compute progress percentage).

$trans->traverse($callback)
Executes the specified callback (a code reference) for each package in the transaction, passing a "URPM::Package" object as argument the callback.

Transaction Element management

$trans->NElements($fileno)
Returns the number of elements in the transaction.
$trans->Element_version($index)
Returns the version of the $index-th element in the transaction.
$trans->Element_release($index)
Returns the release of the $index-th element in the transaction.
$trans->Element_fullname($index)
Returns the fullname of the $index-th element in the transaction.
 

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 Mageia");
    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.
 

Misc other functions

setVerbosity($level)
Sets rpm verbosity level. $level is an integer between 2 (RPMMESS_CRIT) and 7 (RPMMESS_DEBUG).
rpmErrorString()
rpmErrorWriteTo($fd)
archscore($arch)
Return the score of the given arch. 0 mean not compatible, lower is prefered.
osscore($os)
Return the score of the given os. 0 mean not compatible, lower is prefered.
 

The $state object

It has the following fields:

backtrack: {
   selected => { id => undef }, 
   deadlock => { id|property => undef },
 }

cached_installed: { property_name => { fullname => undef } }

oldpackage: int
   # will be passed to $trans->run to set RPMPROB_FILTER_OLDPACKAGE

selected: { id => {
     requested => bool, install => bool,
     from => pkg, psel => pkg,
     promote => name, unsatisfied => [ id|property ]
 } }

rejected: { fullname => {
     size => int, removed => { fullname|``asked'' => undef },
     obsoleted => { fullname|``asked'' => undef },
     backtrack => { # those info are only used to display why package is unselected
         promote => [ name ], keep => [ fullname ], 
         unsatisfied => [ id|property ], 
         conflicts => [ fullname ],
     },
     closure => { fullname => { old_requested => bool, 
                                unsatisfied => [ id|property ],
                                conflicts => property },
                                avoid => bool },
     },
 } }

rejected_already_installed: { id => pkg }

orphans_to_remove: [ pkg ]

whatrequires: { name => { id => undef } }
   # reversed requires_nosense for selected packages

unselected_uninstalled: [ pkg ]
   # (old) packages which are needed, but installed package is newer

more fields only used in build_transaction_set and its callers):

transaction: [ { upgrade => [ id ], remove => [ fullname ] } ]

transaction_state: $state object  

SEE ALSO

The URPM::Resolve implements the resolving bits.

The urpm package is a higher level module used by the urpmi command line tool, the rpmdrake GUI and the drakx installer.  

COPYRIGHT

Copyright 2002, 2003, 2004, 2005 MandrakeSoft SA

Copyright 2005, 2006, 2007, 2008 Mandriva SA

Copyright 2011, 2012, 2013, 2014, 2015, 2016 Mageia

François Pons (original author), Rafael Garcia-Suarez, Pixel, Thierry Vignaud <tv@mageia.org> (current maintainer)

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


 

Index

NAME
SYNOPSIS
DESCRIPTION
The URPM class
The URPM::DB class
The URPM::Package class
The URPM::Transaction class
Macro handling functions
Misc other functions
The $state object
SEE ALSO
COPYRIGHT