-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathConfig.py
48 lines (41 loc) · 1.57 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
40
41
42
43
44
45
46
47
48
import json
from os.path import exists
# =====================================================================================================================
#
# Authors: Halie Eckert, Gavin Hulvey, Sydney Zuelzke
# Date: 11/9/2021
# Project: Spatial-Social Networks
#
# Purpose:
# Config.py is the class object for the project config. It currently handles storing road networks and file
# locations
#
# =====================================================================================================================
class Config:
def __init__(self):
self.settings = self.defSettings()
self.loadSettings()
# Defines the base config settings
@staticmethod
def defSettings():
settings = {
"Road Networks": {},
"Social Networks": {}
}
return settings
# Updates a setting to a value
def update(self, setting, value):
self.settings[setting] = value
with open("config.json", 'w') as f:
f.write(json.dumps(self.settings, indent=4, sort_keys=True))
# Loads the settings if the file exists and if not, create it
def loadSettings(self):
if exists("config.json"):
with open("config.json", 'r') as f:
self.settings = json.load(f)
else:
with open("config.json", 'w') as f:
f.write(json.dumps(self.settings, indent=4, sort_keys=True))
# Returns the loaded settings
def getSetting(self, setting):
return self.settings[setting]