-
Notifications
You must be signed in to change notification settings - Fork 7
/
settings_init.py
35 lines (28 loc) · 983 Bytes
/
settings_init.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 os
import json
from lvp_logger import lvp_appdata, logger
global settings
def load_settings(logger, filename):
global settings
# load settings JSON file
try:
os.chdir(lvp_appdata)
read_file = open(filename, "r")
except:
logger.exception('[LVP Main ] Unable to open file '+filename)
raise
else:
try:
settings = json.load(read_file)
except:
logger.exception('[LVP Main ] Incompatible JSON file for Microscope Settings')
os.chdir(lvp_appdata)
if os.path.exists("./data/current.json"):
load_settings(logger, "./data/current.json")
elif os.path.exists("./data/settings.json"):
load_settings(logger, "./data/settings.json")
else:
if not os.path.isdir('./data'):
raise FileNotFoundError("Cound't find 'data' directory.")
else:
raise FileNotFoundError('No settings files found.')