]> git.lizzy.rs Git - cheatdb.git/blob - utils/setup.py
Split hard and soft dependers on meta package page
[cheatdb.git] / utils / setup.py
1 # ContentDB
2 # Copyright (C) 2018  rubenwardy
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
17
18 import os, sys, datetime, inspect
19
20 if not "FLASK_CONFIG" in os.environ:
21         os.environ["FLASK_CONFIG"] = "../config.cfg"
22
23 delete_db = len(sys.argv) >= 2 and sys.argv[1].strip() == "-d"
24 create_db = not (len(sys.argv) >= 2 and sys.argv[1].strip() == "-o")
25 test_data = len(sys.argv) >= 2 and sys.argv[1].strip() == "-t" or not create_db
26
27 # Allow finding the `app` module
28 currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
29 parentdir = os.path.dirname(currentdir)
30 sys.path.insert(0,parentdir)
31
32 from app.models import db, User, UserRank
33 from app.default_data import populate, populate_test_data
34
35 if delete_db and os.path.isfile("db.sqlite"):
36         os.remove("db.sqlite")
37
38 if create_db:
39         print("Creating database tables...")
40         db.create_all()
41
42 print("Filling database...")
43
44 populate(db.session)
45 if test_data:
46         populate_test_data(db.session)
47
48 db.session.commit()