-
Notifications
You must be signed in to change notification settings - Fork 32
/
setup.py
131 lines (104 loc) · 3.55 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import os
from pathlib import Path
import django
import django_json_widget as _
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yata.settings")
django.setup()
from decouple import config # noqa: E402
from django.contrib.auth.models import User # noqa: E402
from awards.models import AwardsData # noqa: E402
from bazaar.models import BazaarData # noqa: E402
from company.models import CompanyDescription # noqa: E402
from faction.models import Faction, FactionData # noqa: E402
from loot.models import NPC # noqa: E402
from player.models import Player, PlayerData # noqa: E402
from setup.models import APIKey # noqa: E402
def yes_or_no(question):
reply = str(input(question + " (y/n): ")).lower().strip()
if reply[0] == "y":
return True
if reply[0] == "n":
return False
else:
return yes_or_no("Uhhhh... please enter ")
key = config("SECRET_KEY")
reset_db = False
fill_db = False
static_files = False
reset_db = yes_or_no("Do you want to reset the database?")
fill_db = yes_or_no("Do you want to fill the database?")
static_file = yes_or_no("Do you want to generate static files?")
if reset_db:
if config("DATABASE") == "postgresql":
print("Remove local database")
cmd = "python manage.py reset_db"
r = os.system(cmd)
else:
# remove local database
print("Remove local database")
cmd = "rm -vf db.sqlite3"
r = os.system(cmd)
# migrate
cmd = "python manage.py migrate"
r = os.system(cmd)
# create cache table
cmd = "python manage.py createcachetable"
r = os.system(cmd)
# create db super user
if not len(User.objects.all()):
print("create superuser")
User.objects.create_superuser("admin", "[email protected]", "adminpass")
# create required objects
if not len(PlayerData.objects.all()):
print("Create Players stats")
cmd = "python manage.py players_stats"
r = os.system(cmd)
if not len(Player.objects.filter(tId=-1)):
print("Create Player")
Player.objects.create(tId=-1, name="Anonymous", validKey=False)
if not len(Faction.objects.filter(tId=-1)):
print("Create Faction")
Faction.objects.create(tId=-1, name="Faction Anonymous")
if not len(APIKey.objects.all()) and key:
print("Create API Key")
APIKey.objects.create(key=key)
if not len(AwardsData.objects.all()):
print("Create Awards data")
AwardsData.objects.create()
if not len(BazaarData.objects.all()):
print("Create Bazaar data")
BazaarData.objects.create()
if not len(FactionData.objects.all()):
print("Create Faction data")
FactionData.objects.create()
cmd = "python manage.py init_faction_tree"
r = os.system(cmd)
if not len(NPC.objects.all()):
print("Create NPC")
NPC.objects.create(tId=4, show=True)
NPC.objects.create(tId=15, show=True)
NPC.objects.create(tId=19, show=True)
if not len(CompanyDescription.objects.all()):
print("Create NPC")
cmd = "python manage.py init_companies"
r = os.system(cmd)
if fill_db:
cmd = "python manage.py check_keys"
r = os.system(cmd)
cmd = "python manage.py awards"
r = os.system(cmd)
cmd = "python manage.py items"
r = os.system(cmd)
cmd = "python manage.py players"
r = os.system(cmd)
cmd = "python manage.py loot"
r = os.system(cmd)
cmd = "python manage.py factions"
r = os.system(cmd)
cmd = "python manage.py companies"
r = os.system(cmd)
if static_file:
p = Path(_.__path__[0]) / "static" / "dist" / "jsoneditor.map"
p.touch()
cmd = "python manage.py collectstatic --noinput"
r = os.system(cmd)