-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathconfig.py
More file actions
32 lines (27 loc) · 1.01 KB
/
Copy pathconfig.py
File metadata and controls
32 lines (27 loc) · 1.01 KB
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
import json
class Config:
"""Handles reading, writing, and formatting the configuration file"""
default_layout = None
def __init__(self):
try:
with open("config.json", "x") as file:
print("Created config file")
file.write("{}")
except FileExistsError:
print("Configuration file found")
self.read_config()
def read_config(self):
"""Reads the config.json file"""
with open("config.json", "r") as config_file:
config_text = config_file.read()
try:
config = json.loads(config_text)
self.default_layout = config["default_layout"]
except Exception as e:
print("Failed to load configuration:", e)
def save_config(self):
"""Writes the config.json file"""
with open("config.json", "w+") as config_file:
config_file.write(json.dumps({
"default_layout": self.default_layout
}))