2020-08-14 10:25:48 +00:00
|
|
|
# MIT licensed
|
|
|
|
# Copyright (c) 2019 lilydjwg <lilydjwg@gmail.com>, et al.
|
|
|
|
|
2020-08-14 12:04:05 +00:00
|
|
|
from nvchecker.api import GetVersionError
|
2020-08-14 10:25:48 +00:00
|
|
|
|
|
|
|
API_URL = 'https://repology.org/api/v1/project/{}'
|
|
|
|
|
|
|
|
async def get_version(name, conf, *, cache, **kwargs):
|
|
|
|
project = conf.get('repology') or name
|
|
|
|
repo = conf.get('repo')
|
2020-10-29 14:14:29 +00:00
|
|
|
subrepo = conf.get('subrepo')
|
2020-08-14 10:25:48 +00:00
|
|
|
if not repo:
|
|
|
|
raise GetVersionError('repo field is required for repology source')
|
|
|
|
|
|
|
|
url = API_URL.format(project)
|
|
|
|
data = await cache.get_json(url)
|
|
|
|
|
2020-10-29 14:14:29 +00:00
|
|
|
pkgs = [pkg for pkg in data if pkg['repo'] == repo]
|
|
|
|
if not pkgs:
|
2020-08-14 10:25:48 +00:00
|
|
|
raise GetVersionError('package is not found', repo=repo)
|
|
|
|
|
2020-10-29 14:14:29 +00:00
|
|
|
if subrepo:
|
|
|
|
pkgs = [pkg for pkg in pkgs if pkg.get('subrepo') == subrepo]
|
|
|
|
if not pkgs:
|
|
|
|
raise GetVersionError('package is not found in subrepo',
|
|
|
|
repo=repo, subrepo=subrepo)
|
|
|
|
|
|
|
|
versions = [pkg['version'] for pkg in pkgs]
|
2020-10-30 09:57:31 +00:00
|
|
|
return versions
|