From c15e9b757637f55f922913a65a414d57c958d561 Mon Sep 17 00:00:00 2001 From: Chih-Hsuan Yen Date: Sat, 4 Dec 2021 18:58:34 +0800 Subject: [PATCH] android-sdk improvements * Returns all matched versions to support list options * Don't hard-code the host OS * Document the default of `channel` --- docs/usage.rst | 7 ++++++- nvchecker_source/android_sdk.py | 10 ++++++++-- tests/test_android_sdk.py | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index 79b4c5b..9550aea 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -731,7 +731,12 @@ 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``. + 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``. The default is ``stable``. + +host_os + Choose the target OS for the tracked package from one of ``linux``, ``macosx``, ``windows``. The default is ``linux``. For OS-independent packages (e.g., Java JARs), this field is ignored. + +This source supports :ref:`list options`. Check Sparkle framework ~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/nvchecker_source/android_sdk.py b/nvchecker_source/android_sdk.py index dfb33fd..352cbbc 100644 --- a/nvchecker_source/android_sdk.py +++ b/nvchecker_source/android_sdk.py @@ -38,6 +38,8 @@ async def get_version(name, conf, *, cache, **kwargs): repo_manifest = await cache.get(repo, _get_repo_manifest) + versions = [] + for pkg in repo_manifest.findall('.//remotePackage'): if not pkg.attrib['path'].startswith(pkg_path_prefix): continue @@ -46,7 +48,7 @@ async def get_version(name, conf, *, cache, **kwargs): 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': + if host_os is not None and host_os.text != conf.get('host_os', 'linux'): continue archive_url = archive.find('./complete/url').text # revision @@ -62,4 +64,8 @@ async def get_version(name, conf, *, cache, **kwargs): mobj = re.match(r'r\d+', rel_str) if mobj: rev_strs.append(rel_str) - return '.'.join(rev_strs) + versions.append('.'.join(rev_strs)) + # A package suitable for the target host OS is found - skip remaining + break + + return versions diff --git a/tests/test_android_sdk.py b/tests/test_android_sdk.py index 30d167a..cbc75f4 100644 --- a/tests/test_android_sdk.py +++ b/tests/test_android_sdk.py @@ -27,3 +27,27 @@ async def test_android_package_channel(get_version): "repo": "package", "channel": "beta,dev,canary", }) == "3.22.1" + +async def test_android_list(get_version): + assert await get_version("android-sdk-cmake-older", { + "source": "android_sdk", + "android_sdk": "cmake;", + "repo": "package", + "include_regex": "3\.10.*", + }) == "3.10.2" + +async def test_android_package_os(get_version): + await get_version("android-usb-driver", { + "source": "android_sdk", + "android_sdk": "extras;google;usb_driver", + "repo": "addon", + "host_os": "windows" + }) == "13" + +async def test_android_package_os_missing(get_version): + await get_version("android-usb-driver", { + "source": "android_sdk", + "android_sdk": "extras;google;usb_driver", + "repo": "addon", + "host_os": "linux" + }) == None