From 02601c0b58f0aaf3ea011c59bd5befd87e598d16 Mon Sep 17 00:00:00 2001 From: Yen Chi Hsuan Date: Wed, 11 Oct 2017 02:58:47 +0800 Subject: [PATCH] Support checking versoins from Android SDK --- nvchecker/get_version.py | 2 +- nvchecker/source/android_sdk.py | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 nvchecker/source/android_sdk.py diff --git a/nvchecker/get_version.py b/nvchecker/get_version.py index 1c8e6eb..b2a8311 100644 --- a/nvchecker/get_version.py +++ b/nvchecker/get_version.py @@ -11,7 +11,7 @@ handler_precedence = ( 'gems', 'pacman', 'cmd', 'bitbucket', 'regex', 'manual', 'vcs', 'cratesio', 'npm', 'hackage', 'cpan', 'gitlab', 'packagist', - 'anitya', + 'anitya', 'android_sdk', ) def substitute_version(version, name, conf): diff --git a/nvchecker/source/android_sdk.py b/nvchecker/source/android_sdk.py new file mode 100644 index 0000000..d90e754 --- /dev/null +++ b/nvchecker/source/android_sdk.py @@ -0,0 +1,44 @@ +# MIT licensed +# Copyright (c) 2013-2017 lilydjwg , et al. + +import os +import re +from xml.etree import ElementTree + +from . import session + +ANDROID_REPO_MANIFESTS = { + 'addon': 'https://dl.google.com/android/repository/addon2-1.xml', + 'package': 'https://dl.google.com/android/repository/repository2-1.xml', +} + +async def get_version(name, conf): + repo_xml_url = ANDROID_REPO_MANIFESTS[conf['repo']] + pkg_path_prefix = conf['android_sdk'] + + async with session.get(repo_xml_url) as res: + data = (await res.read()).decode('utf-8') + + repo_manifest = ElementTree.fromstring(data) + for pkg in repo_manifest.findall('.//remotePackage'): + if not pkg.attrib['path'].startswith(pkg_path_prefix): + continue + for archive in pkg.findall('./archives/archive'): + host_os = archive.find('./host-os') + if host_os and host_os.text != 'linux': + continue + archive_url = archive.find('./complete/url').text + # revision + rev = pkg.find('./revision') + rev_strs = [] + for part in ('major', 'minor', 'micro'): + part_node = rev.find('./' + part) + if part_node is not None: + rev_strs.append(part_node.text) + # release number + filename, ext = os.path.splitext(archive_url) + rel_str = filename.rsplit('-')[-1] + mobj = re.match(r'r\d+', rel_str) + if mobj: + rev_strs.append(rel_str) + return '.'.join(rev_strs)