nvchecker/nvchecker_source/debianpkg.py

26 lines
748 B
Python
Raw Normal View History

2017-07-03 17:14:35 +00:00
# MIT licensed
2020-08-14 10:25:48 +00:00
# Copyright (c) 2020 lilydjwg <lilydjwg@gmail.com>, et al.
2017-07-03 17:14:35 +00:00
# Copyright (c) 2017 Felix Yan <felixonmars@archlinux.org>, et al.
2020-08-14 12:04:05 +00:00
from nvchecker.api import GetVersionError
2017-07-03 17:14:35 +00:00
2017-12-05 13:58:26 +00:00
URL = 'https://sources.debian.org/api/src/%(pkgname)s/?suite=%(suite)s'
2017-07-03 17:14:35 +00:00
2020-08-14 10:25:48 +00:00
async def get_version(name, conf, *, cache, **kwargs):
2017-07-03 17:14:35 +00:00
pkg = conf.get('debianpkg') or name
2020-08-14 10:25:48 +00:00
strip_release = conf.get('strip_release', False)
2017-07-03 17:14:35 +00:00
suite = conf.get('suite') or "sid"
url = URL % {"pkgname": pkg, "suite": suite}
2020-08-14 10:25:48 +00:00
data = await cache.get_json(url)
2017-07-03 17:14:35 +00:00
if not data.get('versions'):
2020-08-14 10:25:48 +00:00
raise GetVersionError('Debian package not found')
2017-07-03 17:14:35 +00:00
r = data['versions'][0]
if strip_release:
version = r['version'].split("-")[0]
else:
version = r['version']
return version