From ba1b37f5fe57611a95acc1b2c39ff300c16aff3b Mon Sep 17 00:00:00 2001 From: Jan-Pieter Baert Date: Tue, 19 Apr 2022 20:40:06 +0200 Subject: [PATCH 1/2] Update populate-db to be less hacky --- populate-db.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/populate-db.sh b/populate-db.sh index 400ce2e..5d7157c 100755 --- a/populate-db.sh +++ b/populate-db.sh @@ -3,5 +3,5 @@ set -euo pipefail cd "$(dirname "$0")/app" cp database/* . -../venv/bin/python create_database.py setup_database +env python create_database.py setup_database rm -f add_* create_database.py muhscheme.txt From 2123d7d1a3af99e826c411023fd16c884169ea14 Mon Sep 17 00:00:00 2001 From: mcbloch Date: Tue, 19 Apr 2022 21:31:40 +0200 Subject: [PATCH 2/2] fix the weird copying of files --- app/{database => }/add_admins.py | 5 +++-- app/app.py | 3 ++- app/{database => }/create_database.py | 14 ++++++++------ populate-db.sh | 3 +-- 4 files changed, 14 insertions(+), 11 deletions(-) rename app/{database => }/add_admins.py (84%) rename app/{database => }/create_database.py (86%) diff --git a/app/database/add_admins.py b/app/add_admins.py similarity index 84% rename from app/database/add_admins.py rename to app/add_admins.py index f47dfe0..661c880 100644 --- a/app/database/add_admins.py +++ b/app/add_admins.py @@ -1,10 +1,11 @@ -"Script for adding users as admin to Haldis." +"""Script for adding users as admin to Haldis.""" + from app import db from models import User def add() -> None: - "Add users as admin." + """Add users as admin.""" feli = User() feli.configure("feliciaan", True, 0) db.session.add(feli) diff --git a/app/app.py b/app/app.py index d1abfbc..0273c47 100755 --- a/app/app.py +++ b/app/app.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 -"Main Haldis script" +"""Main Haldis script""" + import logging from logging.handlers import TimedRotatingFileHandler import typing diff --git a/app/database/create_database.py b/app/create_database.py similarity index 86% rename from app/database/create_database.py rename to app/create_database.py index 5460776..e11305b 100644 --- a/app/database/create_database.py +++ b/app/create_database.py @@ -1,5 +1,7 @@ -"Script for interaction and changes to the database" +"""Script for interaction and changes to the database""" + import add_admins + from app import db, app_manager entry_sets = { @@ -11,13 +13,13 @@ no = ["no", "n"] def commit() -> None: - "Commit all the things to the database" + """Commit all the things to the database""" db.session.commit() print("Committing successful") def check_if_overwrite() -> bool: - "Check if the user wants to overwrite the previous database" + """Check if the user wants to overwrite the previous database""" answer = input("Do you want to overwrite the previous database? (y/N) ") return answer.lower() in yes @@ -30,7 +32,7 @@ def add_all() -> None: def recreate_from_scratch() -> None: - "Recreate a completely new database" + """Recreate a completely new database""" print("Resetting the database!") db.drop_all() db.create_all() @@ -38,7 +40,7 @@ def recreate_from_scratch() -> None: def add_to_current() -> None: - "Add things to the current database" + """Add things to the current database""" available = [entry_set for entry_set in entry_sets] def add_numbers() -> str: @@ -68,7 +70,7 @@ def add_to_current() -> None: @app_manager.command def setup_database(): # type: None - "Start the database interaction script" + """Start the database interaction script""" print("Database modification script!") print("=============================\n\n") if (not db.engine.table_names()) or check_if_overwrite(): diff --git a/populate-db.sh b/populate-db.sh index 5d7157c..7735440 100755 --- a/populate-db.sh +++ b/populate-db.sh @@ -2,6 +2,5 @@ set -euo pipefail cd "$(dirname "$0")/app" -cp database/* . + env python create_database.py setup_database -rm -f add_* create_database.py muhscheme.txt