Skip to content
Snippets Groups Projects
Commit 79b2e722 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

client: use TheCodeLabs util packages

parent 616f06cd
No related branches found
No related tags found
No related merge requests found
APP_NAME = 'RoadmapClient'
...@@ -3,6 +3,11 @@ url = "https://pypi.python.org/simple" ...@@ -3,6 +3,11 @@ url = "https://pypi.python.org/simple"
verify_ssl = true verify_ssl = true
name = "pypi" name = "pypi"
[[source]]
url = "https://pypi.thecodedev.de"
verify_ssl = true
name = "TheCodeLabs"
[requires] [requires]
python_version = "3.7" python_version = "3.7"
...@@ -10,3 +15,5 @@ python_version = "3.7" ...@@ -10,3 +15,5 @@ python_version = "3.7"
flask = "==1.1.2" flask = "==1.1.2"
gevent = "==1.5.0" gevent = "==1.5.0"
requests = "==2.23.0" requests = "==2.23.0"
TheCodeLabs-BaseUtils = "==1.0.0"
TheCodeLabs-FlaskUtils = "==1.0.2"
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "dbb97f2c25b5f5b072a133a61c9a6916e36d02156fb4b8e187f292adc2bc8a6d" "sha256": "7f0ccba88af4e372830e455cfe1038d236826bbe8f73f551f1644e55f5f328d8"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
...@@ -12,6 +12,11 @@ ...@@ -12,6 +12,11 @@
"name": "pypi", "name": "pypi",
"url": "https://pypi.python.org/simple", "url": "https://pypi.python.org/simple",
"verify_ssl": true "verify_ssl": true
},
{
"name": "TheCodeLabs",
"url": "https://pypi.thecodedev.de",
"verify_ssl": true
} }
] ]
}, },
...@@ -66,10 +71,10 @@ ...@@ -66,10 +71,10 @@
}, },
"click": { "click": {
"hashes": [ "hashes": [
"sha256:8a18b4ea89d8820c5d0c7da8a64b2c324b4dabb695804dbfea19b9be9d88c0cc", "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a",
"sha256:e345d143d80bf5ee7534056164e5e112ea5e22716bbb1ce727941f4c8b471b9a" "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"
], ],
"version": "==7.1.1" "version": "==7.1.2"
}, },
"flask": { "flask": {
"hashes": [ "hashes": [
...@@ -210,6 +215,20 @@ ...@@ -210,6 +215,20 @@
"index": "pypi", "index": "pypi",
"version": "==2.23.0" "version": "==2.23.0"
}, },
"thecodelabs-baseutils": {
"hashes": [
"sha256:daab1cf2480b3c1352ef94f78774d4c4c8759d91a6c50b113bcb1c73081263cb"
],
"index": "pypi",
"version": "==1.0.0"
},
"thecodelabs-flaskutils": {
"hashes": [
"sha256:98833b87fd1b0b42a7ad6ac9de3b79676623cc21b0fabc940863412e8ee40961"
],
"index": "pypi",
"version": "==1.0.2"
},
"urllib3": { "urllib3": {
"hashes": [ "hashes": [
"sha256:3018294ebefce6572a474f0604c2021e33b3fd8006ecd11d62107a5d2a963527", "sha256:3018294ebefce6572a474f0604c2021e33b3fd8006ecd11d62107a5d2a963527",
......
import json import logging
import os
from datetime import datetime from datetime import datetime
import requests import requests
from flask import Flask, render_template, redirect, jsonify from TheCodeLabs_BaseUtils import DefaultLogger
from gevent.pywsgi import WSGIServer from TheCodeLabs_FlaskUtils import FlaskBaseApp
from flask import render_template, redirect
import Constants
from Localization import LOCALIZATION from Localization import LOCALIZATION
from UrlBuilder import UrlBuilder from UrlBuilder import UrlBuilder
from blueprints import Roadmaps, Authentication, Milestones, Tasks, SubTasks from blueprints import Roadmaps, Authentication, Milestones, Tasks, SubTasks
with open('version.json', 'r') as f: LOGGER = DefaultLogger().create_logger_if_not_exists(Constants.APP_NAME)
VERSION = json.load(f)
VERSION = VERSION['version']
with open('settings.json', 'r') as f:
SETTINGS = json.load(f)
app = Flask(__name__)
app.secret_key = SETTINGS['secret']
class RoadmapClient(FlaskBaseApp):
DEFAULT_DATE = datetime(2000, 1, 1, 0, 0, 0) DEFAULT_DATE = datetime(2000, 1, 1, 0, 0, 0)
URL_BUILDER = UrlBuilder(SETTINGS['apiURL']) def __init__(self, appName: str, rootDir: str, logger: logging.Logger, settingsPath: str):
super().__init__(appName, rootDir, logger, settingsPath=settingsPath)
app.register_blueprint(Authentication.construct_blueprint(URL_BUILDER)) self._urlBuilder = UrlBuilder(self._serverSettings['apiURL'])
app.register_blueprint(Roadmaps.construct_blueprint(URL_BUILDER))
app.register_blueprint(Milestones.construct_blueprint(URL_BUILDER))
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)
def _register_blueprints(self, app):
app.register_blueprint(Authentication.construct_blueprint(self._urlBuilder))
app.register_blueprint(Roadmaps.construct_blueprint(self._urlBuilder))
app.register_blueprint(Milestones.construct_blueprint(self._urlBuilder))
app.register_blueprint(Tasks.construct_blueprint(self._urlBuilder))
app.register_blueprint(SubTasks.construct_blueprint(self._urlBuilder))
@app.route('/') @app.route('/')
def overview(): def overview():
roadmaps = requests.get(URL_BUILDER.build_url('roadmaps')).json() roadmaps = requests.get(self._urlBuilder.build_url('roadmaps')).json()
return render_template('overview.html', roadmaps=roadmaps) return render_template('overview.html', roadmaps=roadmaps)
@app.route('/roadmap/') @app.route('/roadmap/')
def roadmap(): def roadmap():
return redirect('/') return redirect('/')
@app.route('/roadmap/<roadmapID>') @app.route('/roadmap/<roadmapID>')
def roadmap_by_id(roadmapID): def roadmap_by_id(roadmapID):
success, response = __check_roadmap(roadmapID) success, response = self.__check_roadmap(roadmapID, self._urlBuilder)
if success: if success:
return render_template('index.html', roadmap=response, localization=LOCALIZATION) return render_template('index.html', roadmap=response, localization=LOCALIZATION)
return response return response
@app.route('/roadmap/<roadmapID>/fragment') @app.route('/roadmap/<roadmapID>/fragment')
def roadmap_fragment_by_id(roadmapID): def roadmap_fragment_by_id(roadmapID):
success, response = __check_roadmap(roadmapID) success, response = self.__check_roadmap(roadmapID, self._urlBuilder)
if success: if success:
return render_template('roadmapFragment.html', roadmap=response, localization=LOCALIZATION) return render_template('roadmapFragment.html', roadmap=response, localization=LOCALIZATION)
return response return response
@staticmethod
def __check_roadmap(roadmapID): def __check_roadmap(cls, roadmapID, urlBuilder):
try: try:
roadmapID = int(roadmapID) roadmapID = int(roadmapID)
except ValueError: except ValueError:
...@@ -73,7 +64,7 @@ def __check_roadmap(roadmapID): ...@@ -73,7 +64,7 @@ def __check_roadmap(roadmapID):
if roadmapID < 1: if roadmapID < 1:
return False, 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() roadmap = requests.get(urlBuilder.build_url('roadmap', roadmapID, 'full')).json()
if roadmap is None: if roadmap is None:
return False, render_template('error.html', message=LOCALIZATION['error_roadmap_not_existing']) return False, render_template('error.html', message=LOCALIZATION['error_roadmap_not_existing'])
...@@ -81,14 +72,5 @@ def __check_roadmap(roadmapID): ...@@ -81,14 +72,5 @@ def __check_roadmap(roadmapID):
if __name__ == '__main__': if __name__ == '__main__':
if SETTINGS['useSSL']: roadmapClient = RoadmapClient(Constants.APP_NAME, os.path.dirname(__file__), LOGGER, 'settings.json')
http_server = WSGIServer((SETTINGS['listen'], roadmapClient.start_server()
SETTINGS['port']), app,
keyfile=SETTINGS['keyfile'],
certfile=SETTINGS['certfile'])
else:
http_server = WSGIServer((SETTINGS['listen'], SETTINGS['port']), app)
print('RoadmapClient {}({}) - Listening on {}:{}...'.format(VERSION['name'], VERSION['code'],
SETTINGS['listen'], SETTINGS['port']))
http_server.serve_forever()
{ {
"server": {
"listen": "0.0.0.0", "listen": "0.0.0.0",
"port": 11000, "port": 11000,
"secret": "", "secret": "",
...@@ -7,3 +8,4 @@ ...@@ -7,3 +8,4 @@
"certfile": "", "certfile": "",
"apiURL": "" "apiURL": ""
} }
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment