Implement static config for server info
This commit is contained in:
5
Makefile
5
Makefile
@@ -11,9 +11,6 @@ build:
|
|||||||
# Target to run the server container using the host network
|
# Target to run the server container using the host network
|
||||||
run: build
|
run: build
|
||||||
docker run -it --rm \
|
docker run -it --rm \
|
||||||
-e SERVER_WS_URI=${SERVER_WS_URI} \
|
-v "$(pwd)/data":/data \
|
||||||
-e SERVER_API_URL=${SERVER_API_URL} \
|
|
||||||
-e CLIENT_API_URL=${CLIENT_API_URL} \
|
|
||||||
-v $(pwd)/data:/data \
|
|
||||||
--network=host \
|
--network=host \
|
||||||
$(CLIENT_IMAGE)
|
$(CLIENT_IMAGE)
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ if not app_conf.get("nickname"):
|
|||||||
|
|
||||||
app_conf.set("nickname", generated_nickname)
|
app_conf.set("nickname", generated_nickname)
|
||||||
NICKNAME = app_conf.get("nickname")
|
NICKNAME = app_conf.get("nickname")
|
||||||
|
|
||||||
|
print(app_conf)
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
|
|
||||||
# Dictionary mapping command names (strings) to local client functions
|
# Dictionary mapping command names (strings) to local client functions
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class Config:
|
|||||||
except IOError as e:
|
except IOError as e:
|
||||||
print(f"Error saving config file {self.file_path}: {e}")
|
print(f"Error saving config file {self.file_path}: {e}")
|
||||||
except TypeError as 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):
|
def get(self, key, default=None):
|
||||||
"""
|
"""
|
||||||
@@ -89,6 +89,22 @@ class Config:
|
|||||||
else:
|
else:
|
||||||
print(f"Warning: Key '{key}' not found in config.")
|
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):
|
def __getattr__(self, name):
|
||||||
"""
|
"""
|
||||||
Allows accessing configuration values using attribute notation (e.g., config.my_key).
|
Allows accessing configuration values using attribute notation (e.g., config.my_key).
|
||||||
@@ -108,7 +124,7 @@ class Config:
|
|||||||
try:
|
try:
|
||||||
return self.__getattribute__(name)
|
return self.__getattribute__(name)
|
||||||
except AttributeError:
|
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):
|
def __setattr__(self, name, value):
|
||||||
"""
|
"""
|
||||||
@@ -136,4 +152,4 @@ class Config:
|
|||||||
self.delete(name)
|
self.delete(name)
|
||||||
else:
|
else:
|
||||||
# Fallback for standard attributes
|
# Fallback for standard attributes
|
||||||
super().__delattr__(name)
|
super().__delattr__(name)
|
||||||
|
|||||||
Reference in New Issue
Block a user