mirror of
https://github.com/lilydjwg/nvchecker
synced 2025-03-09 21:07:33 +00:00
添加代理支持(使用 pycurl)
This commit is contained in:
parent
4d75b63c95
commit
15fb385235
@ -61,6 +61,9 @@ regex
|
|||||||
|
|
||||||
When multiple version strings are found, the maximum of those is chosen.
|
When multiple version strings are found, the maximum of those is chosen.
|
||||||
|
|
||||||
|
proxy
|
||||||
|
The HTTP proxy to use. The format is ``host:port``, e.g. ``localhost:8087``.
|
||||||
|
|
||||||
Find with a Command
|
Find with a Command
|
||||||
-------------------
|
-------------------
|
||||||
Use a shell command line to get the version. The output is striped first, so trailing newlines do not bother.
|
Use a shell command line to get the version. The output is striped first, so trailing newlines do not bother.
|
||||||
|
@ -4,6 +4,7 @@ import logging
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
import queue
|
import queue
|
||||||
import json
|
import json
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
from pkg_resources import parse_version
|
from pkg_resources import parse_version
|
||||||
from tornado.httpclient import AsyncHTTPClient
|
from tornado.httpclient import AsyncHTTPClient
|
||||||
@ -13,6 +14,12 @@ from tornado.ioloop import IOLoop
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
handler_precedence = ('github', 'aur', 'cmd', 'regex')
|
handler_precedence = ('github', 'aur', 'cmd', 'regex')
|
||||||
|
|
||||||
|
try:
|
||||||
|
import pycurl
|
||||||
|
AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")
|
||||||
|
except ImportError:
|
||||||
|
pycurl = None
|
||||||
|
|
||||||
def get_version(name, conf, callback):
|
def get_version(name, conf, callback):
|
||||||
g = globals()
|
g = globals()
|
||||||
for key in handler_precedence:
|
for key in handler_precedence:
|
||||||
@ -34,9 +41,19 @@ def get_version_by_regex(name, conf, callback):
|
|||||||
|
|
||||||
encoding = conf.get('encoding', 'latin1')
|
encoding = conf.get('encoding', 'latin1')
|
||||||
httpclient = AsyncHTTPClient()
|
httpclient = AsyncHTTPClient()
|
||||||
|
|
||||||
|
kwargs = {}
|
||||||
|
if conf.get('proxy'):
|
||||||
|
if pycurl:
|
||||||
|
host, port = urllib.parse.splitport(conf['proxy'])
|
||||||
|
kwargs['proxy_host'] = host
|
||||||
|
kwargs['proxy_port'] = int(port)
|
||||||
|
else:
|
||||||
|
logger.warn('%s: proxy set but not used because pycurl is unavailable.', name)
|
||||||
|
|
||||||
httpclient.fetch(conf['url'], partial(
|
httpclient.fetch(conf['url'], partial(
|
||||||
_get_version_by_regex, name, r, encoding, callback
|
_get_version_by_regex, name, r, encoding, callback
|
||||||
))
|
), **kwargs)
|
||||||
|
|
||||||
def _get_version_by_regex(name, regex, encoding, callback, res):
|
def _get_version_by_regex(name, regex, encoding, callback, res):
|
||||||
body = res.body.decode(encoding)
|
body = res.body.decode(encoding)
|
||||||
|
@ -24,3 +24,8 @@ github = lilydjwg/winterpy
|
|||||||
|
|
||||||
[nvchecker]
|
[nvchecker]
|
||||||
github = lilydjwg/nvchecker
|
github = lilydjwg/nvchecker
|
||||||
|
|
||||||
|
[ssed]
|
||||||
|
url = http://sed.sourceforge.net/grabbag/ssed/
|
||||||
|
regex = The current version is ([\d.]+)\.
|
||||||
|
proxy = localhost:8087
|
||||||
|
Loading…
Reference in New Issue
Block a user