Product SiteDocumentation Site

Chapter 17. Programming RPM with Perl

17.1. Getting and Using the Perl RPM Modules
17.2. Working with RPM Files
17.2.1. Opening package files
17.2.2. Listing tags from the package
17.2.3. Convenience methods
17.2.4. Listing the name and version
17.2.5. Checking whether the package is a source package
17.3. Programming with the RPM Database
17.3.1. Opening the database
17.3.2. Finding packages
17.3.3. Iterating over packages
17.3.4. Additional query subroutines
17.3.5. Getting information on packages
17.3.6. Comparing versions
17.3.7. Closing the database
17.4. Where to Go from Here
17.5. Summary
This chapter covers:
Perl is one of the most popular scripting languages. Used by system administrators, software developers, and a host of other users, Perl runs on many operating systems including Linux, UNIX, and Windows. Perl stands for Practical Extraction and Report Language, or sometimes Pathologically Eclectic Rubbish Lister.
Note
In the same vein, LISP stands for Lots of Irritating Single Parenthesis and COBOL for Completely Obnoxious Business Oriented Language.
I began my book Cross-Platform Perl (John Wiley & Sons, 2000) by mentioning that when I first started learning Perl, I thought it was an evil plot. I still do. But it is a very practical evil plot. You can get a lot of work done with Perl, and quickly.
Because of a long history of text processing, Perl is especially popular among system administrators. Perl also supports add-on packages, called modules. You can find thousands of add-on modules for text processing, networking, and a plethora of other tasks. There are so many modules available that some people who don’t like the Perl syntax script with Perl anyway, because the available modules save a lot of time.
Cross Reference
See search.cpan.org, the Comprehensive Perl Archive Network, for a listing of many Perl modules.
This chapter covers working with RPM files and the RPM database using Perl. You can combine RPM usage with other Perl usage, such as generating HTML files or downloading RPMs over a network link.
Cross Reference
Many of the RPM tools covered in Chapter 7, RPM Management Software are written in Perl.

Getting and Using the Perl RPM Modules

A number of Perl RPM modules are available. No one module provides all the features you need, although with time, the Perl modules will consolidate into a few modules that most everyone uses. As of this writing, the RPM2 module, by Chip Turner of Red Hat, provides the most recent approach to working with the RPM system from Perl. This chapter covers the RPM2 module.
Red Hat Linux 8.0 comes with a perl-RPM2 package, which you need to install to use this module. Otherwise, you can download the module from www.cpan.org. Install this module, as well as the perl module, which provides the Perl language interpreter. Once you have this module installed and the perl package installed, you are ready to go.
Note
The version of the perl-RPM2 package that ships with Red Hat Linux 8.0 has a bug in that it will not open package files that were created with the version of rpm that ships with Red Hat Linux 8.0. That is, the Perl module cannot read package files that ship with Red Hat Linux. You can read older package files, though. This problem only affects attempts to read .rpm files, not installed packages. The bug is related to reading signed packages but not having the GPG keys in the keyring. The latest version on search.cpan.org fixes this problem.
The RPM2 module contains Perl methods to work on two types of RPM objects: RPM files and installed packages.