Implement static config for server info

This commit is contained in:
Logan Cusano
2025-06-22 22:08:25 -04:00
parent 84135f1eb0
commit 01f892a6db
3 changed files with 22 additions and 7 deletions

View File

@@ -11,9 +11,6 @@ build:
# Target to run the server container using the host network
run: build
docker run -it --rm \
-e SERVER_WS_URI=${SERVER_WS_URI} \
-e SERVER_API_URL=${SERVER_API_URL} \
-e CLIENT_API_URL=${CLIENT_API_URL} \
-v $(pwd)/data:/data \
-v "$(pwd)/data":/data \
--network=host \
$(CLIENT_IMAGE)

View File

@@ -30,6 +30,8 @@ if not app_conf.get("nickname"):
app_conf.set("nickname", generated_nickname)
NICKNAME = app_conf.get("nickname")
print(app_conf)
# ----------------------------
# Dictionary mapping command names (strings) to local client functions

View File

@@ -50,7 +50,7 @@ class Config:
except IOError as e:
print(f"Error saving config file {self.file_path}: {e}")
except TypeError as e:
print(f"Error serializing config data to JSON: {e}. Ensure all values are JSON serializable.")
print(f"Error serializing config data to JSON: {e}. Ensure all values are JSON serializable.")
def get(self, key, default=None):
"""
@@ -89,6 +89,22 @@ class Config:
else:
print(f"Warning: Key '{key}' not found in config.")
def __str__(self):
"""
Returns a neat, formatted string representation of all configuration
key-value pairs. This method is automatically called when the object
is converted to a string (e.g., by print()).
"""
if not self._config_data:
return "\n--- Configuration is Empty ---\n"
output = ["\n--- Current Configuration ---"]
max_key_len = max(len(key) for key in self._config_data)
for key, value in self._config_data.items():
output.append(f"{key.ljust(max_key_len)} : {json.dumps(value, indent=None)}")
output.append("-----------------------------\n")
return "\n".join(output)
def __getattr__(self, name):
"""
Allows accessing configuration values using attribute notation (e.g., config.my_key).
@@ -108,7 +124,7 @@ class Config:
try:
return self.__getattribute__(name)
except AttributeError:
raise AttributeError(f"'Config' object has no attribute '{name}' and key '{name}' not found in config.")
raise AttributeError(f"'Config' object has no attribute '{name}' and key '{name}' not found in config.")
def __setattr__(self, name, value):
"""
@@ -136,4 +152,4 @@ class Config:
self.delete(name)
else:
# Fallback for standard attributes
super().__delattr__(name)
super().__delattr__(name)