From c203317320ab2ac052c19ab821d4e0cfe362efe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phillip=20K=C3=BChne?= Date: Fri, 8 Oct 2021 23:18:56 +0200 Subject: [PATCH] Add Version identification to footer --- .gitignore | 5 +++- .vscode/launch.json | 43 +++++++++++++++++++++++++++++---- .vscode/tasks.json | 13 ++++++++++ backend/app/helpers.py | 11 +++++++++ backend/app/main.py | 5 ++++ backend/app/templates/base.html | 2 +- 6 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore index 9fda913..9f3255d 100644 --- a/.gitignore +++ b/.gitignore @@ -134,4 +134,7 @@ data/ # Node Modules -node_modules/ \ No newline at end of file +node_modules/ + +# Version identification file +.version \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 8a0b09b..32d173f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,12 +4,44 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - - - - {"name":"Python: Flask","type":"python","request":"launch","module":"flask","env":{"FLASK_APP":"backend/app/main.py","FLASK_ENV":"development","FLASK_DEBUG":"1"},"args":["run","--no-debugger","--no-reload"],"jinja":true}, - {"name":"Python: Flask (with reload)","type":"python","request":"launch","module":"flask","env":{"FLASK_APP":"backend/app/main.py","FLASK_ENV":"development","FLASK_DEBUG":"1"},"args":["run","--no-debugger"],"jinja":true}, { + "preLaunchTask": "versiondump", + "name": "Python: Flask", + "type": "python", + "cwd": "${workspaceFolder}/backend/app", + "request": "launch", + "module": "flask", + "env": { + "FLASK_APP": "backend/app/main.py", + "FLASK_ENV": "development", + "FLASK_DEBUG": "1" + }, + "args": [ + "run", + "--no-debugger", + "--no-reload" + ], + "jinja": true + }, + { + "preLaunchTask": "versiondump", + "name": "Python: Flask (with reload)", + "type": "python", + "request": "launch", + "module": "flask", + "env": { + "FLASK_APP": "backend/app/main.py", + "FLASK_ENV": "development", + "FLASK_DEBUG": "1" + }, + "args": [ + "run", + "--no-debugger" + ], + "jinja": true + }, + { + "preLaunchTask": "versiondump", "name": "Python: Flask (with reload, externally reachable)", "type": "python", "request": "launch", @@ -27,6 +59,7 @@ "jinja": true }, { + "preLaunchTask": "versiondump", "name": "Python: Flask (externally reachable)", "type": "python", "request": "launch", diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..405b294 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,13 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "versiondump", + "type": "shell", + "command": "git describe > ${workspaceFolder}/backend/app/.version", + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/backend/app/helpers.py b/backend/app/helpers.py index 4261d17..ad01058 100644 --- a/backend/app/helpers.py +++ b/backend/app/helpers.py @@ -32,6 +32,17 @@ def is_valid_uuid(val): def check_config_exists(): return os.path.isfile(config_file) +def load_version(app): + if os.path.isfile(".version"): + with open('.version', 'r') as file: + data = file.read().replace('\n', '') + if data: + app.config['VERSION'] = data + else: + app.config['VERSION'] = "" + else: + app.config['VERSION'] = "" + def setup_config(app): if check_config_exists(): config = json.load(open(config_file)) diff --git a/backend/app/main.py b/backend/app/main.py index 570c7f6..863a0d7 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -200,6 +200,7 @@ def admin(): @app.before_first_request def activate_job(): + helpers.load_version(app) helpers.create_data_directory() database.create_entry_table() database.create_song_table() @@ -208,6 +209,10 @@ def activate_job(): database.create_done_song_view() helpers.setup_config(app) +@app.context_processor +def inject_version(): + return dict(karaoqueue_version=app.config['VERSION']) + if __name__ == "__main__": app.run(host='127.0.0.1', port=8080, debug=True) diff --git a/backend/app/templates/base.html b/backend/app/templates/base.html index 934135e..a2b5ff5 100644 --- a/backend/app/templates/base.html +++ b/backend/app/templates/base.html @@ -75,7 +75,7 @@ {% endif %} - KaraoQueue (stale branch) - © 2019-2021 - Phillip + KaraoQueue {{karaoqueue_version}} - © 2019-2021 - Phillip Kühne