RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Olivier Thauvin
  Root:   /v/rpm/cvs                       Email:  [EMAIL PROTECTED]
  Module: rpm                              Date:   15-Aug-2007 22:35:28
  Branch: HEAD                             Handle: 2007081521352800

  Modified files:
    rpm/perl                RPM.pm RPM.xs
    rpm/perl/t              00.pod.coverage.t

  Log:
    - perl RPM module cleanup and documentation

  Summary:
    Revision    Changes     Path
    1.7         +80 -476    rpm/perl/RPM.pm
    1.23        +1  -1      rpm/perl/RPM.xs
    1.9         +0  -4      rpm/perl/t/00.pod.coverage.t
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/perl/RPM.pm
  ============================================================================
  $ cvs diff -u -r1.6 -r1.7 RPM.pm
  --- rpm/perl/RPM.pm   15 Aug 2007 02:59:59 -0000      1.6
  +++ rpm/perl/RPM.pm   15 Aug 2007 20:35:28 -0000      1.7
  @@ -19,294 +19,17 @@
       setlogfile
       lastlogmsg
       setverbosity
  +    rpmvercmp
  +    add_macro
  +    delete_macro
  +    load_macro_file
  +    reset_macros
  +    dump_macros
  +    platformscore
   );
   
  -sub open_rpm_db {
  -  my $class = shift;
  -  my %params = @_;
  -
  -  my $self = bless { }, "RPM::DB";
  -  if ($params{-path}) {
  -    $class->add_macro("_dbpath", $params{-path});
  -    $self->{c_db} = RPM::_open_rpm_db($params{-readwrite} ? 1 : 0);
  -    $class->delete_macro("_dbpath");
  -  }
  -  else {
  -    $self->{c_db} = RPM::_open_rpm_db($params{-readwrite} ? 1 : 0);
  -  }
  -
  -  return $self;
  -}
  -
  -sub open_hdlist {
  -  my $class = shift;
  -  my $file = shift;
  -
  -  open FH, "<$file"
  -    or die "Can't open $file: $!";
  -
  -  my @ret;
  -  while (1) {
  -    my ($hdr) = RPM::_read_from_file(*FH);
  -    last unless $hdr;
  -
  -    push @ret, RPM::Header->_new_raw($hdr);
  -  }
  -
  -  close FH;
  -  return @ret;
  -}
  -
  -sub open_package {
  -  my $class = shift;
  -  my $file = shift;
  -  my $flags = shift;
  -
  -  if (RPM->rpm_api_version > 4.0 and not defined $flags) {
  -    $flags = RPM->vsf_default;
  -  }
  -  $flags ||= 0;
  -
  -  open FH, "<$file"
  -    or die "Can't open $file: $!";
  -
  -  my $hdr = RPM::_read_package_info(*FH, $flags);
  -  close FH;
  -
  -  my ($filename, $path) = (basename($file), realpath(dirname($file)));
  -  $hdr = RPM::Header->_new_raw($hdr, File::Spec->catfile($path, $filename));
  -  return $hdr;
  -}
  -
  -sub create_transaction
  -{
  -  my $class = shift;
  -  my $flags = shift;
  -  my $t;
  -
  -  return undef if (RPM->rpm_api_version <= 4.0); 
  -  if(not defined $flags) {
  -    $flags = RPM->vsf_default;
  -  }
  -
  -  $t = RPM::_create_transaction($flags);
  -  $t = RPM::Transaction->_new_raw($t);
  -
  -  return $t; 
  -}
  -
  -package RPM::DB::OLD;
  -
  -sub find_all_iter {
  -  my $self = shift;
  -
  -  return RPM::PackageIterator->new_iterator($self, "RPMTAG_NAME")
  -}
  -
  -sub find_all {
  -  my $self = shift;
  -
  -  return RPM::PackageIterator->new_iterator($self)->expand_iter();
  -}
  -
  -sub find_by_name_iter {
  -  my $self = shift;
  -  my $name = shift;
  -
  -  return RPM::PackageIterator->new_iterator($self, "RPMTAG_NAME", $name);
  -}
  -sub find_by_name {
  -  my $self = shift;
  -  my $name = shift;
  -
  -  return $self->find_by_name_iter($name)->expand_iter;
  -}
  -
  -sub find_by_provides_iter {
  -  my $self = shift;
  -  my $name = shift;
  -
  -  return RPM::PackageIterator->new_iterator($self, "RPMTAG_PROVIDES", $name);
  -}
  -sub find_by_provides {
  -  my $self = shift;
  -  my $name = shift;
  -
  -  return $self->find_by_provides_iter($name)->expand_iter;
  -}
  -
  -sub find_by_requires_iter {
  -  my $self = shift;
  -  my $name = shift;
  -
  -  return RPM::PackageIterator->new_iterator($self, "RPMTAG_REQUIRENAME", 
$name);
  -}
  -
  -sub find_by_requires {
  -  my $self = shift;
  -  my $name = shift;
  -
  -  return $self->find_by_requires_iter($name)->expand_iter;
  -}
  -
  -sub find_by_file_iter {
  -  my $self = shift;
  -  my $name = shift;
  -
  -  return RPM::PackageIterator->new_iterator($self, "RPMTAG_BASENAMES", 
$name);
  -}
  -
  -sub find_by_file {
  -  my $self = shift;
  -  my $name = shift;
  -
  -  return $self->find_by_file_iter($name)->expand_iter;
  -}
  -
  -package RPM::PackageIterator::OLD;
  -
  -sub new_iterator {
  -  my $class = shift;
  -  my $db = shift;
  -  my $tag = shift;
  -  my $key = shift;
  -
  -  my $self = bless { db => $db }, $class;
  -  $self->{c_iter} = RPM::C::DB::_init_iterator($db->{c_db},
  -                                             $RPM::header_tag_map{$tag},
  -                                             $key || "",
  -                                             defined $key ? length $key : 0);
  -  return $self;
  -}
  -
  -sub next {
  -  my $self = shift;
  -
  -  return unless $self->{c_iter};
  -  my ($hdr, $offset) = $self->{c_iter}->_iterator_next();
  -  return unless $hdr;
  -
  -  my $ret = RPM::Header->_new_raw($hdr, undef, $offset);
  -  return $ret;
  -}
  -
  -sub expand_iter {
  -  my $self = shift;
  -
  -  my @ret;
  -  while (my $h = $self->next) {
  -    push @ret, $h;
  -  }
  -
  -  return @ret;
  -}
  -
  -# make sure c_iter is destroyed before {db} so that we always free an
  -# iterator before we free the db it came from
  -
  -sub DESTROY {
  -  my $self = shift;
  -  delete $self->{c_iter};
  -}
  -
  -package RPM::Transaction::OLD;
  -
  -sub _new_raw {
  -  my $class         = shift;
  -  my $c_transaction = shift;
  -
  -  my $self = bless { }, $class;
  -  $self->{c_transaction} = $c_transaction;
  -
  -  return $self;
  -}
  -
  -sub add_install {
  -  my $self    = shift;
  -  my $h       = shift;
  -  my $upgrade = shift || 0;
  -  my $fn;
  -
  -  #
  -  # Must have a header to add
  -  return 0 if(!defined($h));
  -
  -  #
  -  # Get filename
  -  $fn = $h->filename();
  -  
  -  # XXX: Need to add relocations at some point, but I think we live
  -  #      without this for now (until I need it (-;).
  -  return RPM::C::Transaction::_add_install($self->{'c_transaction'}, 
  -     $h->{'c_header'}, $fn, $upgrade)
  -}
  -
  -sub add_erase {
  -  my $self    = shift;
  -  my $h       = shift;
  -  my $db_offset;
  -  my $fn;
  -
  -  #
  -  # Must have a header to add
  -  return 0 if(!defined($h));
  -
  -  #
  -  # Get record offset
  -  $db_offset = $h->offset();
  -  return 0 if(!defined($db_offset));
  - 
  -  # XXX: Need to add relocations at some point, but I think we live
  -  #      without this for now (until I need it (-;).
  -  return RPM::C::Transaction::_add_delete($self->{'c_transaction'}, 
  -     $h->{'c_header'}, $db_offset)
  -}
  -
  -sub element_count {
  -     my $self = shift;
  -     
  -     return $self->{'c_transaction'}->_element_count();
  -}
  -
  -sub close_db {
  -     my $self = shift;
  -     
  -     return $self->{'c_transaction'}->_close_db();
  -}
  -
  -sub check {
  -     my $self = shift;
  -     
  -     return $self->{'c_transaction'}->_check();
  -}
  -
  -sub order {
  -     my $self = shift;
  -             
  -     return $self->{'c_transaction'}->_order();
  -}
  -
  -sub elements {
  -     my $self = shift;
  -     my $type = shift;
  -
  -     $type = 0 if(!defined($type));
  -     
  -     return $self->{'c_transaction'}->_elements($type);
  -}
  -
  -sub run {
  -  my $self         = shift;
  -  my $ok_probs     = shift || '';
  -  my $ignore_probs = shift || 0;
  -
  -  return RPM::C::Transaction::_run($self->{'c_transaction'}, $ok_probs, 
  -     $ignore_probs);
  -}
  -
  -# Preloaded methods go here.
  -
   1;
  +
   __END__
   # Below is stub documentation for your module. You better edit it!
   
  @@ -318,240 +41,107 @@
   
     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";
  -
   =head1 DESCRIPTION
   
   The RPM module provides an object-oriented interface to querying both
   the installed RPM database as well as files on the filesystem.
   
  -=head1 CLASS METHODS
  -
  -Pretty much all use of the class starts here.  There are three main
  -entrypoints into the package -- either through the database of
  -installed 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 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 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 to
  -go out of scope.
  -
  -=over 4
  -
  -=item 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. C<-path>) is optional.
  -
  -=item open_package("foo-1.1-14.noarch.rpm")
  -
  -Opens a specific package (RPM or SRPM).  Returns a Header object.
  -
  -=item 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:
  -
  -=item 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 the
  -various hash and signature formats that rpm supports.
  -
  -=item RPM->vsf_nohdrchk
  -
  -Don't check the header.
  -
  -=item RPM->vsf_needpayload
  -
  -Require that a files payload be part of the RPM (Chip is this right?).
  -
  -=item RPM->vsf_nosha1header
  -
  -
  -=item RPM->vsf_nomd5header
  +=head1 FUNCTIONS
   
  -=item RPM->vsf_nodsaheader
  +=head2 GENERICS FUNCTIONS
   
  -=item RPM->vsf_norsaheader
  +=head3 rpmversion
   
  -=item RPM->vsf_nosha1
  +Return the rpm version which is also the module version:
   
  -=item RPM->vsf_nomd5
  +    RPM::rpmversion(); # return 5.0.DEVEL currently ;)
   
  -=item RPM->vsf_nodsa
  +=head2 MACROS FUNCTIONS
   
  -=item RPM->vsf_norsa
  +=head3 expand_macro($string)
   
  -=back
  -
  -=head1 RPM DB object methods
  -
  -=over 4
  -
  -=item find_all_iter()
  -
  -Returns an iterator object that iterates over the entire database.
  -
  -=item find_all()
  -
  -Returns an list of all of the results of the find_all_iter() method.
  -
  -=item find_by_file_iter($filename)
  -
  -Returns an iterator that returns all packages that contain a given file.
  -
  -=item find_by_file($filename)
  -
  -Ditto, except it just returns the list
  -
  -=item find_by_name_iter($package_name)
  -
  -You get the idea.  This one is for iterating by package name.
  -
  -=item find_by_name($package_name)
  +Return the string after macros expansion:
   
  -Ditto, except it returns a list.
  +    expand_macro('%_dbpath'); # will return '/var/lib/rpm' on most system,
  +                              # depending of your config
  +    expand_macro('%{?_dbpath:is set}'); # will return is set, normally... :)
   
  -=item find_by_provides_iter($provides_string)
  +=head3 add_macro($string)
   
  -This one iterates over provides.
  +Set or overide a macro, the format to use is the macro name (w/o %) follow
  +by its definition:
   
  -=item find_by_provides($provides_string)
  +    add_macro('_anymacros anyvalue');
  +    print expand_macro('%_anymacros'); # show 'anyvalue'
   
  -Ditto, except it returns a list.
  +=head3 delete_macro($macro)
   
  -=item find_by_requires_iter($requires_string)
  +Delete a macro definition:
   
  -This one iterates over requires.
  +    delete_macro('_anymacros');
   
  -=item find_by_requires($requires_string)
  +=head3 dump_macros($handle)
   
  -Ditto, except it returns a list.
  +Dump macros all macros currently defined into $handle. If $handle is missing,
  +STDOUT is used.
   
  -=back
  -
  -=head1 RPM Database Iterator Methods
  -
  -Once you have a a database iterator, then you simply need to step
  -through all the different package headers in the result set via the
  -iterator.
  -
  -=over 4
  -
  -=item next()
  -
  -Return the next package header in the result set.
  -
  -=item expand_iter()
  +=head3 load_macro_file($file)
   
  -Return the list of all the package headers in the result set of the iterator.
  +Load a macro file.
   
  -=back
  +=head3 reset_macros
   
  -=head1 Transaction object methods
  +Reset all macros to default config (aka from rpm configuration).
   
  -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 are
  -treated as on "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.
  +=head2 PLATFORM FUNCTIONS
   
  -=over 4
  +=head3 setverbosity($verbosity)
   
  -=item add_install($pkg, $upgrade)
  +Set the global verbosity of rpmlib.
   
  -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 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.
  +=head3 rpmvercmp($verA, $verB)
   
  -=item add_erase($pkg)
  +Compare two version (or release, not both) and return:
  +  * -1 verA < verB
  +  *  0 verA = verB
  +  *  1 verA > verB
   
  -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.
  +    rpmvercmp('1', '1.1'); # return 1
  +    # This works but will not give the expected result:
  +    rpmvercmp('1-1', '1.1-2') # return -1
   
  -=item element_count()
  +=head3 platformscore($platform)
   
  -Returns the number of elements in a transaction (this is the sum of the
  -install and erase elements.
  +Return the score of platform according your rpm configuration,
  +0 if not compatible.
   
  -=item close_db()
  +    # on x86_64 under Mandriva Linux:
  +    platformscore("i586-mandriva-linux-gnu");
  +    # return 8 here
  +    platformscore("ppc-mandriva-linux-gnu");
  +    # return 0
   
  -Closes the rpm database.  This is needed for some ordering of
  -transactions for non-install purposes.
  +=head2 LOG AND VERBOSITY FUNCTIONS
   
  -=item check()
  +=head3 lastlogmsg
   
  -Verify that the dependencies for this transaction are met.  Returns
  -0 on failure and 1 on success.
  +Return the last message give by rpm. In array context return both
  +the erreur level and message:
   
  -=item order()
  +    my $message = rpmlog();
  +    my ($code, $message) = rpmlog();
   
  -Order the elements in dependency order.
  +=head3 rpmlog($err_level, $message)
   
  -=item elements()
  +Log a message using rpm API.
   
  -Return a list of elements as they are presently ordered.  Note, this
  -returns the NEVR's not the package headers.
  +=head3 setlogcallback
   
  -=item run()
  +DEPRECATED ?
   
  -Run the transaction.  This will automatically check for dependency
  -satisfaction, and order the transaction.
  +=head3 setlogfile
   
  -=back
  +DEPRECATED ?
   
   =head1 TODO
   
  @@ -563,7 +153,12 @@
   
   =over 8
   
  +=item 0.5
  +
  +Massive Rework:
  +
   =item 0.01
  +
   Initial release
   
   =back
  @@ -571,11 +166,20 @@
   
   =head1 AUTHOR
   
  +Olivier Thauvin E<lt>[EMAIL PROTECTED]<gt>
  +
  +Original author:
  +
   Chip Turner E<lt>[EMAIL PROTECTED]<gt>
   
   =head1 SEE ALSO
   
   L<perl>.
  -The original L<RPM> module.
  +L<RPM::Header>
  +L<RPM::PackageIterator>
  +L<RPM::Transaction>
  +L<RPM::Constant>
  +L<RPM::Files>
  +L<RPM::Dependencies>
   
   =cut
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/perl/RPM.xs
  ============================================================================
  $ cvs diff -u -r1.22 -r1.23 RPM.xs
  --- rpm/perl/RPM.xs   15 Aug 2007 02:59:59 -0000      1.22
  +++ rpm/perl/RPM.xs   15 Aug 2007 20:35:28 -0000      1.23
  @@ -150,6 +150,7 @@
   void
   lastlogmsg()
       PPCODE:
  +    if (GIMME_V == G_ARRAY)
       XPUSHs(sv_2mortal(newSViv(rpmlogCode())));
       XPUSHs(sv_2mortal(newSVpv(rpmlogMessage(), 0)));
   
  @@ -199,4 +200,3 @@
       char * msg
       CODE:
       rpmlog(sv2constant(svcode, "rpmlog"), "%s", msg);
  -
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/perl/t/00.pod.coverage.t
  ============================================================================
  $ cvs diff -u -r1.8 -r1.9 00.pod.coverage.t
  --- rpm/perl/t/00.pod.coverage.t      15 Aug 2007 03:00:41 -0000      1.8
  +++ rpm/perl/t/00.pod.coverage.t      15 Aug 2007 20:35:28 -0000      1.9
  @@ -6,11 +6,7 @@
   
   plan tests => 9;
   
  -SKIP: {
  -    skip "RPM no yet finished", 1;
   pod_coverage_ok( "RPM", "RPM is covered" );
  -}
  -
   pod_coverage_ok( "RPM::Constant", "RPM::Constant is covered" );
   pod_coverage_ok( "RPM::Header", "RPM::Header is covered" );
   pod_coverage_ok( "RPM::Transaction", "RPM::Transaction is covered" );
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to