2017-02-28 07:24:53 +00:00
|
|
|
# MIT licensed
|
2020-08-13 12:42:24 +00:00
|
|
|
# Copyright (c) 2013-2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
2017-02-28 07:24:53 +00:00
|
|
|
|
2020-08-14 12:04:05 +00:00
|
|
|
from nvchecker.api import session, GetVersionError
|
2015-11-05 03:42:07 +00:00
|
|
|
|
2017-07-04 09:04:29 +00:00
|
|
|
URL = 'https://www.archlinux.org/packages/search/json/'
|
2014-09-07 16:09:12 +00:00
|
|
|
|
2020-08-13 12:42:24 +00:00
|
|
|
async def request(pkg):
|
2020-08-15 08:58:13 +00:00
|
|
|
res = await session.get(URL, params={"name": pkg})
|
|
|
|
return res.json()
|
2018-10-10 09:03:20 +00:00
|
|
|
|
2020-08-13 12:42:24 +00:00
|
|
|
async def get_version(name, conf, *, cache, **kwargs):
|
2015-11-05 03:42:07 +00:00
|
|
|
pkg = conf.get('archpkg') or name
|
2020-08-13 12:42:24 +00:00
|
|
|
strip_release = conf.get('strip_release', False)
|
2019-10-28 16:19:07 +00:00
|
|
|
provided = conf.get('provided')
|
|
|
|
|
2020-08-13 12:42:24 +00:00
|
|
|
data = await cache.get(pkg, request)
|
2014-09-07 16:09:12 +00:00
|
|
|
|
|
|
|
if not data['results']:
|
2020-08-14 12:04:05 +00:00
|
|
|
raise GetVersionError('Arch package not found')
|
2014-09-07 16:09:12 +00:00
|
|
|
|
2015-11-05 11:33:09 +00:00
|
|
|
r = [r for r in data['results'] if r['repo'] != 'testing'][0]
|
2019-10-28 16:19:07 +00:00
|
|
|
|
|
|
|
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:
|
2015-11-05 11:33:09 +00:00
|
|
|
version = r['pkgver']
|
|
|
|
else:
|
|
|
|
version = r['pkgver'] + '-' + r['pkgrel']
|
|
|
|
|
2017-07-08 07:59:54 +00:00
|
|
|
return version
|