fix: source sparkle (#210)

fix: source sparkle
This commit is contained in:
Guizai 2022-02-22 20:13:18 +08:00 committed by GitHub
parent 3dff0466d1
commit 7739f5c8c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 6 deletions

View File

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

View File

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