nvchecker/nvchecker_source/repology.py

30 lines
896 B
Python
Raw Normal View History

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')
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)
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)
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]
return versions