diff --git a/README.rst b/README.rst index 07c1c3a..c7392d8 100644 --- a/README.rst +++ b/README.rst @@ -438,7 +438,10 @@ archpkg Name of the Arch Linux package. strip-release - Strip the release part. + Strip the release part, only return part before ``-``. + +provided + Instead of the package version, return the version this package provides. Its value is what the package provides, and ``strip-release`` takes effect too. This is best used with libraries. Check Debian Linux official packages ------------------------------------ diff --git a/nvchecker/source/archpkg.py b/nvchecker/source/archpkg.py index cb6a192..9540a79 100644 --- a/nvchecker/source/archpkg.py +++ b/nvchecker/source/archpkg.py @@ -14,6 +14,8 @@ get_cacheable_conf = conf_cacheable_with_name('archpkg') async def get_version(name, conf, **kwargs): pkg = conf.get('archpkg') or name strip_release = conf.getboolean('strip-release', False) + provided = conf.get('provided') + async with session.get(URL, params={"name": pkg}) as res: data = await res.json() @@ -22,7 +24,13 @@ async def get_version(name, conf, **kwargs): return r = [r for r in data['results'] if r['repo'] != 'testing'][0] - if strip_release: + + if provided: + provides = dict(x.split('=', 1) for x in r['provides']) + version = provides.get(provided, None) + if strip_release: + version = version.split('-', 1)[0] + elif strip_release: version = r['pkgver'] else: version = r['pkgver'] + '-' + r['pkgrel'] diff --git a/tests/test_archpkg.py b/tests/test_archpkg.py index a057054..5021672 100644 --- a/tests/test_archpkg.py +++ b/tests/test_archpkg.py @@ -12,3 +12,19 @@ async def test_archpkg(get_version): @flaky async def test_archpkg_strip_release(get_version): assert await get_version("ipw2100-fw", {"archpkg": None, "strip-release": 1}) == "1.3" + +@flaky +async def test_archpkg_provided(get_version): + assert await get_version("jsoncpp", { + "archpkg": None, + "provided": "libjsoncpp.so", + }) == "21-64" + +@flaky +async def test_archpkg_provided_strip(get_version): + assert await get_version("jsoncpp", { + "archpkg": None, + "provided": "libjsoncpp.so", + "strip-release": True, + }) == "21" +