loaih/scripts/loaih-getversion

35 lines
1.2 KiB
Python

#!/usr/bin/env python
# encoding: utf-8
import click
from loaih.versions import BuildVersion
import re, sys, json
@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)
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:
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']))
if __name__ == '__main__':
getversion()