name = "-".join(rpmnameparts[0:releasepos]) info = {"nvra": element[0], "summary": summary, "filesize": filesize, "size" : element[2], "group" : element[3], "description" : description, "sourcerpm" : sourcerpm, "url" : url, "license": license} prvdict = {} for n, r, v, f in provides: if n == name and checkver(v, version): prv = (NPrv, n, versionarch) else: prv = (Prv, n, v) prvdict[prv] = True reqdict = {} for n, r, v, f in requires: if not ((r is None or "=" in r) and (Prv, n, v) in prvdict or system_provides.match(n, r, v)): if f: reqdict[(PreReq, n, r, v)] = True else: reqdict[(Req, n, r, v)] = True
def load(self): CM = self.COMPMAP CF = self.COMPFLAGS Pkg = RPMPackage Prv = RPMProvides NPrv = RPMNameProvides PreReq = RPMPreRequires Req = RPMRequires Obs = RPMObsoletes Cnf = RPMConflicts prog = iface.getProgress(self._cache) for h, offset in self.getHeaders(prog): if h[1106]: # RPMTAG_SOURCEPACKAGE continue arch = h[1022] # RPMTAG_ARCH if getArchScore(arch) == 0: continue name = h[1000] # RPMTAG_NAME epoch = h[1003] # RPMTAG_EPOCH if epoch and epoch != "0": # RPMTAG_VERSION, RPMTAG_RELEASE version = "%s:%s-%s" % (epoch, h[1001], h[1002]) else: # RPMTAG_VERSION, RPMTAG_RELEASE version = "%s-%s" % (h[1001], h[1002]) versionarch = "%s@%s" % (version, arch) n = h[1047] # RPMTAG_PROVIDENAME v = h[1113] # RPMTAG_PROVIDEVERSION prvdict = {} for i in range(len(n)): ni = n[i] if not ni.startswith("config("): vi = v[i] if vi and vi[:2] == "0:": vi = vi[2:] if ni == name and checkver(vi, version): prvdict[(NPrv, intern(ni), versionarch)] = True else: prvdict[(Prv, intern(ni), vi or None)] = True prvargs = prvdict.keys() n = h[1049] # RPMTAG_REQUIRENAME if n: f = h[1048] # RPMTAG_REQUIREFLAGS v = h[1050] # RPMTAG_REQUIREVERSION if f == None: f = [0] elif type(f) != list: f = [f] recdict = {} reqdict = {} for i in range(len(n)): ni = n[i] if ni[:7] not in ("rpmlib(", "config("): vi = v[i] or None if vi and vi[:2] == "0:": vi = vi[2:] r = CM.get(f[i]&CF) if not ((r is None or "=" in r) and (Prv, ni, vi) in prvdict or system_provides.match(ni, r, vi)): # RPMSENSE_PREREQ | # RPMSENSE_SCRIPT_PRE | # RPMSENSE_SCRIPT_PREUN | # RPMSENSE_SCRIPT_POST | # RPMSENSE_SCRIPT_POSTUN == 7744 if (f[i]&rpm.RPMSENSE_MISSINGOK): recdict[(f[i]&7744 and PreReq or Req, intern(ni), r, vi)] = True else: reqdict[(f[i]&7744 and PreReq or Req, intern(ni), r, vi)] = True recargs = collapse_libc_requires(recdict.keys()) reqargs = collapse_libc_requires(reqdict.keys()) else: recargs = None reqargs = None n = h[1054] # RPMTAG_CONFLICTNAME if n: f = h[1053] # RPMTAG_CONFLICTFLAGS v = h[1055] # RPMTAG_CONFLICTVERSION if f == None: f = [0] elif type(f) != list: f = [f] cnfargs = [] for i in range(len(n)): vi = v[i] or None if vi and vi[:2] == "0:": vi = vi[2:] cnfargs.append((Cnf, n[i], CM.get(f[i]&CF), vi)) else: cnfargs = [] obstup = (Obs, name, '<', versionarch) n = h[1090] # RPMTAG_OBSOLETENAME if n: f = h[1114] # RPMTAG_OBSOLETEFLAGS v = h[1115] # RPMTAG_OBSOLETEVERSION if f == None: f = [0] elif type(f) != list: f = [f] upgargs = [] for i in range(len(n)): try: vi = v[i] or None except TypeError: vi = None pass if vi and vi[:2] == "0:": vi = vi[2:] upgargs.append((Obs, n[i], CM.get(f[i]&CF), vi)) cnfargs.extend(upgargs) upgargs.append(obstup) else: upgargs = [obstup] disttag = h[1155] # RPMTAG_DISTTAG distepoch = h[1218] # RPMTAG_DISTEPOCH if disttag: distversion = "%s-%s" % (version, disttag) if distepoch: distversion += distepoch versionarch = "%s@%s" % (distversion, arch) pkg = self.buildPackage((Pkg, name, versionarch), prvargs, reqargs, upgargs, cnfargs, recargs) pkg.loaders[self] = offset self._offsets[offset] = pkg self._groups[pkg] = intern(h[rpm.RPMTAG_GROUP])
def load(self): METADATA = nstag(NS_COMMON, "metadata") PACKAGE = nstag(NS_COMMON, "package") NAME = nstag(NS_COMMON, "name") ARCH = nstag(NS_COMMON, "arch") VERSION = nstag(NS_COMMON, "version") SUMMARY = nstag(NS_COMMON, "summary") DESCRIPTION = nstag(NS_COMMON, "description") URL = nstag(NS_COMMON, "url") TIME = nstag(NS_COMMON, "time") SIZE = nstag(NS_COMMON, "size") LOCATION = nstag(NS_COMMON, "location") FORMAT = nstag(NS_COMMON, "format") CHECKSUM = nstag(NS_COMMON, "checksum") FILE = nstag(NS_COMMON, "file") SOURCERPM = nstag(NS_RPM, "sourcerpm") GROUP = nstag(NS_RPM, "group") LICENSE = nstag(NS_RPM, "license") ENTRY = nstag(NS_RPM, "entry") REQUIRES = nstag(NS_RPM, "requires") PROVIDES = nstag(NS_RPM, "provides") CONFLICTS = nstag(NS_RPM, "conflicts") OBSOLETES = nstag(NS_RPM, "obsoletes") DISTTAG = nstag(NS_RPM, "disttag") DISTEPOCH = nstag(NS_RPM, "distepoch") COMPMAP = { "EQ":"=", "LT":"<", "LE":"<=", "GT":">", "GE":">="} # Prepare progress reporting. lastoffset = 0 mod = 0 progress = iface.getProgress(self._cache) # Prepare package information. name = None version = None arch = None disttag = None distepoch = None info = {} reqdict = {} recdict = {} prvdict = {} upgdict = {} cnfdict = {} filedict = {} # Prepare data useful for the iteration skip = None queue = [] file = open(self._filename) for event, elem in cElementTree.iterparse(file, ("start", "end")): tag = elem.tag if event == "start": if not skip and tag == PACKAGE: if elem.get("type") != "rpm": skip = PACKAGE queue.append(elem) elif event == "end": popped = queue.pop() assert popped is elem if skip: if tag == skip: skip = None elif tag == ARCH: if getArchScore(elem.text) == 0: skip = PACKAGE else: arch = elem.text elif tag == NAME: name = elem.text elif tag == VERSION: e = elem.get("epoch") if e and e != "0": version = "%s:%s-%s" % \ (e, elem.get("ver"), elem.get("rel")) else: version = "%s-%s" % \ (elem.get("ver"), elem.get("rel")) elif tag == DISTTAG: disttag = elem.text elif tag == DISTEPOCH: distepoch = elem.text elif tag == SUMMARY: if elem.text: info["summary"] = elem.text elif tag == DESCRIPTION: if elem.text: info["description"] = elem.text elif tag == URL: if elem.text: info["url"] = elem.text elif tag == TIME: info["time"] = int(elem.get("file")) info["build_time"] = int(elem.get("build")) elif tag == SIZE: info["size"] = int(elem.get("package")) if elem.get("installed"): info["installed_size"] = int(elem.get("installed")) elif tag == CHECKSUM: info[elem.get("type")] = elem.text if elem.get("pkgid") == "YES": pkgid = elem.text elif tag == LOCATION: info["location"] = elem.get("href") elif tag == SOURCERPM: if elem.text: info["sourcerpm"] = elem.text elif tag == GROUP: if elem.text: info["group"] = elem.text elif tag == LICENSE: if elem.text: info["license"] = elem.text elif tag == FILE: filedict[elem.text] = True elif tag == ENTRY: ename = elem.get("name") if (not ename or ename[:7] in ("rpmlib(", "config(")): continue if "ver" in elem.keys(): e = elem.get("epoch") v = elem.get("ver") r = elem.get("rel") eversion = v if e and e != "0": eversion = "%s:%s" % (e, eversion) if r: eversion = "%s-%s" % (eversion, r) if "flags" in elem.keys(): erelation = COMPMAP.get(elem.get("flags")) else: erelation = None else: eversion = None erelation = None lasttag = queue[-1].tag if lasttag == REQUIRES: if elem.get("missingok") == "1": recdict[(RPMRequires, ename, erelation, eversion)] = True else: if elem.get("pre") == "1": reqdict[(RPMPreRequires, ename, erelation, eversion)] = True else: reqdict[(RPMRequires, ename, erelation, eversion)] = True elif lasttag == PROVIDES: if ename[0] == "/": filedict[ename] = True else: if ename == name and checkver(eversion, version): eversion = "%s@%s" % (eversion, arch) Prv = RPMNameProvides else: Prv = RPMProvides prvdict[(Prv, ename.encode('utf-8'), eversion)] = True elif lasttag == OBSOLETES: tup = (RPMObsoletes, ename, erelation, eversion) upgdict[tup] = True cnfdict[tup] = True elif lasttag == CONFLICTS: cnfdict[(RPMConflicts, ename, erelation, eversion)] = True elif elem.tag == PACKAGE: # Use all the information acquired to build the package. versionarch = "%s@%s" % (version, arch) upgdict[(RPMObsoletes, name, '<', versionarch)] = True reqargs = [x for x in reqdict if not ((x[2] is None or "=" in x[2]) and (RPMProvides, x[1], x[3]) in prvdict or system_provides.match(x[1], x[2], x[3]))] reqargs = collapse_libc_requires(reqargs) recargs = [x for x in recdict if not ((x[2] is None or "=" in x[2]) and (RPMProvides, x[1], x[3]) in prvdict or system_provides.match(x[1], x[2], x[3]))] prvargs = prvdict.keys() cnfargs = cnfdict.keys() upgargs = upgdict.keys() if disttag: distversion = "%s-%s" % (version, disttag) if distepoch: distversion += distepoch versionarch = "%s@%s" % (distversion, arch) pkg = self.buildPackage((RPMPackage, name, versionarch), prvargs, reqargs, upgargs, cnfargs, recargs) pkg.loaders[self] = info # Store the provided files for future usage. if filedict: for filename in filedict: lst = self._fileprovides.get(filename) if not lst: self._fileprovides[filename] = [pkg] else: lst.append(pkg) if pkgid: self._pkgids[pkgid] = pkg # Reset all information. name = None version = None arch = None disttag = None distepoch = None pkgid = None reqdict.clear() recdict.clear() prvdict.clear() upgdict.clear() cnfdict.clear() filedict.clear() # Do not clear it. pkg.loaders has a reference. info = {} # Update progress offset = file.tell() div, mod = divmod(offset-lastoffset+mod, BYTESPERPKG) lastoffset = offset progress.add(div) progress.show() elem.clear() file.close()
def test_checknone(self): self.assertTrue(checkver(None, None))
def test_checkdistepoch(self): self.assertTrue(checkver("1-2:3", "1-2"))
def test_checkstring(self): self.assertTrue(checkver("1", "1"))
info = { "nvra": element[0], "summary": summary, "filesize": filesize, "size": element[2], "group": element[3], "description": description, "sourcerpm": sourcerpm, "url": url, "license": license } prvdict = {} for n, r, v, f in provides: if n == name and checkver(v, version): prv = (NPrv, n, versionarch) else: prv = (Prv, n, v) prvdict[prv] = True reqdict = {} for n, r, v, f in requires: if not ((r is None or "=" in r) and (Prv, n, v) in prvdict or system_provides.match(n, r, v)): if f: reqdict[(PreReq, n, r, v)] = True else: reqdict[(Req, n, r, v)] = True cnfdict = {}