Improve android_sdk version extractor

* Add README
* Update author info
* Cache repo manifests
This commit is contained in:
Yen Chi Hsuan 2017-11-05 01:29:12 +08:00
parent bb3fa58481
commit 5df11f7b1a
3 changed files with 31 additions and 6 deletions

View file

@ -37,6 +37,7 @@ Contents
* `Check Debian Linux official packages <#check-debian-linux-official-packages>`_ * `Check Debian Linux official packages <#check-debian-linux-official-packages>`_
* `Check Ubuntu Linux official packages <#check-ubuntu-linux-official-packages>`_ * `Check Ubuntu Linux official packages <#check-ubuntu-linux-official-packages>`_
* `Check Anitya (release-monitoring.org) <#check-anitya>`_ * `Check Anitya (release-monitoring.org) <#check-anitya>`_
* `Check Android SDK <#check-android-sdk>`_
* `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>`_
@ -380,6 +381,16 @@ This enables you to track updates from `Anitya <https://release-monitoring.org/>
anitya anitya
``distro/package``, where ``distro`` can be a lot of things like "fedora", "arch linux", "gentoo", etc. ``package`` is the package name of the chosen distribution. ``distro/package``, where ``distro`` can be a lot of things like "fedora", "arch linux", "gentoo", etc. ``package`` is the package name of the chosen distribution.
Check Android SDK
-----------------
This enables you to track updates of Android SDK packages listed in ``sdkmanager --list``.
android_sdk
The package path prefix. This value is matched against the ``path`` attribute in all <remotePackage> nodes in an SDK manifest XML. The first match is used for version comparisions.
repo
Should be one of ``addon`` or ``package``. Packages in ``addon2-1.xml`` use ``addon`` and packages in ``repository2-1.xml`` use ``package``.
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

@ -1,5 +1,5 @@
# MIT licensed # MIT licensed
# Copyright (c) 2013-2017 lilydjwg <lilydjwg@gmail.com>, et al. # Copyright (c) 2017 Yen Chi Hsuan <yan12125 at gmail dot com>
import os import os
import re import re
@ -7,19 +7,33 @@ from xml.etree import ElementTree
from . import session from . import session
ANDROID_REPO_MANIFESTS = { _ANDROID_REPO_MANIFESTS = {
'addon': 'https://dl.google.com/android/repository/addon2-1.xml', 'addon': 'https://dl.google.com/android/repository/addon2-1.xml',
'package': 'https://dl.google.com/android/repository/repository2-1.xml', 'package': 'https://dl.google.com/android/repository/repository2-1.xml',
} }
async def get_version(name, conf): _repo_manifests_cache = {}
repo_xml_url = ANDROID_REPO_MANIFESTS[conf['repo']]
pkg_path_prefix = conf['android_sdk'] async def _get_repo_manifest(repo):
if repo in _repo_manifests_cache:
return _repo_manifests_cache[repo]
repo_xml_url = _ANDROID_REPO_MANIFESTS[repo]
async with session.get(repo_xml_url) as res: async with session.get(repo_xml_url) as res:
data = (await res.read()).decode('utf-8') data = (await res.read()).decode('utf-8')
repo_manifest = ElementTree.fromstring(data) repo_manifest = ElementTree.fromstring(data)
_repo_manifests_cache[repo] = repo_manifest
return repo_manifest
async def get_version(name, conf):
repo = conf['repo']
pkg_path_prefix = conf['android_sdk']
repo_manifest = await _get_repo_manifest(repo)
for pkg in repo_manifest.findall('.//remotePackage'): for pkg in repo_manifest.findall('.//remotePackage'):
if not pkg.attrib['path'].startswith(pkg_path_prefix): if not pkg.attrib['path'].startswith(pkg_path_prefix):
continue continue

View file

@ -1,5 +1,5 @@
# MIT licensed # MIT licensed
# Copyright (c) 2013-2017 lilydjwg <lilydjwg@gmail.com>, et al. # Copyright (c) 2017 Yen Chi Hsuan <yan12125 at gmail dot com>
import pytest import pytest
pytestmark = pytest.mark.asyncio pytestmark = pytest.mark.asyncio