nvchecker/nvchecker/source/archpkg.py
lilydjwg 903b414183 cache result during a run
so that different entries can refer to a same software without much overhead.

This is needed because entries may be generated, and only nvchecker can
tell if two entries are expecting the same result because the name may
or may not be relevant.

Closes #81.
2018-10-10 17:03:20 +08:00

30 lines
817 B
Python

# MIT licensed
# Copyright (c) 2013-2017 lilydjwg <lilydjwg@gmail.com>, et al.
import structlog
from . import session, conf_cacheable_with_name
logger = structlog.get_logger(logger_name=__name__)
URL = 'https://www.archlinux.org/packages/search/json/'
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)
async with session.get(URL, params={"name": pkg}) as res:
data = await res.json()
if not data['results']:
logger.error('Arch package not found', name=name)
return
r = [r for r in data['results'] if r['repo'] != 'testing'][0]
if strip_release:
version = r['pkgver']
else:
version = r['pkgver'] + '-' + r['pkgrel']
return version