-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
36 lines (28 loc) · 1022 Bytes
/
utils.py
File metadata and controls
36 lines (28 loc) · 1022 Bytes
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
from threading import Event
import tomllib
import os
import sys
import nanoid
def generate(size=20): return nanoid.generate(size=size)
stopping=Event()
with open("version.toml", "rb") as f:
version_data=tomllib.load(f)
version=version_data["version"]
db_version=version_data["db"]
if not os.path.isfile("config.toml") or os.path.getsize("config.toml")==0:
with open("default_config.toml") as fc:
with open("config.toml", "w") as f:
f.write("".join(fc.readlines()[2:]).replace("$URI_PREFIX", generate()))
print("Wrote config.toml")
sys.exit(1)
with open("config.toml", "rb") as f:
config=tomllib.load(f)
if config["version"]<version_data["config"]:
print("Your config.toml version doesn't match, please remove it and run the program again to create a new one")
sys.exit(1)
dev_mode="--dev" in sys.argv or config["server"]["dev"]
BLUE="\033[34m"
YELLOW="\033[33m"
RED="\033[31m"
RESET="\033[0m"
def colored_log(color, tag, text): print(f"{color}[{tag}]{RESET} {text}")