-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig_manager.py
More file actions
76 lines (65 loc) · 2.12 KB
/
Copy pathconfig_manager.py
File metadata and controls
76 lines (65 loc) · 2.12 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import json
import os
class ConfigManager:
def __init__(self, config_file='config.json'):
self.config_file = config_file
self.config = self.load_config()
def load_config(self):
default_config = {
'language': 'en',
'email_notifications': False,
'email_address': '',
'smtp_server': 'smtp.gmail.com',
'smtp_port': 587,
'smtp_username': '',
'smtp_password': '',
'enabled_error_types': [
'SyntaxError',
'TypeError',
'ValueError',
'AttributeError',
'NameError',
'ImportError',
'IndexError',
'KeyError',
'FileNotFoundError',
'404Error',
'500Error',
'DatabaseError',
'ConnectionError'
],
'log_retention_days': 30,
'max_logs_per_file': 10000,
'monitoring_interval': 2
}
if os.path.exists(self.config_file):
try:
with open(self.config_file, 'r') as f:
loaded_config = json.load(f)
default_config.update(loaded_config)
except:
pass
return default_config
def save_config(self):
try:
with open(self.config_file, 'w') as f:
json.dump(self.config, f, indent=4)
return True
except Exception as e:
print(f"Error saving config: {e}")
return False
def get_config(self):
return self.config.copy()
def update_config(self, updates):
self.config.update(updates)
return self.save_config()
def get(self, key, default=None):
return self.config.get(key, default)
def set(self, key, value):
self.config[key] = value
return self.save_config()
def reset_to_defaults(self):
if os.path.exists(self.config_file):
os.remove(self.config_file)
self.config = self.load_config()
return self.save_config()