-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
173 lines (155 loc) · 5.97 KB
/
config.py
File metadata and controls
173 lines (155 loc) · 5.97 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
"""
Configuration management
"""
import json
from pathlib import Path
from typing import Dict, Any, cast
import copy
# Default settings structure
DEFAULT_SETTINGS: Dict[str, Any] = {
'version': {
'godot_version': "4.5.1"
},
'colors': {
'bg': '#1e1e1e',
'fg': '#e0e0e0',
'accent': '#0d47a1',
'accent_light': '#1565c0',
'success': '#4caf50',
'warning': '#ff9800',
'error': '#f44336',
'panel_bg': '#2d2d2d',
'border': '#404040'
},
'database': {
'container_name': 'openchamp-db',
'database_host': '127.0.0.1',
'database_name': 'openchamp',
'database_user': 'openchamp',
'database_password': 'openchamp',
'database_port': '5432',
'persistent_database': True,
'custom_image': False,
'custom_image_tag': 'postgres:latest'
},
'file_paths': {
'log_file_name': "openchamp_admin_tool.log",
'mm_server_build_name': "oc_matchmaking_server.exe",
'ds_server_build_name': "oc_dedicated_server.exe"
},
'ui_dimensions': {
'window_width': 1200,
'window_height': 700,
'init_window_width': 600,
'init_window_height': 500,
'output_window_width': 800,
'output_window_height': 500,
'settings_window_width': 600,
'settings_window_height': 650
},
'intervals': {
'monitoring_update_interval': 2000, # milliseconds
'queue_process_interval': 500, # milliseconds
'output_process_interval': 100 # milliseconds
},
'timeouts': {
'subprocess_timeout': 10, # seconds
'git_timeout': 60, # seconds
'build_timeout': 180, # seconds
'large_build_timeout': 240, # seconds
'godot_timeout': 180, # seconds
'download_timeout': 120 # seconds
}
}
class ConfigManager:
"""Manages application configuration persistence"""
def __init__(self):
self.install_dir = Path.home() / "OpenChamp"
self.config_file = Path.home() / ".openchamp_admin_config.json"
self.settings: Dict[str, Any] = copy.deepcopy(DEFAULT_SETTINGS)
self.load()
def load(self):
"""Load configuration from file"""
if self.config_file.exists():
try:
with open(self.config_file, 'r') as f:
config = json.load(f)
self.install_dir = Path(config.get('install_dir', self.install_dir))
# Load settings, merging with defaults
saved_settings = config.get('settings', {})
self._merge_settings(saved_settings)
except Exception as e:
print(f"Error loading config: {e}")
def save(self):
"""Save configuration to file"""
try:
with open(self.config_file, 'w') as f:
json.dump({
'install_dir': str(self.install_dir),
'settings': self.settings
}, f, indent=2)
except Exception as e:
print(f"Error saving config: {e}")
def _merge_settings(self, saved_settings: Dict[str, Any]):
"""Recursively merge saved settings with defaults"""
for key, value in saved_settings.items():
if key in self.settings:
if isinstance(value, dict) and isinstance(self.settings[key], dict):
self.settings[key].update(value)
else:
self.settings[key] = value
def update_install_dir(self, new_path: str):
"""Update installation directory"""
self.install_dir = Path(new_path)
self.save()
def update_setting(self, category: str, key: str, value: Any):
"""Update a specific setting"""
if category in self.settings and isinstance(self.settings[category], dict):
self.settings[category][key] = value
self.save()
else:
raise ValueError(f"Invalid setting category: {category}")
def update_settings_category(self, category: str, settings: Dict[str, Any]):
"""Update an entire settings category"""
if category in self.settings:
if isinstance(self.settings[category], dict):
self.settings[category].update(settings)
else:
self.settings[category] = settings
self.save()
else:
raise ValueError(f"Invalid setting category: {category}")
def get_setting(self, category: str, key: str, default: Any = None) -> Any:
"""Get a specific setting"""
category_settings = self.settings.get(category)
if isinstance(category_settings, dict):
return category_settings.get(key, default) # type: ignore
return default
def get_settings_category(self, category: str) -> Dict[str, Any]:
"""Get an entire settings category"""
category_settings = self.settings.get(category, {})
if isinstance(category_settings, dict):
return cast(Dict[str, Any], category_settings)
return {}
# Convenience properties for commonly used settings
@property
def godot_version(self) -> str:
return self.get_setting('version', 'godot_version', "4.5.1")
@property
def colors(self) -> Dict[str, str]:
return self.get_settings_category('colors')
@property
def database_settings(self) -> Dict[str, Any]:
return self.get_settings_category('database')
@property
def ui_dimensions(self) -> Dict[str, int]:
return self.get_settings_category('ui_dimensions')
@property
def timeouts(self) -> Dict[str, int]:
return self.get_settings_category('timeouts')
@property
def intervals(self) -> Dict[str, int]:
return self.get_settings_category('intervals')
@property
def file_paths(self) -> Dict[str, str]:
return self.get_settings_category('file_paths')