Repository navigation
Expand file tree
/
Copy pathconfigmanager.py
More file actions
90 lines (72 loc) · 3.7 KB
/
Copy pathconfigmanager.py
File metadata and controls
90 lines (72 loc) · 3.7 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
"""
a:zak-45
d:20/12/2024
v:1.0.0
Manages configuration settings for the application across different environments.
"""
from os import environ
from utils import setup_logging, read_config
class ConfigManager:
"""
Manages configuration settings for the application across different environments.
This class handles configuration initialization, logging setup, and provides access to various configuration sections.
Attributes:
logger: Configured logger instance for the application.
server_config: Configuration settings related to server parameters.
app_config: General application configuration settings.
color_config: Color-related configuration settings.
custom_config: Custom configuration parameters.
logging_config_path: Path to the logging configuration file.
logger_name: Name of the logger to be used.
The configuration management supports both standard and one-file executable environments,
ensuring flexible configuration loading and logging setup.
# Usage
config_manager = ConfigManager(logging_config_path='path/to/logging.ini', logger_name='CustomLoggerName')
"""
def __init__(self, logging_config_path='config/logging.ini', logger_name='WLEDLogger'):
"""
Initializes the configuration manager with default or specified logging configuration settings.
Sets up initial configuration attributes and prepares for configuration loading.
Args:
logging_config_path (str, optional): Path to the logging configuration file. Defaults to 'config/logging.ini'.
logger_name (str, optional): Name of the logger to be used. Defaults to 'WLEDLogger'.
The method initializes configuration-related attributes to None and sets the provided logging configuration path
and logger name. It then calls the initialize method to set up the configuration based on the current environment.
"""
self.logger = None
self.server_config = None
self.app_config = None
self.color_config = None
self.custom_config = None
self.logging_config_path = logging_config_path
self.logger_name = logger_name
self.initialize()
def initialize(self):
"""
When this env var exists, this means running from the one-file compressed executable.
This env does not exist when running from the extracted program.
Expected way to work.
"""
if "NUITKA_ONEFILE_PARENT" not in environ:
self.setup()
def setup(self):
"""
Configures the logging system and loads various configuration sections for the application.
This method sets up the logger and populates configuration attributes with settings from the configuration file.
The method performs the following key actions:
- Initializes the logger using the specified configuration path and logger name
- Reads the configuration file
- Assigns configuration sections to specific attributes for easy access
- Provides a centralized method for setting up application configurations
The configuration sections include server settings, application parameters, color configurations,
and custom settings, making them readily available throughout the application.
"""
# read config
# create logger
self.logger = setup_logging(self.logging_config_path, self.logger_name)
lip_config = read_config()
# config keys
self.server_config = lip_config[0] # server key
self.app_config = lip_config[1] # app key
self.color_config = lip_config[2] # colors key
self.custom_config = lip_config[3] # custom key