def getRpmVersion(): _ts = transaction.initReadOnlyTransaction() for h in _ts.dbMatch('Providename', "rpm"): version = ("rpm", h['version'], h['release'], h['epoch']) return version else: raise up2dateErrors.RpmError( "Couldn't determine what version of rpm you are running.\nIf you get this error, try running \n\n\t\trpm --rebuilddb\n\n" )
def __readHeaderFromRpm(self, fileNames, pkg): fd = os.open(fileNames[0], 0) self.ts.pushVSFlags(~(rpm.RPMVSF_NOMD5|rpm.RPMVSF_NEEDPAYLOAD)) try: hdr = self.ts.hdrFromFdno(fd) except: os.close(fd) self.ts.popVSFlags() raise up2dateErrors.RpmError("Error reading header") self.ts.popVSFlags() os.close(fd) self.log.log_me("Reading header from: %s" % fileNames) self.headerCache[up2dateUtils.pkgToStringArch(pkg)] = hdr return hdr
def getOSVersionAndRelease(): cfg = config.initUp2dateConfig() ts = transaction.initReadOnlyTransaction() for h in ts.dbMatch('Providename', "redhat-release"): if cfg["versionOverride"]: version = cfg["versionOverride"] else: version = h['version'] releaseVersion = (h['name'], version) return releaseVersion else: raise up2dateErrors.RpmError( "Could not determine what version of Red Hat Linux you "\ "are running.\nIf you get this error, try running \n\n"\ "\t\trpm --rebuilddb\n\n")
def _getOSVersionAndRelease(): ts = transaction.initReadOnlyTransaction() for h in ts.dbMatch('Providename', "redhat-release"): osVersionRelease = (h['name'], h['version'], h['release']) return osVersionRelease else: for h in ts.dbMatch('Providename', "distribution-release"): osVersionRelease = (h['name'], h['version'], h['release']) # zypper requires a exclusive lock on the rpmdb. So we need # to close it here. ts.ts.closeDB() return osVersionRelease else: raise up2dateErrors.RpmError( "Could not determine what version of Red Hat Linux you "\ "are running.\nIf you get this error, try running \n\n"\ "\t\trpm --rebuilddb\n\n")
def _getOSVersionAndRelease(): ts = transaction.initReadOnlyTransaction() for h in ts.dbMatch('Providename', "redhat-release"): SYSRELVER = 'system-release(releasever)' version = h['version'] release = h['release'] if SYSRELVER in h['providename']: provides = dict(zip(h['providename'], h['provideversion'])) release = '%s-%s' % (version, release) version = provides[SYSRELVER] osVersionRelease = (h['name'], version, release) return osVersionRelease else: for h in ts.dbMatch('Providename', "distribution-release"): osVersionRelease = (h['name'], h['version'], h['release']) # zypper requires a exclusive lock on the rpmdb. So we need # to close it here. ts.ts.closeDB() return osVersionRelease else: raise up2dateErrors.RpmError( "Could not determine what version of Red Hat Linux you "\ "are running.\nIf you get this error, try running \n\n"\ "\t\trpm --rebuilddb\n\n")
def runTransaction(ts, rpmCallback, transdir=None): cfg = config.initUp2dateConfig() if transdir == None: transdir = cfg['storageDir'] deps = ts.check() if deps: raise up2dateErrors.DependencyError( "Dependencies should have already been resolved, "\ "but they are not.", deps) rc = ts.run(rpmCallback, transdir) if rc: errors = "\n" for e in rc: try: errors = errors + e[1] + "\n" except: errors = errors + str(e) + "\n" raise up2dateErrors.TransactionError( "Failed running transaction of packages: %s" % errors, deps=rc) elif type(rc) == type([]) and not len(rc): # let the user know whats wrong log = up2dateLog.initLog() log.log_me("Failed running rpm transaction - %pre %pro failure ?.") raise up2dateErrors.RpmError("Failed running rpm transaction")
def callback(self, what, amount, total, hdr, path): # print "what: %s amount: %s total: %s hdr: %s path: %s" % ( # what, amount, total, hdr, path) if what == rpm.RPMCALLBACK_INST_OPEN_FILE: fileName = "%s/%s-%s-%s.%s.rpm" % ( path, hdr['name'], hdr['version'], hdr['release'], hdr['arch']) try: self.fd = os.open(fileName, os.O_RDONLY) except OSError: raise up2dateErrors.RpmError("Error opening %s" % fileName) return self.fd elif what == rpm.RPMCALLBACK_INST_CLOSE_FILE: os.close(self.fd) self.fd = 0 elif what == rpm.RPMCALLBACK_INST_START: self.hashesPrinted = 0 self.lastPercent = 0 if type(hdr) == type(""): print " %-23.23s" % (hdr), sys.stdout.flush() else: fileName = "%s/%s-%s-%s.%s.rpm" % (path, hdr['name'], hdr['version'], hdr['release'], hdr['arch']) if self.cfg["isatty"]: if self.progressCurrent == 0: printit("Installing") print "%4d:%-23.23s" % (self.progressCurrent + 1, hdr['name']), sys.stdout.flush() else: printit("Installing %s" % fileName) # gets called at the start of each repackage, with a count of # which package and a total of the number of packages aka: # amount: 2 total: 7 for the second package being repackages # out of 7. That sounds obvious doesnt it? elif what == rpm.RPMCALLBACK_REPACKAGE_PROGRESS: pass # print "what: %s amount: %s total: %s hdr: %s path: %s" % ( # what, amount, total, hdr, path) # self.printRpmHash(amount, total, noInc=1) elif what == rpm.RPMCALLBACK_REPACKAGE_START: printit("Repackaging") #sys.stdout.flush() #print "what: %s amount: %s total: %s hdr: %s path: %s" % ( # what, amount, total, hdr, path) elif what == rpm.RPMCALLBACK_INST_PROGRESS: if type(hdr) == type(""): # repackage... self.printRpmHash(amount, total, noInc=1) else: self.printRpmHash(amount, total) elif what == rpm.RPMCALLBACK_TRANS_PROGRESS: self.printRpmHash(amount, total, noInc=1) elif what == rpm.RPMCALLBACK_TRANS_START: self.hashesPrinted = 0 self.lastPercent = 0 self.progressTotal = 1 self.progressCurrent = 0 print "%-23.23s" % "Preparing", sys.stdout.flush() elif what == rpm.RPMCALLBACK_TRANS_STOP: self.printRpmHash(1, 1) self.progressTotal = self.packagesTotal self.progressCurrent = 0 elif (what == rpm.RPMCALLBACK_UNINST_PROGRESS or what == rpm.RPMCALLBACK_UNINST_START or what == rpm.RPMCALLBACK_UNINST_STOP): pass if hasattr(rpm, "RPMCALLBACK_UNPACK_ERROR"): if ((what == rpm.RPMCALLBACK_UNPACK_ERROR) or (what == rpm.RPMCALLBACK_CPIO_ERROR)): pkg = "%s-%s-%s" % (hdr[rpm.RPMTAG_NAME], hdr[rpm.RPMTAG_VERSION], hdr[rpm.RPMTAG_RELEASE]) if what == rpm.RPMCALLBACK_UNPACK_ERROR: raise up2dateErrors.RpmInstallError, ( "There was a rpm unpack error "\ "installing the package: %s" % pkg, pkg) elif what == rpm.RPMCALLBACK_CPIO_ERROR: raise up2dateErrors.RpmInstallError, ( "There was a cpio error "\ "installing the package: %s" % pkg, pkg)
def getHeader(self, pkg, msgCallback = None, progressCallback = None): baseFileName = "%s-%s-%s.%s.rpm" % (pkg[0], pkg[1], pkg[2], pkg[4]) for dir in self.dir_list: tmpFileNames = glob.glob("%s/%s" % (dir, baseFileName)) fileName = "%s/%s" % (self.cfg["storageDir"], baseFileName) fileNames = tmpFileNames if len(fileNames): if os.access(fileNames[0], os.R_OK): if not re.search("rpm$", fileNames[0]): # it wasnt an rpm, so must be a header if os.stat(fileNames[0])[6] == 0: return None fd = open(fileNames[0], "r") # if this header is corrupt, rpmlib exits and we stop ;-< try: hdr = rpmUtils.readHeaderBlob(fd.read()) except: return None self.headerCache[up2dateUtils.pkgToStringArch(pkg)] = hdr fd.close() self.__saveHeader(hdr) return hdr else: fd = os.open(fileNames[0], 0) # verify just the md5 self.ts.pushVSFlags(~(rpm.RPMVSF_NOMD5|rpm.RPMVSF_NEEDPAYLOAD)) try: #hdr = rpm.headerFromPackage(fd) hdr = self.ts.hdrFromFdno(fd) except: os.close(fd) self.ts.popVSFlags() raise up2dateErrors.RpmError("Error reading header") self.ts.popVSFlags() os.close(fd) self.headerCache[up2dateUtils.pkgToStringArch(pkg)] = hdr self.__saveHeader(hdr) return hdr else: return None else: for dir in self.dir_list: fileNames = glob.glob("%s/%s.noarch.*" % (dir, up2dateUtils.pkgToString(pkg))) if len(fileNames): if os.access(fileNames[0], os.R_OK): if not re.search("rpm$", fileNames[0]): # it's not an rpm, must be a header if os.stat(fileNames[0])[6] == 0: return None fd = open(fileNames[0], "r") try: hdr = rpmUtils.readHeaderBlob(fd.read()) except: self.log.log_me("Corrupt header %s, skipping, "\ "will download later..." % fileNames[0]) return None fd.close() self.headerCache[up2dateUtils.pkgToStringArch(pkg)] = hdr return hdr else: if os.access(fileNames[0], os.R_OK): fd = os.open(fileNames[0], 0) try: #hdr = rpm.headerFromPackage(fd) hdr = self.ts.hdrFromFdno(fd) except: os.close(fd) raise up2dateErrors.RpmError("Error reading header") os.close(fd) self.log.log_me("Reading header from: %s" % fileNames) self.headerCache[up2dateUtils.pkgToStringArch(pkg)] = hdr return hdr else: return None else: return None else: return None