Add ubuntupkg source

This commit is contained in:
Felix Yan 2017-07-06 13:27:24 +08:00
parent c10e88206b
commit 9085dceeb3
4 changed files with 80 additions and 1 deletions

View file

@ -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 <https://packages.ubuntu.com/>`_, 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 <https://code.google.com/>`_ for updates. The version returned is in date format ``%Y%m%d``, e.g. ``20130701``.

View file

@ -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'
)

View file

@ -0,0 +1,48 @@
# MIT licensed
# Copyright (c) 2017 Felix Yan <felixonmars@archlinux.org>, 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

17
tests/test_ubuntupkg.py Normal file
View file

@ -0,0 +1,17 @@
# MIT licensed
# Copyright (c) 2017 Felix Yan <felixonmars@archlinux.org>, 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"