-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings_manager.py
43 lines (36 loc) · 1.37 KB
/
settings_manager.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
# settings_manager.py
import os
import json
import logging
logger = logging.getLogger(__name__)
class SettingsManager:
def __init__(self):
self.settings_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'user_settings.json')
self.default_settings = {
'observer_name': ''
}
self.settings = self.load_settings()
def load_settings(self):
"""Load settings from file or create with defaults if doesn't exist"""
try:
if os.path.exists(self.settings_file):
with open(self.settings_file, 'r') as f:
return json.load(f)
return self.default_settings.copy()
except Exception as e:
logger.error(f"Error loading settings: {str(e)}")
return self.default_settings.copy()
def save_settings(self):
"""Save current settings to file"""
try:
with open(self.settings_file, 'w') as f:
json.dump(self.settings, f, indent=4)
except Exception as e:
logger.error(f"Error saving settings: {str(e)}")
def get_observer_name(self):
"""Get stored observer name"""
return self.settings.get('observer_name', '')
def set_observer_name(self, name):
"""Set and save observer name"""
self.settings['observer_name'] = name
self.save_settings()