-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
75 lines (55 loc) · 1.81 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
import json
import os
from pathlib import Path
import random
import string
try:
with open("/config.json", "r") as file:
config = json.load(file)
except:
config = {}
# generate the secret key if not provided
sync = config.get("sync", {})
secretKey = sync.get("secretKey")
if secretKey is None:
secretKey = "".join(
random.SystemRandom().choice(string.ascii_letters + string.digits)
for _ in range(128)
)
sync["secretKey"] = secretKey
config["sync"] = sync
with open("/config.json", "w") as file:
json.dump(config, file, indent=4)
# Update the config
api = config.get("api", {})
server = api.get("server", {})
server["baseUrl"] = "/api/"
server["webpageUrl"] = "/"
api["server"] = server
driver = api.get("driver", {})
if driver.get("include") is None and driver.get("exclude") is None:
driver["exclude"] = ["MHG"]
api["driver"] = driver
config["api"] = api
# split the config into corresponding components
apiConfig = config.get("api", {})
syncConfig = config.get("sync", {})
# write the config
with open("/app/api/config.json", "w+") as file:
json.dump(apiConfig, file)
with open("/app/sync/config.json", "w+") as file:
json.dump(syncConfig, file)
# create the file if not exists
Path("/data/api/data").mkdir(parents=True, exist_ok=True)
Path("/data/api/image").mkdir(parents=True, exist_ok=True)
Path("/data/sync").mkdir(parents=True, exist_ok=True)
Path("/data/sync/db.sqlite3").touch(mode=0o777, exist_ok=True)
# link the folder/file to the mounted folder/file
try:
os.symlink("/data/api/data", "/app/api/data", target_is_directory=True)
os.symlink("/data/api/image", "/app/api/image", target_is_directory=True)
os.symlink(
"/data/sync/db.sqlite3", "/app/sync/db.sqlite3", target_is_directory=True
)
except FileExistsError:
pass