Skip to content
Snippets Groups Projects
Commit 9faa8e0b authored by Rolf Niepraschk's avatar Rolf Niepraschk
Browse files

read json structure from "releases.json"

parent 10c99ec6
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,8 @@
},
"xsd":{
"filename":"dcc.xsd",
"externalBaseURL":"https://ptb.de/dcc/"
"externalBaseURL":"https://ptb.de/dcc/",
"localPath":"./xsd-local/",
"releases":"https://www.ptb.de/dcc/releases.json"
}
}
......@@ -3,11 +3,13 @@ from flask_cors import CORS
import utils as utils
from trans import Trans
from datetime import datetime
import subprocess
import subprocess, json
from pprint import pprint
config = utils.get_config_dict()
releases_dict = utils.get_releases_dict(config['xsd']['releases'])
versions = utils.get_versions(releases_dict)
app = Flask(__name__)
CORS(app)
trans = Trans()
......@@ -65,11 +67,11 @@ def validate():
@app.route('/validation.html', methods=['GET'])
def validation():
app.logger.debug('hit validation.html')
# pprint(vars(request))
l = str(request.accept_languages).split(',')[0][0:2]
if l != 'de':
l = 'en'
x = "['2.4.0','2.3.0','2.2.0','2.1.1','2.1.0']"
# x = '["2.4.0","2.3.0","2.2.0","2.1.1","2.1.0"]'
x = '[' + ','.join(versions) + ']'# javascript array definition as string
return trans.show_html(version=utils.get_version(), language=l,
xsd_versions=x)
......@@ -90,3 +92,5 @@ def logo_folder(fn):
if __name__ == '__main__':
app.run(host=config['server']['host'], port=config['server']['port'])
......@@ -21,6 +21,29 @@ def get_config_dict():
return config
# get content of 'releases.json' via http request
def get_releases_dict(url):
try:
filename = urlparse(url).path.split('/')[-1]
r = requests.get(url, allow_redirects=True)
if r.url.endswith(filename): # no bad redirection
try:
return json.loads(r.text)
except:
return False
else:
return False
except:
return False
# a reverse list of version strings
def get_versions(d):
v = []
for i in d['releases']:
v.append('"' + i['version'] + '"')
v = list(reversed(v))
return v
def get_version():
try:
with open('./VERSION', 'r') as f:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment