mirror of
https://github.com/lilydjwg/nvchecker
synced 2025-04-17 04:26:25 +00:00
Fix archpkg and add tests
This commit is contained in:
parent
4be2d6c09d
commit
2c17c40206
@ -1,12 +1,15 @@
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
import logging
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from tornado.httpclient import AsyncHTTPClient
|
from tornado.httpclient import AsyncHTTPClient
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
URL = 'https://www.archlinux.org/packages/search/json/?name='
|
URL = 'https://www.archlinux.org/packages/search/json/?name='
|
||||||
|
|
||||||
def get_version(name, conf, callback):
|
def get_version(name, conf, callback):
|
||||||
pkg = conf['archpkg']
|
pkg = conf.get('archpkg') or name
|
||||||
strip_release = conf.getboolean('strip-release', False)
|
strip_release = conf.getboolean('strip-release', False)
|
||||||
url = URL + pkg
|
url = URL + pkg
|
||||||
AsyncHTTPClient().fetch(
|
AsyncHTTPClient().fetch(
|
||||||
@ -23,7 +26,7 @@ def _pkg_done(name, strip_release, callback, res):
|
|||||||
callback(name, None)
|
callback(name, None)
|
||||||
return
|
return
|
||||||
|
|
||||||
version = [r['pkgver'] for r in data['results'] if r['repo'] != 'testing'][0]
|
version = [r['pkgver'] + "-" + r['pkgrel'] for r in data['results'] if r['repo'] != 'testing'][0]
|
||||||
if strip_release and '-' in version:
|
if strip_release and '-' in version:
|
||||||
version = version.rsplit('-', 1)[0]
|
version = version.rsplit('-', 1)[0]
|
||||||
callback(name, version)
|
callback(name, version)
|
||||||
|
9
tests/test_archpkg.py
Normal file
9
tests/test_archpkg.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from tests.helper import ExternalVersionTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class ArchPKGTest(ExternalVersionTestCase):
|
||||||
|
def test_archpkg(self):
|
||||||
|
self.assertEqual(self.sync_get_version("ipw2100-fw", {"archpkg": None}), "1.3-7")
|
||||||
|
|
||||||
|
def test_archpkg_strip_release(self):
|
||||||
|
self.assertEqual(self.sync_get_version("ipw2100-fw", {"archpkg": None, "strip-release": 1}), "1.3")
|
Loading…
Reference in New Issue
Block a user