nvchecker/nvchecker_source/ubuntupkg.py

46 lines
1.2 KiB
Python
Raw Normal View History

2017-07-06 05:27:24 +00:00
# MIT licensed
2020-08-14 10:25:48 +00:00
# Copyright (c) 2020 lilydjwg <lilydjwg@gmail.com>, et al.
2017-07-06 05:27:24 +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-06 05:27:24 +00:00
URL = 'https://api.launchpad.net/1.0/ubuntu/+archive/primary?ws.op=getPublishedSources&source_name=%s&exact_match=true'
2020-08-14 10:25:48 +00:00
async def get_version(name, conf, *, cache, **kwargs):
2017-07-06 05:27:24 +00:00
pkg = conf.get('ubuntupkg') or name
2020-08-14 10:25:48 +00:00
strip_release = conf.get('strip_release', False)
2017-07-06 05:27:24 +00:00
suite = conf.get('suite')
url = URL % pkg
if suite:
suite = "https://api.launchpad.net/1.0/ubuntu/" + suite
releases = []
while not releases:
2020-08-14 10:25:48 +00:00
data = await cache.get_json(url)
2017-07-06 05:27:24 +00:00
if not data.get('entries'):
2020-08-14 10:25:48 +00:00
raise GetVersionError('Ubuntu package not found')
2017-07-06 05:27:24 +00:00
releases = [r for r in data["entries"] if r["status"] == "Published"]
if suite:
releases = [r for r in releases if r["distro_series_link"] == suite]
if "next_collection_link" not in data:
break
url = data["next_collection_link"]
if not releases:
2020-08-14 10:25:48 +00:00
raise GetVersionError('Ubuntu package not found')
return
2017-07-06 05:27:24 +00:00
if strip_release:
version = releases[0]['source_package_version'].split("-")[0]
else:
version = releases[0]['source_package_version']
return version