80 lines
2.4 KiB
Python
80 lines
2.4 KiB
Python
import os
|
|
import re
|
|
import requests
|
|
from html.parser import HTMLParser
|
|
|
|
BUILDBOT_URL = "https://builder.blender.org/"
|
|
BUILDBOT_DOWNLOAD_URL = BUILDBOT_URL + "download/"
|
|
|
|
|
|
class BuildbotHTMLParser(HTMLParser):
|
|
def __init__(self):
|
|
HTMLParser.__init__(self)
|
|
self._is_inside_official_table = False
|
|
self._is_official_table_finished = False
|
|
self.official_builds = []
|
|
|
|
def handle_starttag(self, tag, attrs):
|
|
tag_lower = tag.lower()
|
|
if tag_lower == 'a':
|
|
if self._is_inside_official_table:
|
|
for attr in attrs:
|
|
if attr[0].lower() == 'href':
|
|
href = attr[1]
|
|
self.official_builds.append(href)
|
|
elif tag_lower == 'table':
|
|
classes = ()
|
|
for attr in attrs:
|
|
if attr[0].lower() == 'class':
|
|
classes = attr[1].lower().split()
|
|
if 'table-striped' in classes:
|
|
if self._is_inside_official_table:
|
|
self._is_inside_official_table = False
|
|
self._is_official_table_finished = True
|
|
else:
|
|
if not self._is_official_table_finished:
|
|
self._is_inside_official_table = True
|
|
|
|
def handle_endtag(self, tag):
|
|
pass
|
|
|
|
def handle_data(self, data):
|
|
pass
|
|
|
|
|
|
def _getBuildbotPlatformRegex(platform, bitness):
|
|
platform_lower = platform.lower()
|
|
if platform_lower in ("linux", "lin"):
|
|
if bitness.startswith("64"):
|
|
return re.compile(".*linux-glibc[0-9]+-x86_64.*")
|
|
elif bitness.startswith("32"):
|
|
return re.compile(".*linux-glibc[0-9]+-i686.*")
|
|
else:
|
|
# TOGO(sergey): Needs implementation
|
|
pass
|
|
return None
|
|
|
|
|
|
def buildbotGetLatetsVersion(platform, bitness):
|
|
"""
|
|
Get latest Blender version URL from buildbot website.
|
|
|
|
Returns None if something is wrong.
|
|
"""
|
|
# Get content of the page.
|
|
r = requests.get(BUILDBOT_DOWNLOAD_URL)
|
|
if r.status_code != requests.codes.ok:
|
|
return None
|
|
# Parse the page.
|
|
parser = BuildbotHTMLParser()
|
|
parser.feed(r.text)
|
|
official_builds = parser.official_builds
|
|
# Get build which corresponds to requested platform.
|
|
regex = _getBuildbotPlatformRegex(platform, bitness)
|
|
if not regex:
|
|
return None
|
|
for build in official_builds:
|
|
if regex.match(build):
|
|
return BUILDBOT_DOWNLOAD_URL + build
|
|
return None
|