def test_evr(self): le = self.labels[0][0:3] ge = self.labels[1][0:3] self.assertEqual(rpm.labelCompare(le, ge), -1) self.assertEqual(rpm.labelCompare(ge, le), 1) self.assertEqual(rpm.labelCompare(ge, ge), 0) self.assertEqual(rpm.labelCompare(ge, ge), 0)
def test_evrd(self): le = self.labels[0] ge = self.labels[1] self.assertEqual(rpm.labelCompare(le, ge), -1) self.assertEqual(rpm.labelCompare(ge, le), 1) self.assertEqual(rpm.labelCompare(ge, ge), 0) self.assertEqual(rpm.labelCompare(ge, ge), 0)
def compare(self, other): def ends_with_which(s): for idx, suff in enumerate(self.suffixes): if s.lower().endswith(suff): return idx # Easier compare return len(self.suffixes) raw_compare = rpm.labelCompare(self.evr, other.evr) non_beta_compare = rpm.labelCompare(self.evr_nosuff, other.evr_nosuff) if non_beta_compare != raw_compare: if ends_with_which(self.version) < ends_with_which(other.version): return -1 return 1 return raw_compare
def parse_smart_pkglist(output): pkglist = {} for line in output.splitlines(): if line == '': continue fields = line.split() pkgname = fields[0] (version, arch) = fields[1].split('@') if pkgname not in pkglist: pkglist[pkgname] = {} pkglist[pkgname][arch] = version elif arch not in pkglist[pkgname]: pkglist[pkgname][arch] = version else: stored_ver = pkglist[pkgname][arch] # The rpm.labelCompare takes version broken into 3 components # It returns: # 1, if first arg is higher version # 0, if versions are same # -1, if first arg is lower version rc = rpm.labelCompare(stringToVersion(version), stringToVersion(stored_ver)) if rc > 0: # Update version pkglist[pkgname][arch] = version return pkglist
def compare_nvr(nvr_dict1, nvr_dict2, ignore_epoch=False): """Compare two N-V-R dictionaries. @param nvr_dict1: {name, version, release, epoch} @type nvr_dict1: dict @param nvr_dict2: {name, version, release, epoch} @type nvr_dict2: dict @param ignore_epoch: ignore epoch during the comparison @type ignore_epoch: bool @return: nvr1 newer than nvr2: 1, same nvrs: 0, nvr1 older: -1, different names: ValueError @rtype: int """ nvr1 = nvr_dict1.copy() nvr2 = nvr_dict2.copy() nvr1["epoch"] = nvr1.get("epoch", None) nvr2["epoch"] = nvr2.get("epoch", None) if nvr1["name"] != nvr2["name"]: raise ValueError("Package names doesn't match: %s, %s" % (nvr1["name"], nvr2["name"])) if ignore_epoch: nvr1["epoch"] = 0 nvr2["epoch"] = 0 if nvr1["epoch"] is None: nvr1["epoch"] = "" if nvr2["epoch"] is None: nvr2["epoch"] = "" return rpm.labelCompare((str(nvr1["epoch"]), str(nvr1["version"]), str(nvr1["release"])), (str(nvr2["epoch"]), str(nvr2["version"]), str(nvr2["release"])))
def compare_builds(testing_build, stable_build, untag, tag): if stable_build["package_name"] == testing_build["package_name"]: if ( rpm.labelCompare( (str(testing_build["epoch"]), testing_build["version"], testing_build["release"]), (str(stable_build["epoch"]), stable_build["version"], stable_build["release"]), ) < 0 ): print "%s is older than %s" % (testing_build["nvr"], stable_build["nvr"]) try: build = PackageBuild.byNvr(testing_build["nvr"]) for update in build.updates: if update.status != "testing": print "%s not testing in bodhi!" % update.title raise SQLObjectNotFound else: if untag: print "Obsoleting via bodhi" update.obsolete(newer=stable_build["nvr"]) else: print "Need to obsolete via bodhi" except SQLObjectNotFound: if untag: print "Untagging via koji" koji = get_session() koji.untagBuild(tag, testing_build["nvr"], force=True) else: print "Need to untag koji build %s" % testing_build["nvr"]
def _build_rpmdict(rpmlist, dir=".", verbose=False): """ Scans through the given directory, extracts RPM headers from the files in the rpmlist. """ rpmdict = {} dupes = {} for pkg in rpmlist: hdr = get_rpm_hdr(dir + "/" + pkg) # Ugh. Unsanitary repo. We'll try to make the best of it. # We're going to use whichever package rpm.labelCompare # deems is the "best". if rpmdict.has_key(hdr['name']): e1, v1, r1 = get_evr(hdr) e2, v2, r2 = get_evr(rpmdict[hdr['name']]['hdr']) # return 1: a is newer than b # 0: a and b are the same version # -1: b is newer than a if rpm.labelCompare((e1, v1, r1), (e2, v2, r2)) == 1: rpmdict[hdr['name']] = {"pkg": pkg, "hdr": hdr} if verbose: print "WARNING! Duplicate package: %s. Using %s" % \ (hdr['name'], pkg) else: if verbose: print "WARNING! Duplicate package: %s. Using %s" % \ (hdr['name'], rpmdict[hdr['name']]['pkg']) dupes[hdr['name']] = {"pkg": pkg, "hdr": hdr} else: rpmdict[hdr['name']] = {"pkg": pkg, "hdr": hdr} return rpmdict, dupes
def latestRpmEVR(directory, rpmname): epo, ver, rel = None, '1.0', '0' filenames = glob.glob(os.path.join(directory, "%s-*.noarch.rpm" % rpmname)) if not filenames: return epo, ver, rel hdr = [epo, ver, rel] for rpm_file in filenames: cmd = [ 'rpm', '-qp', '--qf', '%{EPOCH}-|_%{VERSION}-|_%{RELEASE}', rpm_file ] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout_value, stderr_value = p.communicate() if p.returncode > 0: raise CertToolException(repr(stdout_value) + repr(stderr_value)) epo, ver, rel = string.split(stdout_value, '-|_') if epo and epo == '(none)': epo = None h = [epo, ver, rel] comp = rpm.labelCompare(h, hdr) if comp > 0: hdr = h return hdr
def _compare_rpmlists(srclist, destlist, verbose=False): """ compares two lists of rpms, looking for new/updated rpms """ updates = {} newpkgs = {} keys = srclist.keys() keys.sort() for pkg in keys: if verbose: print "DEBUG: Examining %s" % pkg if destlist.has_key(pkg): e1, v1, r1 = get_evr(srclist[pkg]["hdr"]) e2, v2, r2 = get_evr(destlist[pkg]["hdr"]) # return 1: a is newer than b # 0: a and b are the same version # -1: b is newer than a if rpm.labelCompare((e1, v1, r1), (e2, v2, r2)) == 1: if verbose: print "INFO: " "Update found: %s - s(%s, %s, %s) d(%s, %s, %s)" % (pkg, e1, v1, r1, e2, v2, r2) updates[pkg] = srclist[pkg] else: if verbose: e1 = str(srclist[pkg]["hdr"]["epoch"]) v1 = str(srclist[pkg]["hdr"]["version"]) r1 = str(srclist[pkg]["hdr"]["release"]) print "INFO: New package found: %s (%s, %s, %s)" % (pkg, e1, v1, r1) newpkgs[pkg] = srclist[pkg] return updates, newpkgs
def comparePoEVR(po1, po2): """ Compare two Package or PackageEVR objects. """ (e1, v1, r1) = (po1.epoch, po1.version, po1.release) (e2, v2, r2) = (po2.epoch, po2.version, po2.release) return rpm.labelCompare((e1, v1, r1), (e2, v2, r2))
def test_01_condor_run_pbs(self): core.skip_ok_unless_installed('condor', 'blahp') core.skip_ok_unless_installed('torque-mom', 'torque-server', 'torque-scheduler', by_dependency=True) self.skip_bad_unless(core.state['jobs.env-set'], 'job environment not set') self.skip_bad_unless(service.is_running('condor'), 'condor not running') self.skip_bad_unless(service.is_running('pbs_server'), 'pbs not running') command = ('condor_run', '-u', 'grid', '-a', 'grid_resource=pbs', '-a', 'periodic_remove=JobStatus==5', '/bin/env') # Figure out whether the installed BLAHP package is the same as or later # than "blahp-1.18.11.bosco-4.osg*" (in the RPM sense), because it's the # first build in which the job environments are correctly passed to PBS. # The release following "osg" does not matter and it is easier to ignore # the OS major version. This code may be a useful starting point for a # more general library function. blahp_envra = core.get_package_envra('blahp') blahp_pbs_has_env_vars = (rpm.labelCompare( ['blahp', '1.18.11.bosco', '4.osg'], blahp_envra[1:4]) <= 0) self.run_job_in_tmp_dir(command, 'condor_run a Condor job', verify_environment=blahp_pbs_has_env_vars)
def rpmvercmp(rpm1, rpm2): (e1, v1, r1) = stringToVersion(rpm1) (e2, v2, r2) = stringToVersion(rpm2) if e1 is not None: e1 = str(e1) if e2 is not None: e2 = str(e2) rc = rpm.labelCompare((e1, v1, r1), (e2, v2, r2)) return rc
def __cmp__(self, other): if self.n > other.n: return 1 elif self.n < other.n: return -1 return rpm.labelCompare((self.e, self.v, self.r), (other.e, other.v, other.r))
def version_test(version, c_op, c_ver): result = rpm.labelCompare(ver_to_label(version), ver_to_label(c_ver)) if ((result == 1 and c_op in ['>', '>=']) or (result == 0 and c_op in ['=', '>=', '<=']) or (result == -1 and c_op in ['<', '<='])): return True return False
def _build_rpmdict(rpmlist, dir=".", verbose=False): """ Scans through the given directory, extracts RPM headers from the files in the rpmlist. """ rpmdict = {} dupes = {} for pkg in rpmlist: hdr = get_rpm_hdr(dir + "/" + pkg) # Ugh. Unsanitary repo. We'll try to make the best of it. # We're going to use whichever package rpm.labelCompare # deems is the "best". if rpmdict.has_key(hdr["name"]): e1, v1, r1 = get_evr(hdr) e2, v2, r2 = get_evr(rpmdict[hdr["name"]]["hdr"]) # return 1: a is newer than b # 0: a and b are the same version # -1: b is newer than a if rpm.labelCompare((e1, v1, r1), (e2, v2, r2)) == 1: rpmdict[hdr["name"]] = {"pkg": pkg, "hdr": hdr} if verbose: print "WARNING! Duplicate package: %s. Using %s" % (hdr["name"], pkg) else: if verbose: print "WARNING! Duplicate package: %s. Using %s" % (hdr["name"], rpmdict[hdr["name"]]["pkg"]) dupes[hdr["name"]] = {"pkg": pkg, "hdr": hdr} else: rpmdict[hdr["name"]] = {"pkg": pkg, "hdr": hdr} return rpmdict, dupes
def __cmp__(self, other): assert type(self) == type(other), "%r vs %r" % (self, other) if not self.name == other.name: raise RuntimeError("NVRs for different names: %s %s" % (self.name, other.name)) this_version = (None, self.version, self.release) other_version = (None, other.version, other.release) return rpm.labelCompare(this_version, other_version) # @UndefinedVariable
def compare_package_versions(version1, version2): """Compare two EVR versions against each other. :param version1: The version to be compared. :type version1: str :param version2: The version to compare against. :type version2: str :example: >>> match = compare_package_versions("5.14.10-300.fc35", "5.14.15-300.fc35") >>> match # -1 .. note:: Since the return type is a int, this could be difficult to understand the meaning of each number, so here is a quick list of the meaning from every possible number: * -1 if the evr1 is less then evr2 version * 0 if the evr1 is equal evr2 version * 1 if the evr1 is greater than evr2 version :return: Return a number indicating if the versions match, are less or greater then. :rtype: int """ evr1 = utils.string_to_version(version1) evr2 = utils.string_to_version(version2) return rpm.labelCompare(evr1, evr2)
def valid_rpm(in_rpm): """ check a given rpm matches the current installed rpm :param in_rpm: a dict of name, version and release to check against :return: bool representing whether the rpm is valid or not """ rpm_state = False ts = rpm.TransactionSet() mi = ts.dbMatch('name', in_rpm['name']) if mi: # check the version is OK rpm_hdr = mi.next() rc = rpm.labelCompare(('1', rpm_hdr['version'], rpm_hdr['release']), ('1', in_rpm['version'], in_rpm['release'])) if rc < 0: # -1 version old return False else: # 0 = version match, 1 = version exceeds min requirement return True else: # rpm not installed return False
def compare_builds(testing_build, stable_build, untag, tag): if stable_build['package_name'] == testing_build['package_name']: if rpm.labelCompare( (str(testing_build['epoch']), testing_build['version'], testing_build['release']), (str(stable_build['epoch']), stable_build['version'], stable_build['release'])) < 0: print "%s is older than %s" % (testing_build['nvr'], stable_build['nvr']) try: build = PackageBuild.byNvr(testing_build['nvr']) for update in build.updates: if update.status != 'testing': print "%s not testing in bodhi!" % update.title raise SQLObjectNotFound else: if untag: print "Obsoleting via bodhi" update.obsolete(newer=stable_build['nvr']) else: print "Need to obsolete via bodhi" except SQLObjectNotFound: if untag: print "Untagging via koji" koji = get_session() koji.untagBuild(tag, testing_build['nvr'], force=True) else: print "Need to untag koji build %s" % testing_build['nvr']
def compare_builds(testing_build, stable_build, untag, tag): if stable_build['package_name'] == testing_build['package_name']: if rpm.labelCompare((str(testing_build['epoch']), testing_build['version'], testing_build['release']), (str(stable_build['epoch']), stable_build['version'], stable_build['release'])) < 0: print "%s is older than %s" % (testing_build['nvr'], stable_build['nvr']) try: build = PackageBuild.byNvr(testing_build['nvr']) for update in build.updates: if update.status != 'stable': print "%s not stable in bodhi!" % update.title raise SQLObjectNotFound else: pass # TODO: do the untagging? except SQLObjectNotFound: if untag: print "Untagging via koji" koji = get_session() koji.untagBuild(tag, testing_build['nvr'], force=True) else: print "Need to untag koji build %s" % testing_build['nvr']
def main(): python38 = set(pathlib.Path('python38.pkgs').read_text().splitlines()) kojirepo = set(pathlib.Path('koji.repoquery').read_text().splitlines()) py39repo = set( pathlib.Path('python39koji.repoquery').read_text().splitlines()) kojidict = dict(split(pkg) for pkg in kojirepo) py39dict = dict(split(pkg) for pkg in py39repo) todo = set() for pkg in sorted(python38): if pkg not in py39dict: continue sign = SIGNS[rpm.labelCompare(kojidict[pkg], py39dict[pkg])] print( f'{pkg: <30} {"-".join(kojidict[pkg])} {sign} {"-".join(py39dict[pkg])}' ) if sign == '>': todo.add(pkg) print() for pkg in sorted(todo): print(pkg)
def __cmp__(self, other): """Compare two medias >>> media = InstallationMedia(False) >>> media.version, media.release = "2.5", "0" >>> media.full_version '2.5-0' >>> installed = InstalledMedia(False) >>> installed.version, installed.release = "2.6", "0" >>> installed.full_version '2.6-0' >>> media < installed True >>> media == installed False >>> media > installed False >>> media.version = "2.6" >>> media == installed True >>> media.release = "1" >>> media == installed False >>> media > installed True """ assert InstallationMedia in type(other).mro() this_version = ('1', self.version, self.release) other_version = ('1', other.version, other.release) return rpm.labelCompare( this_version, # @UndefinedVariable other_version)
def _compare_rpmlists(srclist, destlist, verbose=False): """ compares two lists of rpms, looking for new/updated rpms """ updates = {} newpkgs = {} keys = srclist.keys() keys.sort() for pkg in keys: if verbose: print "DEBUG: Examining %s" % pkg if destlist.has_key(pkg): e1, v1, r1 = get_evr(srclist[pkg]['hdr']) e2, v2, r2 = get_evr(destlist[pkg]['hdr']) # return 1: a is newer than b # 0: a and b are the same version # -1: b is newer than a if rpm.labelCompare((e1, v1, r1), (e2, v2, r2)) == 1: if verbose: print "INFO: " \ "Update found: %s - s(%s, %s, %s) d(%s, %s, %s)" % \ (pkg, e1, v1, r1, e2, v2, r2) updates[pkg] = srclist[pkg] else: if verbose: e1 = str(srclist[pkg]['hdr']['epoch']) v1 = str(srclist[pkg]['hdr']['version']) r1 = str(srclist[pkg]['hdr']['release']) print "INFO: New package found: %s (%s, %s, %s)" % \ (pkg, e1, v1, r1) newpkgs[pkg] = srclist[pkg] return updates, newpkgs
def __cmp__(self, other): """Compare two medias >>> media = InstallationMedia(False) >>> media.version, media.release = "2.5", "0" >>> media.full_version '2.5-0' >>> installed = InstalledMedia(False) >>> installed.version, installed.release = "2.6", "0" >>> installed.full_version '2.6-0' >>> media < installed True >>> media == installed False >>> media > installed False >>> media.version = "2.6" >>> media == installed True >>> media.release = "1" >>> media == installed False >>> media > installed True """ assert InstallationMedia in type(other).mro() this_version = ('1', self.version, self.release) other_version = ('1', other.version, other.release) return rpm.labelCompare(this_version, # @UndefinedVariable other_version)
def cmpEVR(p1, p2): # compare criterion: arch compatibility first, then repo # priority, and version last a1 = p1.arch() a2 = p2.arch() if str(a1) != str(a2): if a1.compatible_with(a2): return -1 else: return 1 # Priority of a repository is an integer value between 0 (the # highest priority) and 99 (the lowest priority) pr1 = int(p1.repoInfo().priority()) pr2 = int(p2.repoInfo().priority()) if pr1 > pr2: return -1 elif pr1 < pr2: return 1 ed1 = p1.edition() ed2 = p2.edition() (e1, v1, r1) = map(str, [ed1.epoch(), ed1.version(), ed1.release()]) (e2, v2, r2) = map(str, [ed2.epoch(), ed2.version(), ed2.release()]) return rpm.labelCompare((e1, v1, r1), (e2, v2, r2))
def version_cmp(ver1, ver2): ''' .. versionadded:: 2015.5.4 Do a cmp-style comparison on two packages. Return -1 if ver1 < ver2, 0 if ver1 == ver2, and 1 if ver1 > ver2. Return None if there was a problem making the comparison. CLI Example: .. code-block:: bash salt '*' pkg.version_cmp '0.2-001' '0.2.0.1-002' ''' if HAS_RPM: try: cmp_result = rpm.labelCompare( _string_to_evr(ver1), _string_to_evr(ver2) ) if cmp_result not in (-1, 0, 1): raise Exception( 'cmp result \'{0}\' is invalid'.format(cmp_result) ) return cmp_result except Exception as exc: log.warning( 'Failed to compare version \'{0}\' to \'{1}\' using ' 'rpmUtils: {2}'.format(ver1, ver2, exc) ) return salt.utils.version_cmp(ver1, ver2)
def compare_version(self, other): if self.packagetype == 'R' and other.packagetype == 'R': return labelCompare(self._version_string_rpm(), other._version_string_rpm()) elif self.packagetype == 'D' and other.packagetype == 'D': vs = Version(self._version_string_deb()) vo = Version(other._version_string_deb()) return version_compare(vs, vo)
def version_compare(evr1, evr2): """Compare the EVRs (epoch, version, release) of two RPMs and return - -1 if the first EVR is older than the second, - 0 if the two arguments are equal, - 1 if the first EVR is newer than the second. Each EVR may be specified as a string (of the form "V-R" or "E:V-R"), or as a 3-element tuple or list. """ if is_string(evr1): epoch1, version1, release1 = stringToVersion(evr1) elif isinstance(evr1, bytes): epoch1, version1, release1 = stringToVersion(evr1.decode()) else: epoch1, version1, release1 = evr1 if is_string(evr2): epoch2, version2, release2 = stringToVersion(evr2) elif isinstance(evr2, bytes): epoch2, version2, release2 = stringToVersion(evr2.decode()) else: epoch2, version2, release2 = evr2 return rpm.labelCompare((epoch1, version1, release1), (epoch2, version2, release2))
def is_dashboard_juno_or_above(self, actual_dashboard_version): """Returns True if installed openstack-dashboard package belongs to Juno or higher sku, False if not. """ # override for ubuntu when required import rpm juno_version = ('0', '2014.2.2', '1.el7') return rpm.labelCompare(actual_dashboard_version, juno_version) >= 0
def compare(pkgA, pkgB): pkgdictA = koji.parse_NVR(pkgA) pkgdictB = koji.parse_NVR(pkgB) rc = rpm.labelCompare((pkgdictA['epoch'], pkgdictA['version'], pkgdictA['release']), (pkgdictB['epoch'], pkgdictB['version'], pkgdictB['release'])) return rc
def check_downgrade(old_version, new_version): old_version, old_release = old_version.rsplit('-', 1) new_version, new_release = new_version.rsplit('-', 1) # labelCompare returns 1 if tup1 > tup2 # It is ok to default epoch to 0, since rhts-devel doesn't generate # task packages with epoch > 0 return rpm.labelCompare(('0', old_version, old_release), ('0', new_version, new_release)) == 1
def __cmp__(self, obj): """ The convention for __cmp__ is: a < b : return -1 a = b : return 0 a > b : return 1 """ return rpm.labelCompare(("1", self.name, self.ver), ("1", obj.name, obj.ver))
def __cmp__(self, other): """ This function is called by comparison operators to compare two versions. The rpm.labelCompare() function takes two versions, specified in a list structure, and returns -1, 0, or 1. """ return rpm.labelCompare((self.epoch, self.version, self.release), (other.epoch, other.version, other.release))
def __lt__(self, other): if (self.na < other.na): return True if (self.na > other.na): return False one = (str(self.epoch), self.version, self.release) two = (str(other.epoch), other.version, other.release) return rpm.labelCompare(one, two) <= -1
def _do_compare(self, other): assert type(self) == type(other), "%r vs %r" % (self, other) if not self.name == other.name: raise RuntimeError("NVRs for different names: %s %s" % (self.name, other.name)) this_version = (None, self.version, self.release) other_version = (None, other.version, other.release) return rpm.labelCompare(this_version, other_version)
def compare_rpm_versions(a: RpmMetadata, b: RpmMetadata) -> int: # This is not a rule, but it makes sense that our libs don't want to # compare versions of different RPMs if a.name != b.name: raise ValueError( f"Cannot compare RPM versions when names do not match") return rpm.labelCompare((str(a.epoch), a.version, a.release), (str(b.epoch), b.version, b.release))
def __cmp__(self, other): if not self.name == other.name: raise RuntimeError("NVRs for different names: %s %s" % (self.name, other.name)) this_version = (None, self.version, self.release) other_version = (None, other.version, other.release) return rpm.labelCompare( this_version, # @UndefinedVariable other_version)
def compare(pkgA, pkgB): pkgdictA = koji.parse_NVR(pkgA) pkgdictB = koji.parse_NVR(pkgB) rc = rpm.labelCompare( (pkgdictA['epoch'], pkgdictA['version'], pkgdictA['release']), (pkgdictB['epoch'], pkgdictB['version'], pkgdictB['release'])) return rc
def __ge__(self, other): if not isinstance(other, NEVR): return NotImplemented if self.name != other.name: return NotImplemented return labelCompare((self.epoch, self.version, self.release), (other.epoch, other.version, other.release)) != -1
def compare_builds(build1, build2): """Compare versions of two builds Return -1, 0 or 1 if version of build1 is lesser, equal or greater than build2. """ evr1 = evr(build1) evr2 = evr(build2) return rpm.labelCompare(evr1, evr2)
def testEvrFilterGT(self): nlimitstr = '38:mozilla-1.5-2.rhfc1.dag' nlimit = rhnDependency.make_evr(nlimitstr) pack = self.solve_deps_with_limits(self.serv_id, [self.filename], 2, limit_operator='>', limit=nlimitstr) assert rpm.labelCompare((pack[self.filename][0][3], pack[self.filename][0][1], pack[self.filename][0][2]), (nlimit['epoch'], nlimit['version'], nlimit['release'])) == 1
def nvre_compare(t1, t2): def build_evr(p): evr = [p[3], p[1], p[2]] evr = list(map(str, evr)) if evr[0] == "": evr[0] = None return evr if t1[0] != t2[0]: raise ValueError("You should only compare packages with the same name") evr1, evr2 = (build_evr(t1), build_evr(t2)) return rpm.labelCompare(evr1, evr2)
def testEvrFilterLTE( self ): nlimitstr = '38:mozilla-1.5-2.rhfc1.dag' nlimit = rhnDependency.make_evr( nlimitstr ) pack = self.solve_deps_with_limits( self.serv_id,\ [self.filename],\ 2,\ limit_operator = '<=',\ limit = nlimitstr ) ret = rpm.labelCompare( ( pack[self.filename][0][3], pack[self.filename][0][1], pack[self.filename][0][2] ),\ ( nlimit['epoch'], nlimit['version'], nlimit['release']) ) assert ret == -1 or ret == 0
def __cmp__(self, other): ret = cmp(self.name, other.name) if ret == 0: rel_self = str(self.release).split('.')[0] rel_other = str(other.release).split('.')[0] # pylint: disable=E1101 ret = rpm.labelCompare((str(self.epoch), str(self.version), rel_self), (str(other.epoch), str(other.version), rel_other)) if ret == 0: ret = cmp(self.arch, other.arch) return ret
def testUp2dateFilterLTE1(self): nlimitstr = 'mozilla-1-1:35' nlimit = rhnDependency.make_evr(nlimitstr) pack = self.up2date.solveDependencies_with_limits(self.myserver.getSystemId(), [self.filename], 2, limit_operator='<=', limit=nlimitstr) ret = rpm.labelCompare((pack[self.filename][0][3], pack[self.filename][0][1], pack[self.filename][0][2]), (nlimit['epoch'], nlimit['version'], nlimit['release'])) assert ret == -1 or ret == 0
def check_if_reboot_required(self, host_highest): ver, rel = self.kernel.rsplit('-') rel = rel.rstrip('xen') rel = rel.rstrip('PAE') kernel_ver = ('', str(ver), str(rel)) host_highest_ver = ('', host_highest.version, host_highest.release) if labelCompare(kernel_ver, host_highest_ver) == -1: self.reboot_required = True else: self.reboot_required = False
def rpmCompareVersion(first_version,second_version): """This function compares two RPM version numbers. Each argument is a list of three variables [epoch,version,release]. The function returns: * 1 if first_version is considered greater than second_version * 0 if the both version are equal * -1 if first_version is considered less than second_version """ return rpm.labelCompare(first_version,second_version)
def testUp2dateFilterGT( self ): nlimitstr = '35:mozilla-0-0' nlimit = rhnDependency.make_evr( nlimitstr ) pack = self.up2date.solveDependencies_with_limits( self.myserver.getSystemId(),\ [self.filename],\ 2,\ limit_operator = '>',\ limit = nlimitstr ) ret = rpm.labelCompare( ( pack[self.filename][0][3], pack[self.filename][0][1], pack[self.filename][0][2] ),\ ( nlimit['epoch'], nlimit['version'], nlimit['release']) ) assert ret == 1
def cmpEVR(p1, p2): a1 = p1.arch() a2 = p2.arch() if str(a1) != str(a2): if a1.compatible_with(a2): return -1 else: return 1 ed1 = p1.edition() ed2 = p2.edition() (e1, v1, r1) = map(str, [ed1.epoch(), ed1.version(), ed1.release()]) (e2, v2, r2) = map(str, [ed2.epoch(), ed2.version(), ed2.release()]) return rpm.labelCompare((e1, v1, r1), (e2, v2, r2))
def latest_pkg(pkg1, pkg2, version_key='version', release_key='release', epoch_key='epoch'): # Sometimes empty epoch is a space, sometimes its an empty string, which # breaks the comparison, strip it here to fix t1 = (pkg1[epoch_key].strip(), pkg1[version_key], pkg1[release_key]) t2 = (pkg2[epoch_key].strip(), pkg2[version_key], pkg2[release_key]) result = rpm.labelCompare(t1, t2) if result == 1: return pkg1 elif result == -1: return pkg2 else: return None
def hdrLabelCompare(hdr1, hdr2): """ take two RPMs or headers and compare them for order """ if hdr1['name'] == hdr2['name']: hdr1 = [hdr1['epoch'] or None, hdr1['version'], hdr1['release']] hdr2 = [hdr2['epoch'] or None, hdr2['version'], hdr2['release']] if hdr1[0]: hdr1[0] = str(hdr1[0]) if hdr2[0]: hdr2[0] = str(hdr2[0]) return rpm.labelCompare(hdr1, hdr2) elif hdr1['name'] < hdr2['name']: return -1 return 1
def cmpRpmHeader(a, b): """ cmp() implemetation suitable for use with sort. """ n1 = str(a.get('name')) e1 = str(a.get('epoch')) v1 = str(a.get('version')) r1 = str(a.get('release')) n2 = str(b.get('name')) e2 = str(b.get('epoch')) v2 = str(b.get('version')) r2 = str(b.get('release')) return rpm.labelCompare((e1, v1, r1), (e2, v2, r2))
def check_if_reboot_required(self, host_highest): to_strip = ['xen', '-xen', 'PAE', '-pae', '-default', 'vanilla', '-pv'] kernel = self.kernel for s in to_strip: if kernel.endswith(s): kernel = kernel[:-len(s)] ver, rel = kernel.rsplit('-') kernel_ver = ('', str(ver), str(rel)) host_highest_ver = ('', host_highest.version, host_highest.release) if labelCompare(kernel_ver, host_highest_ver) == -1: self.reboot_required = True else: self.reboot_required = False
def packageCompare(self, package, x, y): """ Compares two packages based on version If the versions are the same, tries to get the mtime of the changes file receives two tuples (repo, version) as input """ res = rpm.labelCompare((None, str(x[1]), "1"), (None, str(y[1]), "1")) # only fetch mtimes if the package is in the repo if res == 0 and x[1] and y[1]: return cmp(self.data[x[0]].mtime(package), self.data[y[0]].mtime(package)) else: return res
def compare_pkgs(pkg1, pkg2): """Helper function to compare two package versions return 1 if a > b return 0 if a == b return -1 if a < b""" # the 'or 0' is because some epoch's that should be 0 but are None # and in rpm.labelCompare(), None < 0 e1 = str(pkg1['epoch'] or 0) v1 = str(pkg1['version']) r1 = str(pkg1['release']) e2 = str(pkg2['epoch'] or 0) v2 = str(pkg2['version']) r2 = str(pkg2['release']) #print "(%s, %s, %s) vs (%s, %s, %s)" % (e1, v1, r1, e2, v2, r2) return rpm.labelCompare((e1, v1, r1), (e2, v2, r2))
def clean_testing_builds(untag=False): koji = get_session() for release in Release.select(): stable_builds = koji.listTagged(release.stable_tag, latest=True) stable_nvrs = [build["nvr"] for build in stable_builds] print "Fetched %d builds tagged with %s" % (len(stable_builds), release.stable_tag) testing_builds = koji.listTagged(release.testing_tag, latest=True) print "Fetched %d builds tagged with %s" % (len(testing_builds), release.testing_tag) testing_nvrs = [build["nvr"] for build in testing_builds] for testing_build in testing_builds: for build in testing_builds: compare_builds(testing_build, build, untag, release.testing_tag) for build in stable_builds: compare_builds(testing_build, build, untag, release.testing_tag) # Find testing updates that aren't in the list of latest builds for update in PackageUpdate.select( AND( PackageUpdate.q.releaseID == release.id, PackageUpdate.q.status == "testing", PackageUpdate.q.request == None, ) ): for build in update.builds: if build.nvr not in testing_nvrs: latest_testing = None latest_stable = None for testing in testing_nvrs: if testing.startswith(build.package.name + "-"): latest_testing = testing break for stable in stable_nvrs: if stable.startswith(build.package.name + "-"): latest_stable = stable break if latest_testing: koji_build = koji.getBuild(build.nvr) latest_build = koji.getBuild(latest_testing) if rpm.labelCompare(build_evr(koji_build), build_evr(latest_build)) < 0: print "%s in testing, latest_testing = %s, latest_stable = %s" % ( update.title, latest_testing, latest_stable, ) if untag: print "Obsoleting %s" % update.title update.obsolete(newer=latest_testing)