archpkg: support provides

This commit is contained in:
lilydjwg 2019-10-29 00:19:07 +08:00
parent 7e44dd5767
commit be7e54404e
3 changed files with 29 additions and 2 deletions

View File

@ -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
------------------------------------

View File

@ -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']

View File

@ -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"