Python rpm.labelCompare() Examples
The following are 9
code examples of rpm.labelCompare().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rpm
, or try the search function
.
Example #1
Source File: util.py From mock with GNU General Public License v2.0 | 5 votes |
def cmpKernelVer(str1, str2): 'compare two kernel version strings and return -1, 0, 1 for less, equal, greater' import rpm return rpm.labelCompare(('', str1, ''), ('', str2, ''))
Example #2
Source File: specfile.py From rdopkg with Apache License 2.0 | 5 votes |
def nvrcmp(nvr1, nvr2): if not RPM_AVAILABLE: raise exception.RpmModuleNotAvailable() t1 = string_to_version(nvr1) t2 = string_to_version(nvr2) return rpm.labelCompare(t1, t2)
Example #3
Source File: specfile.py From rdopkg with Apache License 2.0 | 5 votes |
def vcmp(v1, v2): if not RPM_AVAILABLE: raise exception.RpmModuleNotAvailable() t1 = ('0', v1, '') t2 = ('0', v2, '') return rpm.labelCompare(t1, t2)
Example #4
Source File: helpers.py From the-new-hotness with GNU Lesser General Public License v2.1 | 5 votes |
def _compare_rpm_labels(lhs, rhs): lhs_epoch, lhs_version, lhs_release = lhs rhs_epoch, rhs_version, rhs_release = rhs result = _compare_rpm_field(lhs_epoch, rhs_epoch) if result: return result result = _compare_rpm_field(lhs_version, rhs_version) if result: return result return _compare_rpm_field(lhs_release, rhs_release)
Example #5
Source File: helpers.py From the-new-hotness with GNU Lesser General Public License v2.1 | 5 votes |
def rpm_cmp(v1, v2): diff = _compare_rpm_labels((None, v1, None), (None, v2, None)) return diff
Example #6
Source File: anchore_utils.py From anchore with Apache License 2.0 | 5 votes |
def is_pkg_vuln(vtag, vpkg, flavor, ivers, iversonly, vvers): isvuln = False #print "cve-scan: " + vpkg + "\n\tvulnerability package version: " + vvers + "\n\timage package version: " + ivers if vtag == 'VulnerableIn' and vvers == 'all': isvuln = True elif vvers != 'None': if flavor == 'RHEL': fixfile = vpkg + "-" + vvers + ".arch.rpm" imagefile = vpkg + "-" + ivers + ".arch.rpm" (n1, v1, r1, e1, a1) = splitFilename(imagefile) (n2, v2, r2, e2, a2) = splitFilename(fixfile) if vtag == 'FixedIn': if rpm.labelCompare(('1', v1, r1), ('1', v2, r2)) < 0: isvuln = True elif vtag == 'VulnerableIn': if ivers == vvers or iversonly == vvers: isvuln = True elif flavor == 'DEB': if vtag == 'FixedIn': if ivers != vvers: comp_rc = dpkg_compare_versions(ivers, 'lt', vvers) if comp_rc == 0: isvuln = True elif vtag == 'VulnerableIn': if ivers == vvers or iversonly == vvers: isvuln = True elif flavor == "ALPINE": if vtag == 'FixedIn': comp_rc = apkg_compare_versions(ivers, 'lt', vvers) if comp_rc == 0: isvuln = True elif vtag == 'VulnerableIn': if ivers == vvers or iversonly == vvers: isvuln = True else: isvuln = True return(isvuln)
Example #7
Source File: util.py From koschei with GNU General Public License v2.0 | 5 votes |
def compare_evr(evr1, evr2): def epoch_to_str(epoch): return str(epoch) if epoch is not None else None evr1, evr2 = ((epoch_to_str(e), v, r) for (e, v, r) in (evr1, evr2)) return rpm.labelCompare(evr1, evr2)
Example #8
Source File: common.py From koschei with GNU General Public License v2.0 | 5 votes |
def rpmvercmp(v1, v2): return rpm.labelCompare((None, None, v1), (None, None, v2))
Example #9
Source File: anchore_utils.py From anchore with Apache License 2.0 | 4 votes |
def compare_package_versions(imageId, pkga, vera, pkgb, verb): # if ret == 0, versions are equal # if ret > 0, vers A is greater than version B # if ret < 0, vers A is less than version B fulla = '-'.join([str(pkga), str(vera)]) fullb = '-'.join([str(pkgb), str(verb)]) if fulla == fullb: return(0) distrometa = get_distro_from_imageId(imageId) idistro = distrometa['DISTRO'] idistrovers = distrometa['DISTROVERS'] ilikedistro = distrometa['LIKEDISTRO'] distrodict = get_distro_flavor(idistro, idistrovers, likedistro=ilikedistro) flavor = distrodict['flavor'] if flavor == "RHEL": fixfile = pkgb + "-" + verb + ".arch.rpm" imagefile = pkga + "-" + vera + ".arch.rpm" (n1, v1, r1, e1, a1) = splitFilename(imagefile) (n2, v2, r2, e2, a2) = splitFilename(fixfile) if rpm.labelCompare(('1', v1, r1), ('1', v2, r2)) < 0: return(-1) else: return(1) elif flavor == "DEB": comp_rc = dpkg_compare_versions(vera, 'lt', verb) if comp_rc == 0: return(-1) else: return(1) elif flavor == "ALPINE": comp_rc = apkg_compare_versions(vera, 'lt', verb) if comp_rc == 0: return(-1) else: return(1) else: raise ValueError("unsupported distro, cannot compare package versions") return(0)