add new source: archpkg

This commit is contained in:
lilydjwg 2014-09-08 00:09:12 +08:00
parent 81a17ef690
commit 819a2c69d3
2 changed files with 26 additions and 1 deletions

View File

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

View File

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