def addInstall(self, item, key, how='u', relocs = None): if isinstance(item, str): f = file(item) header = self.hdrFromFdno(f) f.close() elif isinstance(item, file): header = self.hdrFromFdno(item) else: header = item if not how in ['u', 'i']: raise ValueError('how argument must be "u" or "i"') upgrade = (how == "u") if relocs: if type(relocs) == str: prefixes = header['prefixes'] if relocs == '': relocs = [] elif len(prefixes) > 0: relocs = [(prefixes[0], relocs)] else: raise ValueError('prefix given, but package is not relocatable') elif type(relocs) != list: raise ValueError("relocs argument must be either a string or a list"); if not _rpmext.addInstall(self, header, key, upgrade, relocs): raise rpm.error("adding package to transaction failed") return if not _rpmts.addInstall(self, header, key, upgrade): raise rpm.error("adding package to transaction failed")
def hdrCheck(self, blob): res, msg = TransactionSetCore.hdrCheck(self, blob) # generate backwards compatibly broken exceptions if res == rpm.RPMRC_NOKEY: raise rpm.error("public key not available") elif res == rpm.RPMRC_NOTTRUSTED: raise rpm.error("public key not trusted") elif res != rpm.RPMRC_OK: raise rpm.error(msg)
def hdrCheck(self, blob): res, msg = _rpmts.hdrCheck(self, blob) # generate backwards compatibly broken exceptions if res == rpm.RPMRC_NOKEY: raise rpm.error("public key not available") elif res == rpm.RPMRC_NOTTRUSTED: raise rpm.error("public key not trusted") elif res != rpm.RPMRC_OK: raise rpm.error(msg)
def add_install(self, path, key=None, upgrade=False): log.debug('add_install(%s, %s, upgrade=%s)', path, key, upgrade) if key is None: key = path with open(path) as fileobj: retval, header = self.hdrFromFdno(fileobj) if retval != rpm.RPMRC_OK: raise rpm.error("error reading package header") if not self.addInstall(header, key, upgrade): raise rpm.error("adding package to transaction failed")
def hdrFromFdno(self, fd): res, h = TransactionSetCore.hdrFromFdno(self, fd) # generate backwards compatibly broken exceptions if res == rpm.RPMRC_NOKEY: raise rpm.error("public key not available") elif res == rpm.RPMRC_NOTTRUSTED: raise rpm.error("public key not trusted") elif res != rpm.RPMRC_OK: raise rpm.error("error reading package header") return h
def hdrFromFdno(self, fd): res, h = _rpmts.hdrFromFdno(self, fd) # generate backwards compatibly broken exceptions if res == rpm.RPMRC_NOKEY: raise rpm.error("public key not available") elif res == rpm.RPMRC_NOTTRUSTED: raise rpm.error("public key not trusted") elif res != rpm.RPMRC_OK: raise rpm.error("error reading package header") return h
def addInstall(self, item, key, how="u"): header = self._f2hdr(item) if how not in ['u', 'i']: raise ValueError('how argument must be "u" or "i"') upgrade = (how == "u") if not TransactionSetCore.addInstall(self, header, key, upgrade): if upgrade: raise rpm.error("adding upgrade to transaction failed") else: raise rpm.error("adding install to transaction failed")
def addInstall(self, item, key, how="u"): header = self._f2hdr(item) if not how in ['u', 'i']: raise ValueError('how argument must be "u" or "i"') upgrade = (how == "u") if not TransactionSetCore.addInstall(self, header, key, upgrade): raise rpm.error("adding package to transaction failed")
def addErase(self, item): hdrs = [] # match iterators are passed on as-is if isinstance(item, rpm.mi): hdrs = item elif isinstance(item, rpm.hdr): hdrs.append(item) elif isinstance(item, (int, str)): if isinstance(item, int): dbi = rpm.RPMDBI_PACKAGES else: dbi = rpm.RPMDBI_LABEL for h in self.dbMatch(dbi, item): hdrs.append(h) if not hdrs: raise rpm.error("package not installed") else: raise TypeError("invalid type %s" % type(item)) for h in hdrs: if not TransactionSetCore.addErase(self, h): raise rpm.error("adding erasure to transaction failed")
def addInstall(self, item, key, how="u"): if isinstance(item, _string_types): f = open(item) header = self.hdrFromFdno(f) f.close() elif isinstance(item, rpm.hdr): header = item else: header = self.hdrFromFdno(item) if not how in ['u', 'i']: raise ValueError('how argument must be "u" or "i"') upgrade = (how == "u") if not TransactionSetCore.addInstall(self, header, key, upgrade): raise rpm.error("adding package to transaction failed")
def addInstall(self, item, key, how="u"): if isinstance(item, str): f = file(item) header = self.hdrFromFdno(f) f.close() elif isinstance(item, file): header = self.hdrFromFdno(item) else: header = item if not how in ['u', 'i']: raise ValueError('how argument must be "u" or "i"') upgrade = (how == "u") if not _rpmts.addInstall(self, header, key, upgrade): raise rpm.error("adding package to transaction failed")
def addInstall(self, item, key, how="u"): if isinstance(item, basestring): f = file(item) header = self.hdrFromFdno(f) f.close() elif isinstance(item, file): header = self.hdrFromFdno(item) else: header = item if not how in ["u", "i"]: raise ValueError('how argument must be "u" or "i"') upgrade = how == "u" if not TransactionSetCore.addInstall(self, header, key, upgrade): raise rpm.error("adding package to transaction failed")
def addErase(self, item): hdrs = [] if isinstance(item, rpm.hdr): hdrs = [item] elif isinstance(item, rpm.mi): hdrs = item elif isinstance(item, int): hdrs = self.dbMatch(rpm.RPMDBI_PACKAGES, item) elif isinstance(item, _string_types): hdrs = self.dbMatch(rpm.RPMDBI_LABEL, item) else: raise TypeError("invalid type %s" % type(item)) for h in hdrs: if not TransactionSetCore.addErase(self, h): raise rpm.error("package not installed") # garbage collection should take care but just in case... if isinstance(hdrs, rpm.mi): del hdrs
def addErase(self, item): hdrs = [] if isinstance(item, rpm.hdr): hdrs = [item] elif isinstance(item, rpm.mi): hdrs = item elif isinstance(item, int): hdrs = self.dbMatch(rpm.RPMDBI_PACKAGES, item) elif isinstance(item, str): hdrs = self.dbMatch(rpm.RPMDBI_LABEL, item) else: raise TypeError("invalid type %s" % type(item)) for h in hdrs: if not _rpmts.addErase(self, h): raise rpm.error("package not installed") # garbage collection should take care but just in case... if isinstance(hdrs, rpm.mi): del hdrs
def _i2hdrs(self, item): hdrs = [] # match iterators are passed on as-is if isinstance(item, rpm.mi): hdrs = item elif isinstance(item, rpm.hdr): hdrs.append(item) elif isinstance(item, (int, str)): if isinstance(item, int): dbi = rpm.RPMDBI_PACKAGES else: dbi = rpm.RPMDBI_LABEL for h in self.dbMatch(dbi, item): hdrs.append(h) if not hdrs: raise rpm.error("package not installed") else: raise TypeError("invalid type %s" % type(item)) return hdrs
def addReinstall(self, item, key): header = self._f2hdr(item) if not TransactionSetCore.addReinstall(self, header, key): raise rpm.error("adding package to transaction failed")
def addRestore(self, item): hdrs = self._i2hdrs(item) for h in hdrs: if not TransactionSetCore.addErase(self, h): raise rpm.error("adding restore to transaction failed")
def read_from_rpm(init): if type(init) == str: th = None url = urlparse(init) if url.scheme not in [None, '', 'file']: fdno, fdno_w = os.pipe() try: fdurl = urlopen(init) try: if fdurl.info()['Content-length'] < 0x70: raise rpm.error("error reading package header") except KeyError: pass # Read the magic buff = fdurl.read(0x04) if buff[0:4] != '\xed\xab\xee\xdb': raise rpm.error("error reading package header") # Read the lead and the signature structure buff += fdurl.read(0x6c) # Read the signature and the header structure tbr = 0x10 * struct.unpack( ">i", buff[-8:-4])[0] + struct.unpack(">i", buff[-4:])[0] tbr += 0x10 + (0x8 - (tbr % 0x8)) % 0x8 buff += fdurl.read(tbr) # Read the rest of the header tbr = 0x10 * struct.unpack( ">i", buff[-8:-4])[0] + struct.unpack(">i", buff[-4:])[0] tbr += (0x8 - (tbr % 0x8)) % 0x8 + 100 buff += fdurl.read(tbr) fdurl.close() # If the pipe buffer fills, we'll block, so the pipe write needs to be threaded th = Thread(target=os.write, args=(fdno_w, buff)) th.start() except: os.close(fdno) raise finally: os.close(fdno_w) else: fdno = os.open(url.netloc + url.path, os.O_RDONLY) try: hdr = ts.hdrFromFdno(fdno) finally: os.close(fdno) if th: th.join(1.0) elif type(init) == int: hdr = ts.hdrFromFdno(init) elif type(init) == rpm.hdr: hdr = init else: raise TypeError('Could not initialize from type ' + str(type(init))) return RpmInfo(name=hdr[rpm.RPMTAG_NAME], version=hdr[rpm.RPMTAG_VERSION], release=hdr[rpm.RPMTAG_RELEASE], is_src=not bool(hdr[rpm.RPMTAG_SOURCERPM]), arch=hdr[rpm.RPMTAG_ARCH], requires=set(hdr[rpm.RPMTAG_REQUIRES]), provides=set(hdr[rpm.RPMTAG_PROVIDES]), path=init)
def read_from_rpm(init): if type(init) == str: th = None url = urlparse(init) if url.scheme not in [None, '', 'file']: fdno, fdno_w = os.pipe() try: fdurl = urlopen(init) try: if fdurl.info()['Content-length'] < 0x70: raise rpm.error("error reading package header") except KeyError: pass # Read the magic buff = fdurl.read(0x04) if buff[0:4] != '\xed\xab\xee\xdb': raise rpm.error("error reading package header") # Read the lead and the signature structure buff += fdurl.read(0x6c) # Read the signature and the header structure tbr = 0x10 * struct.unpack(">i", buff[-8:-4])[0] + struct.unpack(">i", buff[-4:])[0] tbr += 0x10 + ( 0x8 - (tbr % 0x8 ) ) % 0x8 buff += fdurl.read(tbr) # Read the rest of the header tbr = 0x10 * struct.unpack(">i", buff[-8:-4])[0] + struct.unpack(">i", buff[-4:])[0] tbr += ( 0x8 - ( tbr % 0x8 ) ) % 0x8 + 100 buff += fdurl.read(tbr) fdurl.close() # If the pipe buffer fills, we'll block, so the pipe write needs to be threaded th = Thread(target=os.write, args=(fdno_w, buff)) th.start() except: os.close(fdno) raise finally: os.close(fdno_w) else: fdno = os.open(url.netloc + url.path, os.O_RDONLY) try: hdr = ts.hdrFromFdno(fdno) finally: os.close(fdno) if th: th.join(1.0) elif type(init) == int: hdr = ts.hdrFromFdno(init) elif type(init) == rpm.hdr: hdr = init else: raise TypeError('Could not initialize from type ' + str(type(init))) return RpmInfo(name = hdr[rpm.RPMTAG_NAME], version = hdr[rpm.RPMTAG_VERSION], release = hdr[rpm.RPMTAG_RELEASE], is_src = not bool( hdr[rpm.RPMTAG_SOURCERPM] ), arch = hdr[rpm.RPMTAG_ARCH], requires = set(hdr[rpm.RPMTAG_REQUIRES]), provides = set(hdr[rpm.RPMTAG_PROVIDES]), path = init)