From 494c4ddf6768dbb4d93c0d18de9c788ef0b43c91 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Sun, 25 Jul 2021 19:38:26 +0800 Subject: [PATCH] alpm: make `repo` option optional --- docs/usage.rst | 4 ++-- nvchecker_source/alpm.py | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index c5db018..0da4d18 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -814,10 +814,10 @@ alpm Name of the package. repo - Name of the package repository in which the package resides. + Name of the package repository in which the package resides. If not provided, nvchecker will search ``core``, ``extra``, ``community`` and ``multilib``, in that order. dbpath - Path to the ALPM database directory. Default: ``/var/lib/pacman``. + Path to the ALPM database directory. Default: ``/var/lib/pacman``. You need to update the database yourself. strip_release Strip the release part, only return the part before ``-``. diff --git a/nvchecker_source/alpm.py b/nvchecker_source/alpm.py index c40ea6d..6069fad 100644 --- a/nvchecker_source/alpm.py +++ b/nvchecker_source/alpm.py @@ -1,5 +1,5 @@ # MIT licensed -# Copyright (c) 2020 DDoSolitary , et al. +# Copyright (c) 2020-2021 DDoSolitary , et al. from nvchecker.api import GetVersionError from pyalpm import Handle @@ -15,11 +15,21 @@ async def open_db(info): async def get_version(name, conf, *, cache, **kwargs): pkgname = conf.get('alpm', name) dbpath = conf.get('dbpath', '/var/lib/pacman') - repo = conf['repo'] strip_release = conf.get('strip_release', False) provided = conf.get('provided') - db = (await cache.get((dbpath, repo), open_db))[1] - pkg = db.get_pkg(pkgname) + + repo = conf.get('repo') + if repo is None: + repos = ['core', 'extra', 'community', 'multilib'] + else: + repos = [repo] + + for repo in repos: + db = (await cache.get((dbpath, repo), open_db))[1] + pkg = db.get_pkg(pkgname) + if pkg is not None: + break + if pkg is None: raise GetVersionError('package not found in the ALPM database') if provided is None: