-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
40 lines (32 loc) · 1.15 KB
/
config.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
import configparser
import os
import logging
CONFIG_FILE = "config.ini"
def load_config():
config = configparser.ConfigParser()
# Check if the config file exists
if not os.path.exists(CONFIG_FILE):
logging.error("Error: No config.ini found. Creating default config.ini...")
create_default_config()
exit(1)
config.read(CONFIG_FILE)
try:
host_ip = config.get("SERVER", "HOST_IP")
host_port = config.get("SERVER", "HOST_Port")
player_id = config.get("PLAYER", "Player_ID")
return host_ip, host_port, player_id
except (configparser.NoSectionError, configparser.NoOptionError):
logging.error("Error: Invalid config.ini format. Please check your configuration.")
exit(1)
def create_default_config():
config = configparser.ConfigParser()
config["SERVER"] = {
"HOST_IP": "LMS IP",
"HOST_Port": "LMS Port"
}
config["PLAYER"] = {
"Player_ID": "Your Player's MAC address"
}
with open(CONFIG_FILE, "w") as configfile:
config.write(configfile)
logging.info("Default config.ini created. Please edit it and restart the script.")