Versione funzionante.
This commit is contained in:
parent
1a9887fe27
commit
3ba59005b9
116
getversions.py
116
getversions.py
|
@ -3,60 +3,86 @@
|
||||||
|
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
import re, sys
|
from packaging.version import parse as parse_version
|
||||||
|
import re, sys, json
|
||||||
|
|
||||||
archiveurl = "https://downloadarchive.documentfoundation.org/libreoffice/old/"
|
ARCHIVE = "https://downloadarchive.documentfoundation.org/libreoffice/old/"
|
||||||
baseurl = "https://download.documentfoundation.org/libreoffice/"
|
RELEASE = "https://download.documentfoundation.org/libreoffice/stable/"
|
||||||
|
DAILY = "https://dev-builds.libreoffice.org/daily/master/Linux-rpm_deb-x86_64@tb87-TDF/current/"
|
||||||
|
|
||||||
def getlatestrel(basever):
|
def getlatestrel(basever):
|
||||||
"""Search in downloadarchive the latest version matching the baseversion indicated."""
|
"""Search in downloadarchive for the latest version matching baseversion."""
|
||||||
versionlist = etree.HTML(urllib.request.urlopen(archiveurl).read()).xpath('//td/a')
|
versionlist = etree.HTML(urllib.request.urlopen(ARCHIVE).read()).xpath('//td/a')
|
||||||
# Getting a more polished matching list
|
# Getting a more polished matching list
|
||||||
cleanlist = list(dict.fromkeys([x.strip('/') if x.startswith(basever) else None for x in versionlist]))
|
cleanlist = list(dict.fromkeys([x.text.strip('/') for x in versionlist if x.text.startswith(basever)]))
|
||||||
# Removing None entries
|
|
||||||
cleanlist.remove(None)
|
|
||||||
# Sorting, then returning the last version
|
# Sorting, then returning the last version
|
||||||
return sorted(cleanlist)[-1]
|
return sorted(cleanlist)[-1]
|
||||||
|
|
||||||
|
def getbranchrel(branch):
|
||||||
|
"""Based on branch names, get the release number."""
|
||||||
|
basedirurl = {}
|
||||||
|
version = ''
|
||||||
|
if branch == 'daily':
|
||||||
|
basedirurl = { 'x86_64': DAILY, 'x86': '-' }
|
||||||
|
version = etree.HTML(urllib.request.urlopen(DAILY).read()).xpath('//td/a')[1].text.split('_')[1]
|
||||||
|
|
||||||
|
return { 'version': version, 'basedirurl': basedirurl }
|
||||||
|
|
||||||
|
versions = etree.HTML(urllib.request.urlopen(RELEASE).read()).xpath('//td/a')
|
||||||
|
index = 1
|
||||||
|
if branch == 'still':
|
||||||
|
index = 2
|
||||||
|
elif branch == 'fresh':
|
||||||
|
index = 3
|
||||||
|
version = getlatestrel(versions[index].text.strip('/'))
|
||||||
|
|
||||||
|
return { 'version': version, 'basedirurl': getbaseurl(version) }
|
||||||
|
|
||||||
|
def getbaseurl(version):
|
||||||
|
"""Returns the links based on the numeric version."""
|
||||||
|
basediriurl = {}
|
||||||
|
url = ARCHIVE + '/' + version + '/deb/'
|
||||||
|
# x86 binaries are not anymore offered after 6.3.0.
|
||||||
|
if parse_version(version) < parse_version('6.3.0'):
|
||||||
|
basedirurl['x86'] = url + 'x86/'
|
||||||
|
else:
|
||||||
|
basedirurl['x86'] = '-'
|
||||||
|
|
||||||
|
basedirurl['x86_64'] = url + 'x86_64/'
|
||||||
|
|
||||||
|
return basedirurl
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# Preparing variables for outputting
|
||||||
|
version = ''
|
||||||
|
basedirurl = {}
|
||||||
|
basever = 'fresh'
|
||||||
|
|
||||||
|
# At the end of the checks, we need a version string and a basedirurl, which
|
||||||
|
# should be a dictionaly for x86, x86_64 with the base of the directory where
|
||||||
|
# to download the files.
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
# A version has been specified.
|
# A version has been specified.
|
||||||
version = sys.argv[1]
|
basever = sys.argv[1]
|
||||||
if '.' in version:
|
|
||||||
# Numbered version.
|
# Once overridden with Argv, parse the inputs
|
||||||
# Let's check it is a 4 dotted release
|
if '.' in basever:
|
||||||
if not len(version.split('.')) == 4:
|
# Numbered version. Let's check it is a 4 dotted release
|
||||||
version = getlatestrel(version)
|
if len(basever.split('.')) == 4:
|
||||||
|
version = basever
|
||||||
else:
|
else:
|
||||||
# string version
|
version = getlatestrel(basever)
|
||||||
if version == 'still':
|
|
||||||
elif version == 'fresh':
|
|
||||||
elif version == 'daily':
|
|
||||||
|
|
||||||
|
basedirurl = getbaseurl(version)
|
||||||
|
else:
|
||||||
|
# String versions.
|
||||||
|
a = getbranchrel(basever)
|
||||||
|
version = a['version']
|
||||||
|
basedirurl = a['basedirurl']
|
||||||
|
|
||||||
# Running for stable channel
|
output = """query: %s
|
||||||
html_stable = urllib.request.urlopen(baseurl + 'stable/').read()
|
version: %s
|
||||||
|
x86: %s
|
||||||
# Processing page content
|
x86_64: %s""" % (basever, version, basedirurl['x86'] or '-', basedirurl['x86_64'])
|
||||||
stable_contents = etree.HTML(html_stable)
|
print(output)
|
||||||
|
|
||||||
# Processing first page links
|
|
||||||
stable_versions = []
|
|
||||||
for link in stable_contents.xpath('//td/a'):
|
|
||||||
next if link.text == "Parent Directory"
|
|
||||||
|
|
||||||
stable_versions.append(link.get('href').replace('/', '')
|
|
||||||
|
|
||||||
# getting URL for specific versions
|
|
||||||
for arch in [ 'x86', 'x86_64' ]:
|
|
||||||
newurl = baseurl + 'stable/' + link.get('href') + 'deb/' + arch + '/'
|
|
||||||
res = etree.HTML(urllib.request.urlopen(newurl).read()).xpath("//td/a")
|
|
||||||
if len(res) == 1:
|
|
||||||
# No packages provided
|
|
||||||
next
|
|
||||||
|
|
||||||
for link in res:
|
|
||||||
next if res.text == 'Parent Directory'
|
|
||||||
next if re.search(r'deb.tar.gz$', res.text):
|
|
||||||
# Matches a package - good.
|
|
||||||
# Checking for language packs and offline help
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue