2017-10-10 18:58:47 +00:00
|
|
|
# MIT licensed
|
2020-08-14 10:25:48 +00:00
|
|
|
# Copyright (c) 2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
2019-12-17 07:29:27 +00:00
|
|
|
# Copyright (c) 2017,2020 Chih-Hsuan Yen <yan12125 at gmail dot com>
|
2017-10-10 18:58:47 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
from xml.etree import ElementTree
|
|
|
|
|
2020-08-14 12:04:05 +00:00
|
|
|
from nvchecker.api import session
|
2017-10-10 18:58:47 +00:00
|
|
|
|
2017-11-04 17:29:12 +00:00
|
|
|
_ANDROID_REPO_MANIFESTS = {
|
2017-10-10 18:58:47 +00:00
|
|
|
'addon': 'https://dl.google.com/android/repository/addon2-1.xml',
|
|
|
|
'package': 'https://dl.google.com/android/repository/repository2-1.xml',
|
|
|
|
}
|
|
|
|
|
2019-12-17 07:29:27 +00:00
|
|
|
# See <channel> tags in Android SDK XML manifests
|
|
|
|
_CHANNEL_MAP = {
|
|
|
|
'stable': 'channel-0',
|
|
|
|
'beta': 'channel-1',
|
|
|
|
'dev': 'channel-2',
|
|
|
|
'canary': 'channel-3',
|
|
|
|
}
|
|
|
|
|
2017-11-04 17:29:12 +00:00
|
|
|
async def _get_repo_manifest(repo):
|
2020-08-14 10:25:48 +00:00
|
|
|
repo_xml_url = _ANDROID_REPO_MANIFESTS[repo]
|
2017-10-10 18:58:47 +00:00
|
|
|
|
2020-08-17 08:21:02 +00:00
|
|
|
res = await session.get(repo_xml_url)
|
|
|
|
data = res.body.decode('utf-8')
|
2017-11-04 17:29:12 +00:00
|
|
|
|
2020-08-14 10:25:48 +00:00
|
|
|
repo_manifest = ElementTree.fromstring(data)
|
|
|
|
return repo_manifest
|
2017-11-04 17:29:12 +00:00
|
|
|
|
2020-08-14 10:25:48 +00:00
|
|
|
async def get_version(name, conf, *, cache, **kwargs):
|
2017-11-04 17:29:12 +00:00
|
|
|
repo = conf['repo']
|
|
|
|
pkg_path_prefix = conf['android_sdk']
|
2019-12-17 07:29:27 +00:00
|
|
|
channels = [_CHANNEL_MAP[channel]
|
|
|
|
for channel in conf.get('channel', 'stable').split(',')]
|
2017-11-04 17:29:12 +00:00
|
|
|
|
2020-08-14 10:25:48 +00:00
|
|
|
repo_manifest = await cache.get(repo, _get_repo_manifest)
|
2017-11-04 17:29:12 +00:00
|
|
|
|
2017-10-10 18:58:47 +00:00
|
|
|
for pkg in repo_manifest.findall('.//remotePackage'):
|
|
|
|
if not pkg.attrib['path'].startswith(pkg_path_prefix):
|
|
|
|
continue
|
2019-12-17 07:29:27 +00:00
|
|
|
channelRef = pkg.find('./channelRef')
|
|
|
|
if channelRef.attrib['ref'] not in channels:
|
|
|
|
continue
|
2017-10-10 18:58:47 +00:00
|
|
|
for archive in pkg.findall('./archives/archive'):
|
|
|
|
host_os = archive.find('./host-os')
|
2019-03-07 09:22:58 +00:00
|
|
|
if host_os is not None and host_os.text != 'linux':
|
2017-10-10 18:58:47 +00:00
|
|
|
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)
|