Skip to content

Instantly share code, notes, and snippets.

@DALDEI
Created October 5, 2016 00:53
Show Gist options
  • Save DALDEI/b2b1aaac794be2b775708084df5ab89a to your computer and use it in GitHub Desktop.
Save DALDEI/b2b1aaac794be2b775708084df5ab89a to your computer and use it in GitHub Desktop.
rpm utils - normalize an rpm path. Given an rpm file print its normalized path as name-version-release-arch.rpm
#! /usr/bin/python
# normalize an rpm path.
# Given an rpm file print its normalized path as name-version-release-arch.rpm
# Note: this reads the metadata from the rpm file itself to generate the path
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 "{0}-{1}-{2}-{3}.rpm".format(n,v,r,a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment