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
174
175
176
177
178
179
180
181
|
# KaZoe::Settings Class Documentation
## Overview
The `KaZoe::Settings` class provides a robust system-wide configuration management solution. It allows reading and writing settings from configuration files with category support, type safety, and change notifications.
## Features
- Read settings from multiple configuration files
- Support for different value types (string, int, double, boolean)
- Category-based organization of settings
- File change monitoring
- Permission-based write access
- Change notification system
## Configuration File Structure
Settings are stored in configuration files with the `.conf` extension. The file format supports:
- Categories in square brackets: `[CategoryName]`
- Key-value pairs: `key = value`
- Owner declarations: `@key = owner_id`
### Value Types SettingValue
- Strings: `key = "value"` or `key = value`
- Numbers: `key = 42` or `key = 3.14`
- Booleans: `key = true/false` or `key = on/off`
## Usage
### Initialization
```cmake
find_package(KaZoeSettings REQUIRED)
include_directories(${LIBKAZOESETTINGS_INCLUDE_DIR})
...
target_link_libraries(myproject PUBLIC ${LIBKAZOESETTINGS_LIBRARIES})
```
```cpp
#include <settings.h>
KaZoe::Settings settings; // Creates instance and loads configuration
```
### Reading Settings
```cpp
// Get value with default
auto value = settings.get("key", "category", defaultValue);
// Get value without category
auto value = settings.get("key");
// Get value using category notation
auto value = settings.get("[category]key");
```
### Writing Settings
```cpp
// Set value with category
settings.set("key", value, "category");
// Set value without category
settings.set("key", value);
```
### Utility with SettingValue type
KaZoe::makeValue: provide a way to convert std::string into SettingValue managing numeric, bool and string conversion
```cpp
#include <settings.h>
SettingValue v1 = KaZoe::makeValue("42"); // Integer
SettingValue v2 = KaZoe::makeValue("3.14"); // Double
SettingValue v3 = KaZoe::makeValue("true"); // Boolean
SettingValue v4 = KaZoe::makeValue("text"); // String
```
KaZoe::valueToStr: provide a way to convert SettingValue into std::string to display
```cpp
#include <settings.h>
std::cout << KaZoe::valueToStr(v1) << std::endl;
```
### Change Notifications and print helper function
```cpp
// Set a notification handler
settings.setNotifier([](const std::string& category, const std::string& key, SettingValue value) {
// Handle setting change
std::cout << category << " | " << key << " changed to " << KaZoe::valueToStr(value) << std::endl;
});
```
## File Locations
The system reads configuration from:
- /etc/kazoe.conf - System defaults (read-only)
- /etc/kazoe.conf.d/* - System configuration fragments (read-only, own by projects packages)
- /var/kazoe.conf.d/<appid>.conf - Persistant write data storage (set)
## Permissions
Settings must be declared writable using @key = owner_id
The owner should be the binary filename of the application
Only the declared owner can modify the setting if the program name is the good one
The settings command-line tool can bypass ownership restrictions but must used ONLY for debug usage
## Value Types
The system supports these value types through the SettingValue variant:
- std::string
- int
- double
- bool
# KaZoeSettings Python Module Documentation
## Overview
The KaZoeSettings module provides a Python interface for managing KaZoe settings across your application. It automatically uses the Python script name as a unique identifier.
## Usage Class: KaZoeSettings
```python
from KaZoeSettings import KaZoeSettings
```
## Constructor
```python
settings = KaZoeSettings.KaZoeSettings()
```
Creates a new KaZoeSettings instance using the current Python script name as identifier.
## Methods
### get(key, category="", default=None)
Retrieves a setting value.
Parameters:
key (str): The setting key
category (str, optional): Setting category
default: Default value if setting not found
Returns: The setting value or default if not found
Supported value types: str, int, float, bool
```python
value = settings.get("my_setting", "my_category", "default_value")
```
### set(key, value, category="")
Sets a setting value.
Parameters:
key (str): The setting key
value: The value to set (str, int, float, or bool)
category (str, optional): Setting category
Returns: True if successful, False otherwise
```python
settings.set("my_setting", "new_value", "my_category")
```
## Full example usage
```python
from KaZoeSettings import KaZoeSettings
# Create settings instance
settings = KaZoeSettings()
# Set values
settings.set("port", 8080, "network")
settings.set("debug", True, "app")
# Get values
port = settings.get("port", "network", 80) # returns 8080
debug = settings.get("debug", "app", False) # returns True
```
|