2022-03-20 23:57:45 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
import urllib.request
|
|
|
|
from lxml import etree
|
|
|
|
from packaging.version import parse as parse_version
|
|
|
|
|
|
|
|
class BuildVersion(object):
|
2022-04-09 01:18:12 +02:00
|
|
|
DOWNLOADPAGE = "https://www.libreoffice.org/download/download/"
|
2022-03-20 23:57:45 +01:00
|
|
|
ARCHIVE = "https://downloadarchive.documentfoundation.org/libreoffice/old/"
|
|
|
|
RELEASE = "https://download.documentfoundation.org/libreoffice/stable/"
|
2022-03-22 01:24:55 +01:00
|
|
|
DAILY = "https://dev-builds.libreoffice.org/daily/master/Linux-rpm_deb-x86_64@tb87-TDF/"
|
|
|
|
PRERELEASE = "https://dev-builds.libreoffice.org/pre-releases/deb/x86_64/"
|
2022-03-20 23:57:45 +01:00
|
|
|
|
|
|
|
def __init__(self, query):
|
|
|
|
self.query = query
|
|
|
|
self.version = ''
|
|
|
|
self.basedirurl = {}
|
|
|
|
|
|
|
|
# Parsing the query input.
|
|
|
|
if '.' in self.query:
|
|
|
|
# Numbered self.version. Let's check it is a 4 dotted release
|
|
|
|
if len(self.query.split('.')) == 4:
|
|
|
|
self.version = self.query
|
|
|
|
else:
|
|
|
|
# If not 4 dotted, let's search for the 4 dotted version
|
|
|
|
self.version = self.__getlatestrel(self.query)
|
|
|
|
|
|
|
|
self.basedirurl = self.__getbaseurl(self.version)
|
|
|
|
else:
|
|
|
|
# String self.versions.
|
|
|
|
a = self.__getbranchrel(self.query)
|
|
|
|
self.version = a['version']
|
|
|
|
self.basedirurl = a['basedirurl']
|
|
|
|
|
|
|
|
def __getlatestrel(self, basever):
|
|
|
|
"""Search in downloadarchive for the latest version matching baseversion."""
|
|
|
|
versionlist = etree.HTML(urllib.request.urlopen(BuildVersion.ARCHIVE).read()).xpath('//td/a')
|
|
|
|
# Getting a more polished matching list
|
|
|
|
cleanlist = list(dict.fromkeys([x.text.strip('/') for x in versionlist if x.text.startswith(basever)]))
|
|
|
|
|
|
|
|
# Sorting, then returning the last version
|
|
|
|
return sorted(cleanlist)[-1]
|
|
|
|
|
|
|
|
def __getbranchrel(self, branch):
|
|
|
|
"""Based on branch names, get the release number."""
|
|
|
|
basedirurl = {}
|
|
|
|
version = ''
|
|
|
|
if branch == 'daily':
|
2022-03-22 01:24:55 +01:00
|
|
|
# The daily builds can be mostly distinguished by the day of build
|
|
|
|
# (official version is constant.
|
|
|
|
|
|
|
|
# The last built version is the next-to-last version [-2] on the page.
|
|
|
|
fulldailypath = etree.HTML(urllib.request.urlopen(BuildVersion.DAILY).read()).xpath('//td/a')[-2].text
|
|
|
|
dailyversion = fulldailypath.split('_')[0].replace('-', '')
|
|
|
|
version
|
|
|
|
newurl = str.join('/', [ BuildVersion.DAILY, fulldailypath, '' ])
|
|
|
|
|
|
|
|
basedirurl = { u'x86_64': newurl, u'x86': '-' }
|
|
|
|
version = etree.HTML(urllib.request.urlopen(newurl).read()).xpath('//td/a')[1].text.split('_')[1]
|
|
|
|
|
|
|
|
return { 'version': version + '-' + dailyversion, 'basedirurl': basedirurl }
|
|
|
|
|
|
|
|
if branch == 'prerelease':
|
|
|
|
version = etree.HTML(urllib.request.urlopen(BuildVersion.PRERELEASE).read()).xpath('//td/a')[1].text.split('_')[1]
|
|
|
|
basedirurl = { u'x86': '-', u'x86_64': BuildVersion.PRERELEASE }
|
2022-03-20 23:57:45 +01:00
|
|
|
|
|
|
|
return { 'version': version, 'basedirurl': basedirurl }
|
|
|
|
|
2022-03-22 01:24:55 +01:00
|
|
|
# Stable releases.
|
2022-04-09 01:18:12 +02:00
|
|
|
# Old approach - Doesn't really work because RelEng can screw order.
|
|
|
|
#versions = etree.HTML(urllib.request.urlopen(BuildVersion.RELEASE).read()).xpath('//td/a')
|
|
|
|
#index = 1
|
|
|
|
#if branch == 'still':
|
|
|
|
# index = -2
|
|
|
|
#elif branch == 'fresh':
|
|
|
|
# index = -1
|
|
|
|
#version = self.__getlatestrel(versions[index].text.strip('/'))
|
|
|
|
|
|
|
|
# Now I'll rely on DownloadPage
|
|
|
|
versions = etree.HTML(urllib.request.urlopen(BuildVersion.DOWNLOADPAGE).read()).xpath('//span[@class="dl_version_number"]')
|
|
|
|
index = 0
|
2022-03-20 23:57:45 +01:00
|
|
|
if branch == 'still':
|
2022-04-09 01:18:12 +02:00
|
|
|
index = 1
|
2022-03-20 23:57:45 +01:00
|
|
|
elif branch == 'fresh':
|
2022-04-09 01:18:12 +02:00
|
|
|
index = 0
|
|
|
|
version = self.__getlatestrel(versions[index].text)
|
2022-03-20 23:57:45 +01:00
|
|
|
|
|
|
|
return { 'version': version, 'basedirurl': self.__getbaseurl(version) }
|
|
|
|
|
|
|
|
def __getbaseurl(self, version):
|
|
|
|
"""Returns the links based on the numeric version."""
|
|
|
|
basedirurl = {}
|
|
|
|
url = BuildVersion.ARCHIVE + '/' + version + '/deb/'
|
|
|
|
|
|
|
|
# x86 binaries are not anymore offered after 6.3.0.
|
|
|
|
if parse_version(version) < parse_version('6.3.0'):
|
2022-03-22 01:24:55 +01:00
|
|
|
basedirurl[u'x86'] = url + 'x86/'
|
2022-03-20 23:57:45 +01:00
|
|
|
else:
|
2022-03-22 01:24:55 +01:00
|
|
|
basedirurl[u'x86'] = '-'
|
2022-03-20 23:57:45 +01:00
|
|
|
|
2022-03-22 01:24:55 +01:00
|
|
|
basedirurl[u'x86_64'] = url + 'x86_64/'
|
2022-03-20 23:57:45 +01:00
|
|
|
|
|
|
|
return basedirurl
|