feat: Add sparkle source

This commit is contained in:
Guizai 2020-05-05 12:20:36 +08:00
parent bc2fcd148d
commit dd15f68033
4 changed files with 48 additions and 1 deletions

View file

@ -49,6 +49,7 @@ Contents
* `Check Repology (repology.org) <#check-repology>`_ * `Check Repology (repology.org) <#check-repology>`_
* `Check Anitya (release-monitoring.org) <#check-anitya>`_ * `Check Anitya (release-monitoring.org) <#check-anitya>`_
* `Check Android SDK <#check-android-sdk>`_ * `Check Android SDK <#check-android-sdk>`_
* `Check Sparkle framework <#check-sparkle-framework>`_
* `Manually updating <#manually-updating>`_ * `Manually updating <#manually-updating>`_
* `Version Control System (VCS) (git, hg, svn, bzr) <#version-control-system-vcs-git-hg-svn-bzr>`_ * `Version Control System (VCS) (git, hg, svn, bzr) <#version-control-system-vcs-git-hg-svn-bzr>`_
* `Other <#other>`_ * `Other <#other>`_
@ -506,6 +507,13 @@ android_sdk
repo repo
Should be one of ``addon`` or ``package``. Packages in ``addon2-1.xml`` use ``addon`` and packages in ``repository2-1.xml`` use ``package``. Should be one of ``addon`` or ``package``. Packages in ``addon2-1.xml`` use ``addon`` and packages in ``repository2-1.xml`` use ``package``.
Check Sparkle framework
-----------------------
This enables you to track updates of macOS applications which using `Sparkle framework <https://sparkle-project.org/>`_.
sparkle
The url of the sparkle appcast.
Manually updating Manually updating
----------------- -----------------
This enables you to manually specify the version (maybe because you want to approve each release before it gets to the script). This enables you to manually specify the version (maybe because you want to approve each release before it gets to the script).

View file

@ -15,7 +15,7 @@ handler_precedence = (
'gems', 'pacman', 'gems', 'pacman',
'cmd', 'bitbucket', 'regex', 'manual', 'vcs', 'cmd', 'bitbucket', 'regex', 'manual', 'vcs',
'cratesio', 'npm', 'hackage', 'cpan', 'gitlab', 'packagist', 'cratesio', 'npm', 'hackage', 'cpan', 'gitlab', 'packagist',
'repology', 'anitya', 'android_sdk', 'repology', 'anitya', 'android_sdk', 'sparkle',
) )
def substitute_version(version, name, conf): def substitute_version(version, name, conf):

View file

@ -0,0 +1,31 @@
# MIT licensed
# Copyright (c) 2020 Sunlei <guizaicn@gmail.com>
from xml.etree import ElementTree
from . import session
async def get_version(name, conf, **kwargs):
sparkle = conf['sparkle']
async with session.get(sparkle) as res:
resp = await res.read()
root = ElementTree.fromstring(resp)
item = root.find('./channel/item[1]/enclosure')
version_string = item.get('{http://www.andymatuschak.org/xml-namespaces/sparkle}shortVersionString')
build_number = item.get('{http://www.andymatuschak.org/xml-namespaces/sparkle}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:
version.append(build_number)
return '-'.join(version) if version else None

8
tests/test_sparkle.py Normal file
View file

@ -0,0 +1,8 @@
# MIT licensed
# Copyright (c) 2020 Sunlei <guizaicn@gmail.com>
import pytest
pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net]
async def test_sparkle(get_version):
assert await get_version("example", {"sparkle": "https://sparkle-project.org/files/sparkletestcast.xml"}) == "2.0"