parent
3dff0466d1
commit
7739f5c8c0
|
@ -6,13 +6,32 @@ from xml.etree import ElementTree
|
|||
|
||||
from nvchecker.api import session
|
||||
|
||||
NAMESPACE = 'http://www.andymatuschak.org/xml-namespaces/sparkle'
|
||||
|
||||
|
||||
async def get_version(name, conf, *, cache, **kwargs):
|
||||
sparkle = conf['sparkle']
|
||||
return await cache.get(sparkle, get_version_impl)
|
||||
|
||||
|
||||
async def get_version_impl(sparkle):
|
||||
res = await session.get(sparkle)
|
||||
root = ElementTree.fromstring(res.body)
|
||||
version = root.find('./channel/item[1]/{http://www.andymatuschak.org/xml-namespaces/sparkle}version')
|
||||
item = root.find('./channel/item[1]/enclosure')
|
||||
|
||||
return version.text
|
||||
version_string = item.get(f'{{{NAMESPACE}}}shortVersionString')
|
||||
build_number = item.get(f'{{{NAMESPACE}}}version')
|
||||
|
||||
if (version_string and version_string.isdigit()) and (
|
||||
build_number and not build_number.isdigit()
|
||||
):
|
||||
version_string, build_number = build_number, version_string
|
||||
|
||||
version = []
|
||||
|
||||
if version_string:
|
||||
version.append(version_string)
|
||||
if build_number and (build_number not in version):
|
||||
version.append(build_number)
|
||||
|
||||
return '-'.join(version) if version else None
|
||||
|
|
|
@ -6,7 +6,11 @@ import pytest
|
|||
pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net]
|
||||
|
||||
async def test_sparkle(get_version):
|
||||
assert await get_version("example", {
|
||||
"source": "sparkle",
|
||||
"sparkle": "https://sparkle-project.org/files/sparkletestcast.xml",
|
||||
}) == "2.0"
|
||||
assert await get_version('example', {
|
||||
'source': 'sparkle',
|
||||
'sparkle': (
|
||||
'https://raw.githubusercontent.com/sparkle-project/Sparkle/'
|
||||
'f453625573fc9a251760b65c74df59023b1471c1/Tests/Resources/'
|
||||
'testlocalizedreleasenotesappcast.xml'
|
||||
),
|
||||
}) == '6.0'
|
||||
|
|
Loading…
Reference in New Issue