def installedHeadersNameVersion(pkgName, version): _ts = transaction.initReadOnlyTransaction() mi = _ts.dbMatch('Name', pkgName) for h in mi: if h['version'] == version: return h return None
def __init__(self, cacheObject = None): # this is the cache, stuff here is only in storageDir self.cfg = config.initUp2dateConfig() self.log = up2dateLog.initLog() self.dir_list = [self.cfg["storageDir"]] self.ts = transaction.initReadOnlyTransaction() PackageSource.__init__(self, cacheObject = cacheObject)
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 installedHeadersNameVersion(pkgName,version): _ts = transaction.initReadOnlyTransaction() mi = _ts.dbMatch('Name', pkgName) for h in mi: if h['version'] == version: return h return None
def getAdvisoryInfo(pkg, warningCallback=None): log = up2dateLog.initLog() cfg = config.initUp2dateConfig() # no errata for non rhn use if not cfg['useRhn']: return None s = rpcServer.getServer() ts = transaction.initReadOnlyTransaction() mi = ts.dbMatch('Providename', pkg[0]) if not mi: return None # odd,set h to last value in mi. mi has to be iterated # to get values from it... h = None for h in mi: break info = None # in case of package less errata that somehow apply if h: try: pkgName = "%s-%s-%s" % (h['name'], h['version'], h['release']) log.log_me("getAdvisoryInfo for %s" % pkgName) info = rpcServer.doCall(s.errata.getPackageErratum, up2dateAuth.getSystemId(), pkg) except rpclib.Fault, f: if warningCallback: warningCallback(f.faultString) return None
def getInstalledPackageList(msgCallback=None, progressCallback=None, getArch=None, getInfo=None): """ Return list of packages. Package is hash with keys name, epoch, version, release and optionaly arch and cookie """ pkg_list = [] if msgCallback != None: msgCallback(_("Getting list of packages installed on the system")) _ts = transaction.initReadOnlyTransaction() count = 0 total = 0 for h in _ts.dbMatch(): if h == None: break count = count + 1 total = count count = 0 for h in _ts.dbMatch(): if h == None: break package = { 'name': h['name'], 'epoch': h['epoch'], 'version': h['version'], 'release': h['release'], 'installtime': h['installtime'] } if package['epoch'] == None: package['epoch'] = "" else: # convert it to string package['epoch'] = "%s" % package['epoch'] if getArch: package['arch'] = h['arch'] # the arch on gpg-pubkeys is "None"... if package['arch']: pkg_list.append(package) elif getInfo: if h['arch']: package['arch'] = h['arch'] if h['cookie']: package['cookie'] = h['cookie'] pkg_list.append(package) else: pkg_list.append(package) if progressCallback != None: progressCallback(count, total) count = count + 1 pkg_list.sort( key=lambda x: (x['name'], x['epoch'], x['version'], x['release'])) return pkg_list
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 __init__(self, cacheObject = None, packagePath = None): self.cfg = config.initUp2dateConfig() self.log = up2dateLog.initLog() self.dir_list = up2dateUtils.getPackageSearchPath() if packagePath: self.dir_list = self.dir_list + packagePath self.ts = transaction.initReadOnlyTransaction() PackageSource.__init__(self, cacheObject = cacheObject)
def getInstalledPackageList(msgCallback = None, progressCallback = None, getArch=None, getInfo = None): """ Return list of packages. Package is hash with keys name, epoch, version, release and optionaly arch and cookie """ pkg_list = [] if msgCallback != None: msgCallback(_("Getting list of packages installed on the system")) _ts = transaction.initReadOnlyTransaction() count = 0 total = 0 for h in _ts.dbMatch(): if h == None: break count = count + 1 total = count count = 0 for h in _ts.dbMatch(): if h == None: break package = { 'name': h['name'], 'epoch': h['epoch'], 'version': h['version'], 'release': h['release'], 'installtime': h['installtime'] } if package['epoch'] == None: package['epoch'] = "" else: # convert it to string package['epoch'] = "%s" % package['epoch'] if getArch: package['arch'] = h['arch'] # the arch on gpg-pubkeys is "None"... if package['arch']: pkg_list.append(package) elif getInfo: if h['arch']: package['arch'] = h['arch'] if h['cookie']: package['cookie'] = h['cookie'] pkg_list.append(package) else: pkg_list.append(package) if progressCallback != None: progressCallback(count, total) count = count + 1 pkg_list.sort(key=lambda x:(x['name'], x['epoch'], x['version'], x['release'])) return pkg_list
def checkRpmMd5(fileName): _ts = transaction.initReadOnlyTransaction() # XXX Verify only header+payload MD5 with f*cked up contrapositive logic _ts.pushVSFlags(~(rpm.RPMVSF_NOMD5|rpm.RPMVSF_NEEDPAYLOAD)) fdno = os.open(fileName, os.O_RDONLY) try: h = _ts.hdrFromFdno(fdno) except rpm.error, e: _ts.popVSFlags() return 0
def checkRpmMd5(fileName): _ts = transaction.initReadOnlyTransaction() # XXX Verify only header+payload MD5 with f*cked up contrapositive logic _ts.pushVSFlags(~(rpm.RPMVSF_NOMD5 | rpm.RPMVSF_NEEDPAYLOAD)) fdno = os.open(fileName, os.O_RDONLY) try: h = _ts.hdrFromFdno(fdno) except rpm.error, e: _ts.popVSFlags() return 0
def installedHeaderByKeyword(**kwargs): """ just cause this is such a potentially useful looking method... """ _ts = transaction.initReadOnlyTransaction() mi = _ts.dbMatch() for keyword in kwargs.keys(): mi.pattern(keyword, rpm.RPMMIRE_GLOB, kwargs[keyword]) # we really shouldnt be getting multiples here, but what the heck headerList = [] for h in mi: headerList.append(h) return headerList
def installedHeaderIndex(**kwargs): _ts = transaction.initReadOnlyTransaction() mi = _ts.dbMatch() for keyword in kwargs.keys(): mi.pattern(keyword, rpm.RPMMIRE_GLOB, kwargs[keyword]) # we really shouldnt be getting multiples here, but what the heck instanceList = [] for h in mi: instance = mi.instance() instanceList.append(instance) return instanceList
def installedHeaderByKeyword(**kwargs): _ts = transaction.initReadOnlyTransaction() mi = _ts.dbMatch() for keyword in kwargs.keys(): mi.pattern(keyword, rpm.RPMMIRE_GLOB, kwargs[keyword]) # we really shouldnt be getting multiples here, but what the heck headerList = [] for h in mi: #print "%s-%s-%s.%s" % ( h['name'], h['version'], h['release'], h['arch']) headerList.append(h) return headerList
def getInstalledPackageList(msgCallback=None, progressCallback=None, getArch=None, getInfo=None): pkg_list = [] if msgCallback != None: msgCallback("Getting list of packages installed on the system") _ts = transaction.initReadOnlyTransaction() count = 0 total = 0 for h in _ts.dbMatch(): if h == None: break count = count + 1 total = count count = 0 for h in _ts.dbMatch(): if h == None: break name = h['name'] epoch = h['epoch'] if epoch == None: epoch = "" version = h['version'] release = h['release'] if getArch: arch = h['arch'] # the arch on gpg-pubkeys is "None"... if arch: pkg_list.append([name, version, release, epoch, arch]) elif getInfo: arch = h['arch'] cookie = h['cookie'] if arch and cookie: pkg_list.append([name, version, release, epoch, arch, cookie]) else: pkg_list.append([name, version, release, epoch]) if progressCallback != None: progressCallback(count, total) count = count + 1 pkg_list.sort() return pkg_list
def getInstalledPackageList(msgCallback = None, progressCallback = None, getArch=None, getInfo = None): pkg_list = [] if msgCallback != None: msgCallback("Getting list of packages installed on the system") _ts = transaction.initReadOnlyTransaction() count = 0 total = 0 for h in _ts.dbMatch(): if h == None: break count = count + 1 total = count count = 0 for h in _ts.dbMatch(): if h == None: break name = h['name'] epoch = h['epoch'] if epoch == None: epoch = "" version = h['version'] release = h['release'] if getArch: arch = h['arch'] # the arch on gpg-pubkeys is "None"... if arch: pkg_list.append([name, version, release, epoch, arch]) elif getInfo: arch = h['arch'] cookie = h['cookie'] if arch and cookie: pkg_list.append([name, version, release, epoch, arch, cookie]) else: pkg_list.append([name, version, release, epoch]) if progressCallback != None: progressCallback(count, total) count = count + 1 pkg_list.sort() return pkg_list
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 getInstalledObsoletes(msgCallback=None, progressCallback=None, getArch=None): _ts = transaction.initReadOnlyTransaction() obs_list = [] global obsHash if obsHash: return obsHash obsHash = {} count = 0 total = 0 for h in _ts.dbMatch(): if h == None: break count = count + 1 total = count for h in _ts.dbMatch(): if h == None: break obsoletes = h['obsoletes'] name = h['name'] version = h['version'] release = h['release'] nvr = "%s-%s-%s" % (name, version, release) if obsoletes: obs_list.append((nvr, obsoletes)) if progressCallback != None: progressCallback(count, total) count = count + 1 for nvr, obs in obs_list: for ob in obs: if not obsHash.has_key(ob): obsHash[ob] = [] obsHash[ob].append(nvr) return obsHash
def getInstalledObsoletes(msgCallback = None, progressCallback = None, getArch = None): _ts = transaction.initReadOnlyTransaction() obs_list = [] global obsHash if obsHash: return obsHash obsHash = {} count = 0 total = 0 for h in _ts.dbMatch(): if h == None: break count = count + 1 total = count for h in _ts.dbMatch(): if h == None: break obsoletes = h['obsoletes'] name = h['name'] version = h['version'] release = h['release'] nvr = "%s-%s-%s" % (name, version, release) if obsoletes: obs_list.append((nvr, obsoletes)) if progressCallback != None: progressCallback(count, total) count = count + 1 for nvr,obs in obs_list: for ob in obs: if not obsHash.has_key(ob): obsHash[ob] = [] obsHash[ob].append(nvr) return obsHash
def rpm2cpio(fdno, out=sys.stdout, bufsize=2048): """Performs roughly the equivalent of rpm2cpio(8). Reads the package from fdno, and dumps the cpio payload to out, using bufsize as the buffer size.""" ts = transaction.initReadOnlyTransaction() hdr = ts.hdrFromFdno(fdno) del ts compr = hdr[rpm.RPMTAG_PAYLOADCOMPRESSOR] or 'gzip' #XXX FIXME #if compr == 'bzip2': # TODO: someone implement me! #el if compr != 'gzip': raise RpmUtilsError, \ 'Unsupported payload compressor: "%s"' % compr f = gzip.GzipFile(None, 'rb', None, os.fdopen(fdno, 'rb', bufsize)) while 1: tmp = f.read(bufsize) if tmp == "": break out.write(tmp) f.close()
def importGpgKeyring(): # gpg is really really annoying the first time you run it # do this so the bits we care about are always atleast the second running command = "/usr/bin/gpg -q --list-keys > /dev/null 2>&1" fdno = os.popen(command) fdno.close() # method to import an existing keyring into the new # rpm mechanism of storing supported keys as virtual # packages in the database for fingerprint in findGpgFingerprints(): if findKey(fingerprint): continue command = "/usr/bin/gpg %s --export %s" % ( rpmUtils.getGPGflags(), fingerprint) # print command fdno = os.popen(command) pubkey = fdno.read() fdno.close() _ts = transaction.initReadOnlyTransaction() _ts.pgpImportPubkey(pubkey) #_ts.pgpPrtPkts(pubkey) return 0
def importGpgKeyring(): # gpg is really really annoying the first time you run it # do this so the bits we care about are always atleast the second running command = "/usr/bin/gpg -q --list-keys > /dev/null 2>&1" fdno = os.popen(command) fdno.close() # method to import an existing keyring into the new # rpm mechanism of storing supported keys as virtual # packages in the database for fingerprint in findGpgFingerprints(): if findKey(fingerprint): continue command = "/usr/bin/gpg %s --export %s" % (rpmUtils.getGPGflags(), fingerprint) # print command fdno = os.popen(command) pubkey = fdno.read() fdno.close() _ts = transaction.initReadOnlyTransaction() _ts.pgpImportPubkey(pubkey) #_ts.pgpPrtPkts(pubkey) return 0
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 headerFromFilename(filename): ts = transaction.initReadOnlyTransaction() hdr = hdrFromPackage(ts, filename) return hdr