diff --git a/nvchecker/get_version.py b/nvchecker/get_version.py index e6697c2..972eace 100644 --- a/nvchecker/get_version.py +++ b/nvchecker/get_version.py @@ -3,7 +3,7 @@ from importlib import import_module logger = logging.getLogger(__name__) handler_precedence = ( - 'github', 'aur', 'pypi', 'pacman', + 'github', 'aur', 'pypi', 'archpkg', 'pacman', 'cmd', 'gcode_hg', 'regex', ) diff --git a/nvchecker/source/archpkg.py b/nvchecker/source/archpkg.py new file mode 100644 index 0000000..58eaba8 --- /dev/null +++ b/nvchecker/source/archpkg.py @@ -0,0 +1,25 @@ +from functools import partial +import json + +from tornado.httpclient import AsyncHTTPClient + +URL = 'https://www.archlinux.org/packages/search/json/?name=' + +def get_version(name, conf, callback): + pkg = conf['archpkg'] + url = URL + pkg + AsyncHTTPClient().fetch(url, partial(_pkg_done, name, callback)) + +def _pkg_done(name, callback, res): + if res.error: + raise res.error + + data = json.loads(res.body.decode('utf-8')) + + if not data['results']: + logger.error('Arch package not found: %s', name) + callback(name, None) + return + + version = data['results'][0]['pkgver'] + callback(name, version)