From 96368ade49db95e0fb60793de313bc5aea78352c Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Mon, 1 Jul 2013 17:41:01 +0800 Subject: [PATCH] add AUR support --- get_version.py | 15 ++++++++++++++- sample_config.ini | 6 ++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/get_version.py b/get_version.py index 5101491..ef9a6f6 100644 --- a/get_version.py +++ b/get_version.py @@ -3,6 +3,7 @@ import sre_constants import logging from functools import partial import queue +import json from pkg_resources import parse_version from tornado.httpclient import AsyncHTTPClient @@ -10,7 +11,7 @@ import tornado.process from tornado.ioloop import IOLoop logger = logging.getLogger(__name__) -handler_precedence = ('cmd', 'regex') +handler_precedence = ('aur', 'cmd', 'regex') def get_version(name, conf, callback): g = globals() @@ -47,6 +48,18 @@ def _get_version_by_regex(name, regex, encoding, callback, res): else: callback(name, version) +AUR_URL = 'https://aur.archlinux.org/rpc.php?type=info&arg=' + +def get_version_by_aur(name, conf, callback): + aurname = conf.get('aur') or name + url = AUR_URL + aurname + AsyncHTTPClient().fetch(url, partial(_aur_done, name, callback)) + +def _aur_done(name, callback, res): + data = json.loads(res.body.decode('utf-8')) + version = data['results']['Version'] + callback(name, version) + cmd_q = queue.Queue() cmd_q.running = False diff --git a/sample_config.ini b/sample_config.ini index 9039abf..1919161 100644 --- a/sample_config.ini +++ b/sample_config.ini @@ -12,3 +12,9 @@ regex = 7\.3\.\d+ [google-chrome] cmd = wget -qO- http://dl.google.com/linux/chrome/rpm/stable/x86_64/repodata/other.xml.gz | zgrep "google-chrome-stable" | awk -F\" '{print $10"-"$12}' + +[you-get] +aur = python-you-get-git + +[fbcat] +aur