forked from th3r00t/pyShelf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·53 lines (43 loc) · 1.29 KB
/
configure
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
#!/usr/bin/env python3
import os
import sys
import json
from pathlib import Path
from django.core.management.utils import get_random_secret_key
from src.backend.lib.pyShelf import Admin
def load_config():
with open('config.json',"r") as file:
config = json.load(file)
file.close()
return config
def write_config(config):
with open('config.json',"w") as file:
json.dump(config, file)
file.close()
def set_secret(config=load_config()):
if config["SECRET"] == "":
config["SECRET"] = get_random_secret_key()
print(config["SECRET"])
else:
print("Secret already set, skipping.")
def set_book_directory(config=load_config(), *args):
if config["BOOKPATH"] == "":
try: config["BOOKPATH"] = args[0]
except IndexError: config["BOOKPATH"] = input("Input Book Directory ")
def init_django_database():
cmds = [
'python3 manage.py makemigrations',
'python3 manage.py makemigrations interface',
'python3 manage.py migrate',
'python3 manage.py migrate interface',
]
os.chdir("src")
for cmd in cmds:
os.system(cmd)
os.chdir("../")
config = load_config()
set_secret(config)
set_book_directory(config)
write_config(config)
init_django_database()
Admin(Path.cwd()).createsuperuser()