How to parse an RPM file name?
Tom Limoncelli
tlimoncelli at stackexchange.com
Tue Nov 26 15:52:43 UTC 2013
On Tue, Nov 26, 2013 at 10:46 AM, Greg Swift <gregswift at gmail.com> wrote:
> the -p switch allows you to query the RPM file, rather than the installed
> RPM. This method is what I would recommend to minimize your headaches, but
> it does require you to have all the files (which it appears you do)
Sadly I don't have the files either. The project I'm working on is
auditing and cross-checking information about internal repos. I have
the information, not the packages nor the repos. (well, technically I
*have* the packages but they're not on the machine that is doing the
work)
How's this for a regular expression? It works on all the test cases
I've written so far.
#! /usr/bin/python
import sys
import re
for x in sys.argv[1:]:
m = re.search(r'(.*)/*(.*)-(.*)-(.*?)\.(.*)(\.rpm)', x)
if m:
(path, name, version, release, platform, _) = m.groups()
path = path or ''
verrel = version + '-' + release
print "\t".join([path, name, verrel, version, release, platform])
else:
sys.stderr.write('ERROR: Invalid name: %s\n' % x)
sys.exit(1)
Tom
More information about the Rpm-list
mailing list