def get_rpm_header(file_name, ts=None): """Read rpm header. @param file_name: rpm file name (or file object) @type file_name: str (or file) @param ts: transaction set instance @type ts: rpm.TransactionSet @return: rpm header @rtype: rpm.hdr """ if ts is None: ts = rpm.TransactionSet() # no rpm.keyring on rhel5 if hasattr(rpm, "keyring"): # Set an empty keyring to prevent accessing rpmdb, # which may cause race-conditions when running in threads. # NOTE: RPM is *not* tread-safe, but this *usually* works in threads. ts.setKeyring(rpm.keyring()) ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS) if type(file_name) in (str, unicode): fo = open(file_name, "r") else: fo = file_name hdr = ts.hdrFromFdno(fo.fileno()) if fo is not file_name: fo.close() return hdr
def get_rpm_header(file_name, ts=None): """Read rpm header. @param file_name: rpm file name (or file object) @type file_name: str (or file) @param ts: transaction set instance @type ts: rpm.TransactionSet @return: rpm header @rtype: rpm.hdr """ if ts is None: ts = rpm.TransactionSet() # no rpm.keyring on rhel5 if hasattr(rpm, "keyring"): # Set an empty keyring to prevent accessing rpmdb, # which may cause race-conditions when running in threads. # NOTE: RPM is *not* tread-safe, but this *usually* works in threads. ts.setKeyring(rpm.keyring()) ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS) if isinstance(file_name, six.string_types): fo = open(file_name, "r") else: fo = file_name hdr = ts.hdrFromFdno(fo.fileno()) if fo is not file_name: fo.close() return hdr
def _get_header(self): """ Examine a RPM package file and return its header See docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch16s04.html """ ts = rpm.TransactionSet() ts.setKeyring(rpm.keyring()) ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES | rpm._RPMVSF_NODIGESTS) with open(self.path, "r") as f: hdr = ts.hdrFromFdno(f.fileno()) return hdr