diff --git a/README.rst b/README.rst index 65ac6ec..e9a904e 100644 --- a/README.rst +++ b/README.rst @@ -34,6 +34,7 @@ Contents * `Check Local Pacman Database <#check-local-pacman-database>`_ * `Check Arch Linux official packages <#check-arch-linux-official-packages>`_ * `Check Debian Linux official packages <#check-debian-linux-official-packages>`_ + * `Check Ubuntu Linux official packages <#check-ubuntu-linux-official-packages>`_ * `Check Google Code (hg repository) <#check-google-code-hg-repository>`_ * `Check Google Code (svn repository) <#check-google-code-svn-repository>`_ * `Manually updating <#manually-updating>`_ @@ -333,6 +334,19 @@ suite strip-release Strip the release part. +Check Ubuntu Linux official packages +---------------------------------- +This enables you to track the update of `Ubuntu Linux official packages `_, without needing of apt and an updated local APT database. + +ubuntupkg + Name of the Ubuntu Linux source package. + +suite + Name of the Ubuntu release (xenial, zesty, etc, defaults to None, which means no limit on suite) + +strip-release + Strip the release part. + Check Google Code (hg repository) --------------------------------- Check a mercurial (hg) repository on `Google Code `_ for updates. The version returned is in date format ``%Y%m%d``, e.g. ``20130701``. diff --git a/nvchecker/get_version.py b/nvchecker/get_version.py index 1b60b56..eca9560 100644 --- a/nvchecker/get_version.py +++ b/nvchecker/get_version.py @@ -6,7 +6,7 @@ from importlib import import_module logger = logging.getLogger(__name__) handler_precedence = ( - 'github', 'aur', 'pypi', 'archpkg', 'debianpkg', 'gems', 'pacman', + 'github', 'aur', 'pypi', 'archpkg', 'debianpkg', 'ubuntupkg', 'gems', 'pacman', 'cmd', 'bitbucket', 'gcode_hg', 'gcode_svn', 'regex', 'manual', 'vcs', 'cratesio', 'npm', 'hackage', 'cpan', 'gitlab', 'packagist' ) diff --git a/nvchecker/source/ubuntupkg.py b/nvchecker/source/ubuntupkg.py new file mode 100644 index 0000000..35f8366 --- /dev/null +++ b/nvchecker/source/ubuntupkg.py @@ -0,0 +1,48 @@ +# MIT licensed +# Copyright (c) 2017 Felix Yan , et al. + +import logging +from . import session + +logger = logging.getLogger(__name__) + +URL = 'https://api.launchpad.net/1.0/ubuntu/+archive/primary?ws.op=getPublishedSources&source_name=%s&exact_match=true' + +async def get_version(name, conf): + pkg = conf.get('ubuntupkg') or name + strip_release = conf.getboolean('strip-release', False) + suite = conf.get('suite') + url = URL % pkg + + if suite: + suite = "https://api.launchpad.net/1.0/ubuntu/" + suite + + releases = [] + + while not releases: + async with session.get(url) as res: + data = await res.json() + + if not data.get('entries'): + logger.error('Ubuntu package not found: %s', name) + return name, None + + 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: + logger.error('Ubuntu package not found: %s', name) + + if strip_release: + version = releases[0]['source_package_version'].split("-")[0] + else: + version = releases[0]['source_package_version'] + + return name, version diff --git a/tests/test_ubuntupkg.py b/tests/test_ubuntupkg.py new file mode 100644 index 0000000..bb9ebc0 --- /dev/null +++ b/tests/test_ubuntupkg.py @@ -0,0 +1,17 @@ +# MIT licensed +# Copyright (c) 2017 Felix Yan , et al. + +import pytest +pytestmark = pytest.mark.asyncio + +async def test_ubuntupkg(get_version): + assert await get_version("sigrok-firmware-fx2lafw", {"ubuntupkg": None}) == "0.1.3-1" + +async def test_ubuntupkg_strip_release(get_version): + assert await get_version("sigrok-firmware-fx2lafw", {"ubuntupkg": None, "strip-release": 1}) == "0.1.3" + +async def test_ubuntupkg_suite(get_version): + assert await get_version("sigrok-firmware-fx2lafw", {"ubuntupkg": None, "suite": "xenial"}) == "0.1.2-1" + +async def test_ubuntupkg_suite_with_paging(get_version): + assert await get_version("ffmpeg", {"ubuntupkg": None, "suite": "vivid"}) == "7:2.5.10-0ubuntu0.15.04.1"