Skip to content

Instantly share code, notes, and snippets.

@DALDEI
Last active October 5, 2016 00:50
Show Gist options
  • Save DALDEI/a0200bc54aff0da77e2a1fb8b8e420d5 to your computer and use it in GitHub Desktop.
Save DALDEI/a0200bc54aff0da77e2a1fb8b8e420d5 to your computer and use it in GitHub Desktop.
rpm utils - extract the metadata from an rpm and print its 'nevra' and the path file name convention
#! /usr/bin/python
# Same as rpmname.sh but using rpmUtils python library
import sys
import re
import rpmUtils.transaction
from rpmUtils.miscutils import splitFilename
from rpmUtils.miscutils import hdrFromPackage
from rpmUtils.miscutils import pkgTupleFromHeader
ts = rpmUtils.transaction.initReadOnlyTransaction()
for path in sys.argv[1:]:
hdr = hdrFromPackage(ts,path)
(n, a, e, v, r) = pkgTupleFromHeader(hdr)
print "Path: {0}\nFile: {1}".format(path,path[path.rfind('/')+1:])
print "Name: {0}\nEpoch: {1}\nVersion: {2}\nRelease: {3}\nArch: {4}".format(n,e,v,r,a)
print "NVRA Path: {0}-{1}-{2}-{3}.rpm".format(n,v,r,a)
#!/bin/sh
# extract the metadata from an rpm and print its 'nevra'
# and the path file name convention
# Note: This reads the contents of the rpm file, ignoring its filename
#
for r ; do
echo $r
rpm -qp --queryformat="%{N}: %{EPOCH}: %{V}: %{R}: %{ARCH}\n" "$r"
rpm -qp --queryformat="%{N}-%{V}-%{R}.%{ARCH}.rpm\n" "$r"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment