Prima versione riscritta.
This commit is contained in:
parent
c79cc2abcf
commit
6aa0b34216
7 changed files with 390 additions and 353 deletions
|
@ -1,88 +1,34 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
import urllib.request
|
||||
from lxml import etree
|
||||
from packaging.version import parse as parse_version
|
||||
import click
|
||||
from loaih.versions import BuildVersion
|
||||
import re, sys, json
|
||||
|
||||
ARCHIVE = "https://downloadarchive.documentfoundation.org/libreoffice/old/"
|
||||
RELEASE = "https://download.documentfoundation.org/libreoffice/stable/"
|
||||
DAILY = "https://dev-builds.libreoffice.org/daily/master/Linux-rpm_deb-x86_64@tb87-TDF/current/"
|
||||
@click.command()
|
||||
@click.option('-o', '--output', default = 'rundeck', type=click.Choice(['rundeck', 'json', 'text' ], case_sensitive=False), help="Output format, defaulting to Rundeck Key/Value data format. Options: rundeck,json,text")
|
||||
@click.argument('query')
|
||||
def getversion(query, output):
|
||||
b = BuildVersion(query)
|
||||
|
||||
def getlatestrel(basever):
|
||||
"""Search in downloadarchive for the latest version matching baseversion."""
|
||||
versionlist = etree.HTML(urllib.request.urlopen(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(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/'
|
||||
if output.lower() == 'rundeck':
|
||||
print("""RUNDECK:DATA: query = {query}
|
||||
RUNDECK:DATA: version = {version}
|
||||
RUNDECK:DATA: x86 = {x86_url}
|
||||
RUNDECK:DATA: x86_64 = {x86_64_url}""".format(query = query, version = b.version, x86_url = b.basedirurl['x86'], x86_64_url = b.basedirurl['x86_64']))
|
||||
elif output.lower() == 'json':
|
||||
output = {
|
||||
'query': query,
|
||||
'version': b.version,
|
||||
'basedirurl': b.basedirurl
|
||||
}
|
||||
print(json.dumps(output))
|
||||
else:
|
||||
basedirurl['x86'] = '-'
|
||||
|
||||
basedirurl['x86_64'] = url + 'x86_64/'
|
||||
print("""query: {query}
|
||||
version: {version}
|
||||
x86: {x86_url}
|
||||
x86_64: {x86_64_url}""".format(query = query, version = b.version, x86_url = b.basedirurl['x86'], x86_64_url = b.basedirurl['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:
|
||||
# A version has been specified.
|
||||
basever = sys.argv[1]
|
||||
|
||||
# Once overridden with Argv, parse the inputs
|
||||
if '.' in basever:
|
||||
# Numbered version. Let's check it is a 4 dotted release
|
||||
if len(basever.split('.')) == 4:
|
||||
version = basever
|
||||
else:
|
||||
version = getlatestrel(basever)
|
||||
|
||||
basedirurl = getbaseurl(version)
|
||||
else:
|
||||
# String versions.
|
||||
a = getbranchrel(basever)
|
||||
version = a['version']
|
||||
basedirurl = a['basedirurl']
|
||||
|
||||
output = """RUNDECK:DATA: query = %s
|
||||
RUNDECK:DATA: version = %s
|
||||
RUNDECK:DATA: x86 = %s
|
||||
RUNDECK:DATA: x86_64 = %s""" % (basever, version, basedirurl['x86'] or '-', basedirurl['x86_64'])
|
||||
print(output)
|
||||
getversion()
|
||||
|
|
Reference in a new issue