2019-09-08 02:02:16 +02:00
|
|
|
import add_admins
|
|
|
|
import add_fitchen
|
|
|
|
import add_oceans_garden
|
|
|
|
import add_primadonna
|
|
|
|
import add_simpizza
|
2019-10-01 20:57:23 +02:00
|
|
|
import add_testlocation
|
2019-09-11 04:10:24 +02:00
|
|
|
from app import db, create_app
|
2015-04-04 14:11:55 +02:00
|
|
|
|
2019-06-28 18:57:41 +02:00
|
|
|
entry_sets = {
|
|
|
|
"Admins": add_admins.add,
|
2019-10-01 20:57:23 +02:00
|
|
|
"Testlocation": add_testlocation.add,
|
2019-06-28 18:57:41 +02:00
|
|
|
"Ocean's Garden": add_oceans_garden.add,
|
|
|
|
"SimPizza": add_simpizza.add,
|
|
|
|
"Primadonna": add_primadonna.add,
|
2019-09-05 03:33:29 +02:00
|
|
|
"Fitchen": add_fitchen.add,
|
2019-06-28 18:57:41 +02:00
|
|
|
}
|
|
|
|
|
2019-10-01 20:58:24 +02:00
|
|
|
yes = ["yes", "y"]
|
|
|
|
no = ["no", "n"]
|
2015-04-04 14:11:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Commit all the things
|
2019-09-07 15:05:24 +02:00
|
|
|
def commit() -> None:
|
2015-04-04 14:11:55 +02:00
|
|
|
db.session.commit()
|
|
|
|
print("Committing successful")
|
|
|
|
|
|
|
|
|
2019-09-07 15:05:24 +02:00
|
|
|
def check_if_overwrite() -> bool:
|
2018-03-09 00:59:14 +01:00
|
|
|
answer = input("Do you want to overwrite the previous database? (y/N) ")
|
2019-10-01 20:58:24 +02:00
|
|
|
return answer.lower() in yes
|
2015-04-04 14:11:55 +02:00
|
|
|
|
|
|
|
|
2019-09-07 15:05:24 +02:00
|
|
|
def add_all() -> None:
|
2015-04-04 14:26:09 +02:00
|
|
|
for entry_set in entry_sets.keys():
|
|
|
|
print("Adding {}.".format(entry_set))
|
|
|
|
entry_sets[entry_set]()
|
2015-04-04 14:11:55 +02:00
|
|
|
|
|
|
|
|
2019-09-07 15:05:24 +02:00
|
|
|
def recreate_from_scratch() -> None:
|
2018-03-08 23:22:51 +01:00
|
|
|
confirmation = "Are you very very sure? (Will delete previous entries!) (y/N) "
|
2019-10-22 14:10:56 +02:00
|
|
|
if input(confirmation) in yes:
|
2015-05-13 13:34:32 +02:00
|
|
|
print("Resetting the database!")
|
|
|
|
db.drop_all()
|
|
|
|
db.create_all()
|
|
|
|
add_to_current()
|
2019-10-01 20:58:24 +02:00
|
|
|
else:
|
|
|
|
print("You cancelled.")
|
2015-04-04 14:11:55 +02:00
|
|
|
|
|
|
|
|
2019-09-07 15:05:24 +02:00
|
|
|
def add_to_current() -> None:
|
2015-04-04 14:26:09 +02:00
|
|
|
available = [entry_set for entry_set in entry_sets]
|
2015-04-04 14:11:55 +02:00
|
|
|
|
2019-09-07 15:05:24 +02:00
|
|
|
def add_numbers() -> str:
|
2019-09-05 03:33:29 +02:00
|
|
|
return " ".join(
|
|
|
|
["{}({}), ".format(loc, i) for i, loc in enumerate(available)]
|
|
|
|
).rstrip(", ")
|
2015-04-04 14:11:55 +02:00
|
|
|
|
2019-10-01 20:58:24 +02:00
|
|
|
while input("Do you still want to add something? (Y/n) ").lower() not in no:
|
2019-09-05 03:33:29 +02:00
|
|
|
print(
|
|
|
|
"What do you want to add? (Use numbers, or A for all, or C for cancel) "
|
|
|
|
)
|
2018-03-09 00:59:14 +01:00
|
|
|
answer = input("Available: {} : ".format(add_numbers()))
|
2019-10-01 20:58:24 +02:00
|
|
|
if answer.lower() == "a":
|
2015-04-04 14:11:55 +02:00
|
|
|
add_all()
|
2015-05-13 13:34:32 +02:00
|
|
|
available = []
|
2019-10-01 20:58:24 +02:00
|
|
|
elif answer.lower() == "c":
|
2015-04-04 14:11:55 +02:00
|
|
|
pass
|
2019-09-07 15:05:24 +02:00
|
|
|
elif answer.isnumeric() and answer in [str(x) for x in range(len(available))]:
|
|
|
|
answer_index = int(answer)
|
|
|
|
print("Adding {}.".format(available[answer_index]))
|
|
|
|
entry_sets[str(available[answer_index])]()
|
|
|
|
del available[answer_index]
|
2015-04-04 14:11:55 +02:00
|
|
|
else:
|
|
|
|
print("Not a valid answer.")
|
|
|
|
print("Thank you for adding, come again!")
|
|
|
|
|
2019-09-11 04:10:24 +02:00
|
|
|
manager = create_app()
|
2015-04-04 14:11:55 +02:00
|
|
|
|
2019-09-11 04:10:24 +02:00
|
|
|
@manager.command
|
|
|
|
def setup_database():
|
2019-09-05 03:33:29 +02:00
|
|
|
print("Database modification script!")
|
|
|
|
print("=============================\n\n")
|
2015-04-04 14:11:55 +02:00
|
|
|
if check_if_overwrite():
|
|
|
|
recreate_from_scratch()
|
|
|
|
else:
|
|
|
|
add_to_current()
|
2015-04-04 14:36:19 +02:00
|
|
|
commit()
|
2015-04-04 14:11:55 +02:00
|
|
|
|
|
|
|
|
2019-09-11 04:10:24 +02:00
|
|
|
manager.run()
|