Product SiteDocumentation Site

Checking whether the package is a source package

Another handy subroutine tells you if an RPM file represents a source RPM or a binary RPM. The is_source_package subroutine returns a true value if the package is a source package, and a false value otherwise.
The rpmpkg.pl script, shown in Listing 18-2, shows how to use the as_nvre and is_source_package subroutines.
Listing 18-2: rpmpkg.pl
#!/usr/bin/perl
#
# Queries RPM package file and prints
# out name and whether this is a source pkg.
# Usage:
# rpmpkg.pl package_name
#
use strict;
use RPM2;
my $header = RPM2->open_package( $ARGV[0] );
if ( $header->is_source_package() ) {
print "Source package ", $header->as_nvre(), "\n";
} else {
print $header->as_nvre(), "\n";
}