How to parse an RPM file name?

Tom Limoncelli tlimoncelli at stackoverflow.com
Tue Nov 26 15:34:03 UTC 2013


Is there a name-parsing tool that is part of the official RPM tool package?

I have a list of filenames. Each is the filename of an RPM package. I
don't have the actual packages, just the filenames. For each I need to
extract the package name, version, release and arch.  This is part of
a system that I'm writing for managing builds and repositories.

The list of filenames looks like:

$ cat /tmp/packages.txt
/home/builder/packages/testing-dev/python-redis-2.8.0-2.el6.noarch.rpm
/home/builder/packages/testing-dev/redis-2.6.16-1.el6.1.x86_64.rpm
/home/builder/packages/testing-dev/sei_dnsmaster-1.0-99.el6.x86_64.rpm

The output should be:

/home/builder/packages/testing-dev python-redis 2.8.0-2 2.8.0 2 el6.noarch
/home/builder/packages/testing-dev redis 2.6.16-1 2.6.16 1 el6.1.x86_64
/home/builder/packages/testing-dev sei_dnsmaster 1.0-99 1.0 99 el6.x86_64

Google searches have turned up many regular expressions... most of
them are incorrect and fail on some of the most simple test cases.  So
sad.  Sigh.

I looked around the rpmdev package and couldn't find a utility that did this.

The nearest I found is this:
rpm --queryformat "%{NAME} %{VERSION} %{RELEASE} %{ARCH}" -qp filename.rpm
However that requires the package is installed.  In my case this isn't true.

Is there a utility or library call that will do this kind of parsing?
Maybe one exists and I just haven't found it.

If not, I volunteer to contribute one.

Thanks,
Tom Limoncelli

-- 
Email: tal at whatexit.org    Work: tlimoncelli at StackOverflow.com
Skype: YesThatTom
Blog:  http://EverythingSysadmin.com


More information about the Rpm-list mailing list