diff --git a/docs/usage.rst b/docs/usage.rst index 4cb94ee..7259864 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -591,6 +591,9 @@ android_sdk repo Should be one of ``addon`` or ``package``. Packages in ``addon2-1.xml`` use ``addon`` and packages in ``repository2-1.xml`` use ``package``. +channel + Choose the target channel from one of ``stable``, ``beta``, ``dev`` or ``canary``. This option also accepts a comma-seperated list to pick from multiple channels. For example, the latest unstable version is picked with ``beta,dev,canary``. + Check Sparkle framework ~~~~~~~~~~~~~~~~~~~~~~~ :: diff --git a/nvchecker_source/android_sdk.py b/nvchecker_source/android_sdk.py index b101caa..dfb33fd 100644 --- a/nvchecker_source/android_sdk.py +++ b/nvchecker_source/android_sdk.py @@ -1,6 +1,6 @@ # MIT licensed # Copyright (c) 2020 lilydjwg , et al. -# Copyright (c) 2017 Chih-Hsuan Yen +# Copyright (c) 2017,2020 Chih-Hsuan Yen import os import re @@ -13,6 +13,14 @@ _ANDROID_REPO_MANIFESTS = { 'package': 'https://dl.google.com/android/repository/repository2-1.xml', } +# See tags in Android SDK XML manifests +_CHANNEL_MAP = { + 'stable': 'channel-0', + 'beta': 'channel-1', + 'dev': 'channel-2', + 'canary': 'channel-3', +} + async def _get_repo_manifest(repo): repo_xml_url = _ANDROID_REPO_MANIFESTS[repo] @@ -25,12 +33,17 @@ async def _get_repo_manifest(repo): async def get_version(name, conf, *, cache, **kwargs): repo = conf['repo'] pkg_path_prefix = conf['android_sdk'] + channels = [_CHANNEL_MAP[channel] + for channel in conf.get('channel', 'stable').split(',')] repo_manifest = await cache.get(repo, _get_repo_manifest) for pkg in repo_manifest.findall('.//remotePackage'): if not pkg.attrib['path'].startswith(pkg_path_prefix): continue + channelRef = pkg.find('./channelRef') + if channelRef.attrib['ref'] not in channels: + continue for archive in pkg.findall('./archives/archive'): host_os = archive.find('./host-os') if host_os is not None and host_os.text != 'linux': diff --git a/tests/test_android_sdk.py b/tests/test_android_sdk.py index ffcb953..55413a1 100644 --- a/tests/test_android_sdk.py +++ b/tests/test_android_sdk.py @@ -17,4 +17,13 @@ async def test_android_package(get_version): "source": "android_sdk", "android_sdk": "cmake;", "repo": "package", + }) == "3.6.4111459" + + +async def test_android_package_channel(get_version): + assert await get_version("android-sdk-cmake", { + "source": "android_sdk", + "android_sdk": "cmake;", + "repo": "package", + "channel": "beta,dev,canary", }) == "3.18.1"