From 30478e002454b29cbe0f0c5d5c0c296bb210189e Mon Sep 17 00:00:00 2001 From: Robert Goldmann <deadlocker@gmx.de> Date: Tue, 30 Jul 2019 19:40:14 +0200 Subject: [PATCH] client: debug prints ans version.json (v1.0.0) --- client/RoadmapClient.py | 46 +++++++++++++++++++++++++---------------- client/version.json | 7 +++++++ 2 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 client/version.json diff --git a/client/RoadmapClient.py b/client/RoadmapClient.py index 7f10da4..04dd745 100644 --- a/client/RoadmapClient.py +++ b/client/RoadmapClient.py @@ -2,13 +2,17 @@ import json from datetime import datetime import requests -from flask import Flask, render_template, redirect +from flask import Flask, render_template, redirect, jsonify from gevent.pywsgi import WSGIServer from Localization import LOCALIZATION from UrlBuilder import UrlBuilder from blueprints import Roadmaps, Authentication, Milestones, Tasks, SubTasks +with open('version.json', 'r') as f: + VERSION = json.load(f) +VERSION = VERSION['version'] + with open('settings.json', 'r') as f: SETTINGS = json.load(f) @@ -26,6 +30,11 @@ app.register_blueprint(Tasks.construct_blueprint(URL_BUILDER)) app.register_blueprint(SubTasks.construct_blueprint(URL_BUILDER)) +@app.route('/version', methods=['GET']) +def version(): + return jsonify(VERSION) + + @app.route('/') def overview(): roadmaps = requests.get(URL_BUILDER.build_url('roadmaps')).json() @@ -39,36 +48,36 @@ def roadmap(): @app.route('/roadmap/<roadmapID>') def roadmap_by_id(roadmapID): - try: - roadmapID = int(roadmapID) - except ValueError: - return render_template('error.html', message=LOCALIZATION['error_param_invalid']) - - if roadmapID < 1: - return render_template('error.html', message=LOCALIZATION['error_param_invalid']) - - roadmap = requests.get(URL_BUILDER.build_url('roadmap', roadmapID, 'full')).json() - if roadmap is None: - return render_template('error.html', message=LOCALIZATION['error_roadmap_not_existing']) + success, response = __check_roadmap(roadmapID) + if success: + return render_template('index.html', roadmap=response, localization=LOCALIZATION) - return render_template('index.html', roadmap=roadmap, localization=LOCALIZATION) + return response @app.route('/roadmap/<roadmapID>/fragment') def roadmap_fragement_by_id(roadmapID): + success, response = __check_roadmap(roadmapID) + if success: + return render_template('roadmapFragment.html', roadmap=response, localization=LOCALIZATION) + + return response + + +def __check_roadmap(roadmapID): try: roadmapID = int(roadmapID) except ValueError: - return render_template('error.html', message=LOCALIZATION['error_param_invalid']) + return False, render_template('error.html', message=LOCALIZATION['error_param_invalid']) if roadmapID < 1: - return render_template('error.html', message=LOCALIZATION['error_param_invalid']) + return False, render_template('error.html', message=LOCALIZATION['error_param_invalid']) roadmap = requests.get(URL_BUILDER.build_url('roadmap', roadmapID, 'full')).json() if roadmap is None: - return render_template('error.html', message=LOCALIZATION['error_roadmap_not_existing']) + return False, render_template('error.html', message=LOCALIZATION['error_roadmap_not_existing']) - return render_template('roadmapFragment.html', roadmap=roadmap, localization=LOCALIZATION) + return True, roadmap if __name__ == '__main__': @@ -80,5 +89,6 @@ if __name__ == '__main__': else: http_server = WSGIServer((SETTINGS['listen'], SETTINGS['port']), app) - print('Listening on {}:{}...'.format(SETTINGS['listen'], SETTINGS['port'])) + print('RoadmapClient {}({}) - Listening on {}:{}...'.format(VERSION['name'], VERSION['code'], + SETTINGS['listen'], SETTINGS['port'])) http_server.serve_forever() diff --git a/client/version.json b/client/version.json new file mode 100644 index 0000000..b56cd07 --- /dev/null +++ b/client/version.json @@ -0,0 +1,7 @@ +{ + "version": { + "name": "v1.0.0", + "code": 1, + "date": "30.07.19" + } +} \ No newline at end of file -- GitLab