How to use the pyalpm.vercmp function in pyalpm

To help you get started, we’ve selected a few pyalpm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github archlinux / pyalpm / test / test_alpm.py View on Github external
def test_vercmp_smaller():
    assert pyalpm.vercmp('1', '2') == -1
github archlinux / pyalpm / test / test_alpm.py View on Github external
def test_vercmp_greater():
    assert pyalpm.vercmp('2', '1') == 1
    assert pyalpm.vercmp('2.0-1', '1.7-6') == 1
github archlinux / pyalpm / test / test_vercmp.py View on Github external
def test_greater(self):
        self.assertEqual(pyalpm.vercmp('2', '1'), 1)
        self.assertEqual(pyalpm.vercmp('2.0-1', '1.7-6'), 1)
github archlinux / pyalpm / test / test_vercmp.py View on Github external
def test_smaller(self):
        self.assertEqual(pyalpm.vercmp('1', '2'), -1)
github Kwpolska / pkgbuilder / pkgbuilder / upgrade.py View on Github external
if aurcache:
        aurlist = aurcache
    else:
        aurlist = pkgbuilder.utils.info(pkglist)
        # It’s THAT easy.  Oh, and by the way: it is much, MUCH faster than
        # others.  It makes only a handful of multiinfo requests (1-2 on most
        # systems) rather than len(installed_packages) info requests.

    upgradable = []
    downgradable = []
    ignored = []

    for rpkg in aurlist:
        lpkg = localdb.get_pkg(rpkg.name)
        if lpkg is not None:
            vc = pyalpm.vercmp(rpkg.version, lpkg.version)
            if vc > 0 and rpkg.name not in ignorelist:
                upgradable.append([rpkg.name, lpkg.version, rpkg.version])
            elif vc > 0 and rpkg.name in ignorelist:
                DS.log.warning("{0} ignored for upgrade.".format(rpkg.name))
                ignored.append([rpkg.name, lpkg.version, rpkg.version])
            elif vc < 0:
                # If the package version is a date or the name ends in
                # -{git,hg,bzr,svn,cvs,darcs}, do not mark it as downgradable.
                # BTW: the above is yours truly’s list of VCS preference, if
                # you added big a gap between git and hg and then HUGE gaps
                # between everything else.

                try:
                    # For epoch packages.  Also, cheating here.
                    v = rpkg.version.split(':')[1]
                except IndexError:
github archlinuxcn / lilac / lilac2 / pkgbuild.py View on Github external
elif line.startswith('replaces = '):
      pkg = line.split()[-1]
      if pkg in _official_packages:
        bad_packages.append(pkg)
    elif line.startswith('pkgname = '):
      pkgnames.append(line.split()[-1])

  _G.epoch, _G.pkgver, _G.pkgrel = _get_package_version(srcinfo)

  # check if the newly built package is older than the existing
  # package in repos or not
  built_version = format_package_version(_G.epoch, _G.pkgver, _G.pkgrel)
  for pkgname in pkgnames:
    try:
      repo_version = _repo_package_versions[pkgname]
      if pyalpm.vercmp(built_version, repo_version) < 0:
        raise DowngradingError(pkgname, built_version, repo_version)
    except KeyError:
      # the newly built package is not in repos yet - fine
      pass

  if bad_groups or bad_packages:
    raise ConflictWithOfficialError(bad_groups, bad_packages)
github Kwpolska / pkgbuilder / pkgbuilder / build.py View on Github external
def _test_dependency(available, difference, wanted):
    """Test a dependency requirement."""
    if '-' in available:
        # Stripping the pkgver.
        available = available.split('-')[0]

    vercmp = pyalpm.vercmp(available, wanted)

    return (('<' in difference and vercmp == -1) or
            ('=' in difference and vercmp == 0) or
            ('>' in difference and vercmp == 1))
github lahwaacz / archweb_manpages / update.py View on Github external
for db in finder.sync_db.get_syncdbs():
        if only_repos and db.name not in only_repos:
            continue
        logger.info("Updating packages from repository '{}'...".format(db.name))
        for pkg in db.pkgcache:
            result = Package.objects.filter(repo=db.name, name=pkg.name)
            assert len(result) in {0, 1}
            if len(result) == 0:
                db_package = Package()
                db_package.repo = db.name
                db_package.name = pkg.name
                db_package.arch = pkg.arch
                updated_pkgs.append(pkg)
            else:
                db_package = result[0]
                if pyalpm.vercmp(db_package.version, pkg.version) == -1:
                    updated_pkgs.append(pkg)
                elif force is True:
                    updated_pkgs.append(pkg)
                else:
                    # skip void update of db_package
                    continue

            # update volatile fields (this is run iff the pkg was added to updated_pkgs)
            db_package.version = pkg.version
            db_package.description = pkg.desc
            db_package.url = pkg.url
            db_package.build_date = datetime.datetime.fromtimestamp(pkg.builddate, tz=datetime.timezone.utc)
            db_package.licenses = pkg.licenses
            db_package.save()

    # delete old packages from the django database
github lilydjwg / nvchecker / nvchecker / sortversion.py View on Github external
# MIT licensed
# Copyright (c) 2013-2017 lilydjwg , et al.

'''
Sort versions using pkg_resource.parse_version or pyalpm.vercmp
'''

__all__ = ["sort_version_keys"]

from functools import cmp_to_key

from pkg_resources import parse_version
try:
  import pyalpm
  vercmp = cmp_to_key(pyalpm.vercmp)
except ImportError:
  def vercmp(k):
    raise NotImplementedError("Using vercmp but pyalpm can not be imported!")

sort_version_keys = {"parse_version": parse_version, "vercmp": vercmp}

if __name__ == '__main__':
  assert(parse_version("v6.0") < parse_version("6.1"))
  assert(parse_version("v6.0") > parse_version("v6.1-stable"))
  assert(vercmp("v6.0") < vercmp("v6.1-stable"))
github archlinux / arch-security-tracker / tracker / pacman.py View on Github external
def sort_packages(packages):
    packages = sorted(packages, key=lambda item: item.arch)
    packages = sorted(packages, key=lambda item: item.db.name)
    packages = sorted(packages, key=cmp_to_key(vercmp, attrgetter('version')), reverse=True)
    return packages