Add Debian package source

This commit is contained in:
Felix Yan 2017-07-04 01:14:35 +08:00
parent 780f75eaf7
commit 2b5f2d190d
No known key found for this signature in database
GPG Key ID: 786C63F330D7CB92
4 changed files with 69 additions and 1 deletions

View File

@ -317,6 +317,19 @@ archpkg
strip-release
Strip the release part.
Check Debian Linux official packages
----------------------------------
This enables you to track the update of `Debian Linux official packages <https://packages.debian.org>`_, without needing of apt and an updated local APT database.
debianpkg
Name of the Debian Linux source package.
suite
Name of the Debian release (jessie, wheezy, etc, defaults to sid)
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', 'gems', 'pacman',
'github', 'aur', 'pypi', 'archpkg', 'debianpkg', 'gems', 'pacman',
'cmd', 'bitbucket', 'gcode_hg', 'gcode_svn', 'regex', 'manual', 'vcs',
'cratesio', 'npm', 'hackage', 'cpan', 'gitlab', 'packagist'
)

View File

@ -0,0 +1,39 @@
# MIT licensed
# Copyright (c) 2017 Felix Yan <felixonmars@archlinux.org>, et al.
from functools import partial
import logging
import json
from tornado.httpclient import AsyncHTTPClient
logger = logging.getLogger(__name__)
URL = 'https://sources.debian.net/api/src/%(pkgname)s/?suite=%(suite)s'
def get_version(name, conf, callback):
pkg = conf.get('debianpkg') or name
strip_release = conf.getboolean('strip-release', False)
suite = conf.get('suite') or "sid"
url = URL % {"pkgname": pkg, "suite": suite}
AsyncHTTPClient().fetch(
url, partial(_pkg_done, name, strip_release, callback))
def _pkg_done(name, strip_release, callback, res):
if res.error:
raise res.error
data = json.loads(res.body.decode('utf-8'))
if not data.get('versions'):
logger.error('Debian package not found: %s', name)
callback(name, None)
return
r = data['versions'][0]
if strip_release:
version = r['version'].split("-")[0]
else:
version = r['version']
callback(name, version)

16
tests/test_debianpkg.py Normal file
View File

@ -0,0 +1,16 @@
# MIT licensed
# Copyright (c) 2017 Felix Yan <felixonmars@archlinux.org>, et al.
import os
from tests.helper import ExternalVersionTestCase
class DebianPKGTest(ExternalVersionTestCase):
def test_debianpkg(self):
self.assertEqual(self.sync_get_version("sigrok-firmware-fx2lafw", {"debianpkg": None}), "0.1.3-1")
def test_debianpkg_strip_release(self):
self.assertEqual(self.sync_get_version("sigrok-firmware-fx2lafw", {"debianpkg": None, "strip-release": 1}), "0.1.3")
def test_debianpkg_suite(self):
self.assertEqual(self.sync_get_version("sigrok-firmware-fx2lafw", {"debianpkg": None, "suite": "jessie"}), "0.1.2-1")