Commit 973879dc authored by Seblu's avatar Seblu
Browse files

Add pacman compare mode

Allow to check package against local pacman synced db

Add new deps to alpm
parent 54a57f7f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ pkgdesc='Archlinux Version Controller'
arch=('any')
url='https://github.com/seblu/archversion'
license=('GPL2')
depends=('python' 'python-xdg' 'bash')
depends=('python' 'pyalpm' 'python-xdg')

prepare() {
  cd "$startdir/.."
+5 −5
Original line number Diff line number Diff line
# Options in this section will be applied on all others
# unless they are defined.
[DEFAULT]
# Comparaison method (archweb, aur, cache, none)
compare = archweb
# Comparaison method (See below)
compare = pacman

# Url request timeout in seconds
#timeout =
@@ -12,7 +12,7 @@ compare = archweb
# URL to check (upstream)
url =

# Comparaison method (archlinux, aur, cache, none)
# Comparaison method (pacman, archweb, aur, cache, none)
#compare =

# Url request timeout in seconds
@@ -42,12 +42,12 @@ url =
# e.g: version.replace("-", "_")
#eval_compare =

# Archlinux compare mode: Only look on arch architectur
# List of architectures (archweb compare mode only)
# Comma separated list (not stripped)
# e.g: x86_64,any
#arch =

# Archlinux compare mode: Only look into repository
# List of repositories (archweb and pacman compare mode)
# Comma separated list (not stripped)
# e.g: communty-testing,community
# repo =
 No newline at end of file
+26 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import json
import logging
import re
import sys
import pycman

class VersionController(object):
    '''
@@ -42,6 +43,7 @@ class VersionController(object):
        # populate compare table
        # need to be done manually to avoid get_upstream to be in
        self.compare_table = {
            "pacman": self.get_version_pacman,
            "archweb": self.get_version_archweb,
            "aur": self.get_version_aur,
            "cache": self.get_version_cache,
@@ -86,6 +88,30 @@ class VersionController(object):
            raise VersionNotFound("Upstream check failed: %s" % exp)
        assert(False)

    @staticmethod
    def get_version_pacman(name, value):
        '''Return pacman version'''
        logging.debug("Get pacman version")
        # Load pacman
        pacman = pycman.config.PacmanConfig("/etc/pacman.conf").initialize_alpm()
        # Map db and name
        repos = dict((db.name, db) for db in pacman.get_syncdbs())
        # filter if repo is provided
        if "repo" in value:
            allowed_repos = value.get("repo").split(",")
            for r in list(repos.keys()):
                if r not in allowed_repos:
                    repos.pop(r)
        # looking into db for package name
        for repo, db in repos.items():
            logging.debug("Repo %s" % repo)
            pkg = db.get_pkg(name)
            if pkg is not None:
                v = pkg.version.rsplit("-")[0]
                logging.debug("pacman version is : %s" % v)
                return v
        raise VersionNotFound("No pacman package found")

    @staticmethod
    def get_version_archweb(name, value):
        '''Return archweb version'''