-
Notifications
You must be signed in to change notification settings - Fork 3
/
config_singleton.py
35 lines (27 loc) · 937 Bytes
/
config_singleton.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
import json
class ConfigSingleton:
__instance = None
@staticmethod
def getInstance():
""" Static access method. """
if ConfigSingleton.__instance == None:
ConfigSingleton()
return ConfigSingleton.__instance
@staticmethod
def open_files(path):
CONFIGURATION_FILE = path
with open(CONFIGURATION_FILE) as config_file:
return json.load(config_file)
def __init__(self):
try:
self.config = ConfigSingleton.open_files("configuration.json")
except FileNotFoundError as ex:
self.config = ConfigSingleton.open_files("..\configuration.json")
if ConfigSingleton.__instance != None:
raise Exception("ConfigSingleton EXCEPTION")
else:
ConfigSingleton.__instance = self
def get_config(self):
return self.config
# maybe needed V V V
# ConfigSingleton.getInstance()