def get_rpm_info(rpm_file):
    """Returns rpm information by querying a rpm"""
    ts = rpm.ts()
    fdno = os.open(rpm_file, os.O_RDONLY)
    try:
        hdr = ts.hdrFromFdno(fdno)
    except rpm.error:
        fdno = os.open(rpm_file, os.O_RDONLY)
        ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
        hdr = ts.hdrFromFdno(fdno)
    os.close(fdno)
    return { 'name': hdr[rpm.RPMTAG_NAME], 'ver' : "%s-%s" % (hdr[rpm.RPMTAG_VERSION],\
    hdr[rpm.RPMTAG_RELEASE]), 'epoch': hdr[rpm.RPMTAG_EPOCH],\
    'arch': hdr[rpm.RPMTAG_ARCH] }
Returns rpm information by querying a rpm
recipes/Python/306705_Query_rpm_file_return_dict_various_rpm/recipe-306705.py