testgres.postgres-configuration 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- testgres/postgres_configuration/__init__.py +22 -0
- testgres/postgres_configuration/abstract/v00/configuration.py +435 -0
- testgres/postgres_configuration/core/bugcheck_error.py +219 -0
- testgres/postgres_configuration/core/controller_utils.py +982 -0
- testgres/postgres_configuration/core/data_verificator.py +60 -0
- testgres/postgres_configuration/core/handlers.py +483 -0
- testgres/postgres_configuration/core/helpers.py +95 -0
- testgres/postgres_configuration/core/model.py +296 -0
- testgres/postgres_configuration/core/option/handlers/add/option_handler_to_add__std.py +38 -0
- testgres/postgres_configuration/core/option/handlers/get_value/option_handler_to_get_value__std__simple.py +36 -0
- testgres/postgres_configuration/core/option/handlers/get_value/option_handler_to_get_value__std__union_list.py +36 -0
- testgres/postgres_configuration/core/option/handlers/prepare_get_value/option_handler_to_prepare_get_value__std__bool.py +31 -0
- testgres/postgres_configuration/core/option/handlers/prepare_get_value/option_handler_to_prepare_get_value__std__generic.py +41 -0
- testgres/postgres_configuration/core/option/handlers/prepare_get_value/option_handler_to_prepare_get_value__std__int.py +31 -0
- testgres/postgres_configuration/core/option/handlers/prepare_get_value/option_handler_to_prepare_get_value__std__str.py +31 -0
- testgres/postgres_configuration/core/option/handlers/prepare_get_value/option_handler_to_prepare_get_value__std__unique_str_list.py +46 -0
- testgres/postgres_configuration/core/option/handlers/prepare_set_value/option_handler_to_prepare_set_value__std__bool.py +115 -0
- testgres/postgres_configuration/core/option/handlers/prepare_set_value/option_handler_to_prepare_set_value__std__generic.py +41 -0
- testgres/postgres_configuration/core/option/handlers/prepare_set_value/option_handler_to_prepare_set_value__std__int.py +44 -0
- testgres/postgres_configuration/core/option/handlers/prepare_set_value/option_handler_to_prepare_set_value__std__str.py +37 -0
- testgres/postgres_configuration/core/option/handlers/prepare_set_value/option_handler_to_prepare_set_value__std__unique_str_list.py +63 -0
- testgres/postgres_configuration/core/option/handlers/prepare_set_value_item/option_handler_to_prepare_set_value_item__std__str.py +37 -0
- testgres/postgres_configuration/core/option/handlers/set_value/option_handler_to_set_value__std__simple.py +38 -0
- testgres/postgres_configuration/core/option/handlers/set_value_item/option_handler_to_set_value_item__std__unique.py +38 -0
- testgres/postgres_configuration/core/option/handlers/write/option_handler_to_write__std__bool.py +42 -0
- testgres/postgres_configuration/core/option/handlers/write/option_handler_to_write__std__generic.py +51 -0
- testgres/postgres_configuration/core/option/handlers/write/option_handler_to_write__std__int.py +27 -0
- testgres/postgres_configuration/core/option/handlers/write/option_handler_to_write__std__str.py +36 -0
- testgres/postgres_configuration/core/option/handlers/write/option_handler_to_write__std__unique_str_list.py +37 -0
- testgres/postgres_configuration/core/raise_error.py +365 -0
- testgres/postgres_configuration/core/read_utils.py +308 -0
- testgres/postgres_configuration/core/write_utils.py +112 -0
- testgres/postgres_configuration/implementation/v00/configuration_base.py +4408 -0
- testgres/postgres_configuration/implementation/v00/configuration_std.py +538 -0
- testgres/postgres_configuration/os/abstract/configuration_os_ops.py +98 -0
- testgres/postgres_configuration/os/local/configuration_os_ops.py +154 -0
- testgres_postgres_configuration-0.1.0.dist-info/METADATA +25 -0
- testgres_postgres_configuration-0.1.0.dist-info/RECORD +40 -0
- testgres_postgres_configuration-0.1.0.dist-info/WHEEL +5 -0
- testgres_postgres_configuration-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,4408 @@
|
|
|
1
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
# Postgres Pro. PostgreSQL Configuration Python Library.
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
# fmt: off
|
|
7
|
+
from ...abstract.v00.configuration import PostgresConfiguration
|
|
8
|
+
from ...abstract.v00.configuration import PostgresConfigurationObject
|
|
9
|
+
from ...abstract.v00.configuration import PostgresConfigurationComment
|
|
10
|
+
from ...abstract.v00.configuration import PostgresConfigurationOption
|
|
11
|
+
from ...abstract.v00.configuration import PostgresConfigurationOptions
|
|
12
|
+
from ...abstract.v00.configuration import PostgresConfigurationOptionsIterator
|
|
13
|
+
from ...abstract.v00.configuration import PostgresConfigurationInclude
|
|
14
|
+
from ...abstract.v00.configuration import PostgresConfigurationFileLine
|
|
15
|
+
from ...abstract.v00.configuration import PostgresConfigurationFileLines
|
|
16
|
+
from ...abstract.v00.configuration import PostgresConfigurationFileLinesIterator
|
|
17
|
+
from ...abstract.v00.configuration import PostgresConfigurationFile
|
|
18
|
+
from ...abstract.v00.configuration import PostgresConfigurationFiles
|
|
19
|
+
from ...abstract.v00.configuration import PostgresConfigurationFilesIterator
|
|
20
|
+
from ...abstract.v00.configuration import PostgresConfigurationSetOptionValueEventID
|
|
21
|
+
from ...abstract.v00.configuration import PostgresConfigurationSetOptionValueResult
|
|
22
|
+
|
|
23
|
+
from ...core.model import ConfigurationData as PgCfgModel__ConfigurationData
|
|
24
|
+
from ...core.model import ObjectData as PgCfgModel__ObjectData
|
|
25
|
+
from ...core.model import FileLineElementData as PgCfgModel__FileLineElementData
|
|
26
|
+
from ...core.model import CommentData as PgCfgModel__CommentData
|
|
27
|
+
from ...core.model import OptionData as PgCfgModel__OptionData
|
|
28
|
+
from ...core.model import IncludeData as PgCfgModel__IncludeData
|
|
29
|
+
from ...core.model import FileLineData as PgCfgModel__FileLineData
|
|
30
|
+
from ...core.model import FileData as PgCfgModel__FileData
|
|
31
|
+
from ...core.model import FileStatus as PgCfgModel__FileStatus
|
|
32
|
+
|
|
33
|
+
from ...core.handlers import OptionHandlerToPrepareSetValue as PgCfgModel__OptionHandlerToPrepareSetValue
|
|
34
|
+
from ...core.handlers import OptionHandlerCtxToPrepareSetValue as PgCfgModel__OptionHandlerCtxPrepareToSetValue
|
|
35
|
+
from ...core.handlers import OptionHandlerToPrepareGetValue as PgCfgModel__OptionHandlerToPrepareGetValue
|
|
36
|
+
from ...core.handlers import OptionHandlerCtxToPrepareGetValue as PgCfgModel__OptionHandlerCtxPrepareToGetValue
|
|
37
|
+
from ...core.handlers import OptionHandlerToPrepareSetValueItem as PgCfgModel__OptionHandlerToPrepareSetValueItem
|
|
38
|
+
from ...core.handlers import OptionHandlerCtxToPrepareSetValueItem as PgCfgModel__OptionHandlerCtxPrepareToSetValueItem
|
|
39
|
+
from ...core.handlers import OptionHandlerToSetValue as PgCfgModel__OptionHandlerToSetValue
|
|
40
|
+
from ...core.handlers import OptionHandlerCtxToSetValue as PgCfgModel__OptionHandlerCtxToSetValue
|
|
41
|
+
from ...core.handlers import OptionHandlerToGetValue as PgCfgModel__OptionHandlerToGetValue
|
|
42
|
+
from ...core.handlers import OptionHandlerCtxToGetValue as PgCfgModel__OptionHandlerCtxToGetValue
|
|
43
|
+
from ...core.handlers import OptionHandlerToAddOption as PgCfgModel__OptionHandlerToAddOption
|
|
44
|
+
from ...core.handlers import OptionHandlerCtxToAddOption as PgCfgModel__OptionHandlerCtxToAddOption
|
|
45
|
+
from ...core.handlers import OptionHandlerToSetValueItem as PgCfgModel__OptionHandlerToSetValueItem
|
|
46
|
+
from ...core.handlers import OptionHandlerCtxToSetValueItem as PgCfgModel__OptionHandlerCtxToSetValueItem
|
|
47
|
+
from ...core.handlers import OptionHandlerToWrite as PgCfgModel__OptionHandlerToWrite
|
|
48
|
+
from ...core.handlers import OptionHandlerCtxToWrite as PgCfgModel__OptionHandlerCtxToWrite
|
|
49
|
+
from ...core.handlers import ConfigurationDataHandler as PgCfgModel__DataHandler
|
|
50
|
+
|
|
51
|
+
from ...core.controller_utils import DataControllerUtils as PgCfgModel__DataControllerUtils
|
|
52
|
+
from ...core.data_verificator import DataVerificator
|
|
53
|
+
from ...core.helpers import Helpers
|
|
54
|
+
from ...core.write_utils import WriteUtils
|
|
55
|
+
from ...core.read_utils import ReadUtils
|
|
56
|
+
from ...core.read_utils import LineReader as ReadUtils__LineReader
|
|
57
|
+
from ...core.raise_error import RaiseError
|
|
58
|
+
from ...core.bugcheck_error import BugCheckError
|
|
59
|
+
# fmt: on
|
|
60
|
+
|
|
61
|
+
from ...os.abstract.configuration_os_ops import ConfigurationFileReader
|
|
62
|
+
from ...os.abstract.configuration_os_ops import ConfigurationOsFile
|
|
63
|
+
from ...os.abstract.configuration_os_ops import ConfigurationOsOps
|
|
64
|
+
|
|
65
|
+
import typing
|
|
66
|
+
import datetime
|
|
67
|
+
|
|
68
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
69
|
+
# class PostgresConfigurationComment_Base
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class PostgresConfigurationComment_Base(PostgresConfigurationComment):
|
|
73
|
+
m_FileLine: PostgresConfigurationFileLine_Base
|
|
74
|
+
m_CommentData: PgCfgModel__CommentData
|
|
75
|
+
|
|
76
|
+
# --------------------------------------------------------------------
|
|
77
|
+
def __init__(
|
|
78
|
+
self,
|
|
79
|
+
fileLine: PostgresConfigurationFileLine_Base,
|
|
80
|
+
commentData: PgCfgModel__CommentData,
|
|
81
|
+
):
|
|
82
|
+
assert fileLine is not None
|
|
83
|
+
assert commentData is not None
|
|
84
|
+
assert type(fileLine) == PostgresConfigurationFileLine_Base
|
|
85
|
+
assert type(commentData) == PgCfgModel__CommentData
|
|
86
|
+
|
|
87
|
+
assert commentData.m_Parent is fileLine.m_FileLineData
|
|
88
|
+
|
|
89
|
+
super().__init__()
|
|
90
|
+
|
|
91
|
+
self.m_FileLine = fileLine
|
|
92
|
+
self.m_CommentData = commentData
|
|
93
|
+
|
|
94
|
+
# Object interface ---------------------------------------------------
|
|
95
|
+
def get_Configuration(self) -> PostgresConfiguration_Base:
|
|
96
|
+
self.Helper__CheckAlive()
|
|
97
|
+
return self.m_FileLine.get_Configuration()
|
|
98
|
+
|
|
99
|
+
# --------------------------------------------------------------------
|
|
100
|
+
def get_Parent(self) -> PostgresConfigurationFileLine_Base:
|
|
101
|
+
self.Helper__CheckAlive()
|
|
102
|
+
return self.m_FileLine
|
|
103
|
+
|
|
104
|
+
# Comment interface --------------------------------------------------
|
|
105
|
+
def get_Text(self) -> str:
|
|
106
|
+
self.Helper__CheckAlive()
|
|
107
|
+
assert type(self.m_CommentData) == PgCfgModel__CommentData
|
|
108
|
+
assert type(self.m_CommentData.m_Text) == str
|
|
109
|
+
return self.m_CommentData.m_Text
|
|
110
|
+
|
|
111
|
+
# --------------------------------------------------------------------
|
|
112
|
+
def Delete(self, withLineIfLast: bool):
|
|
113
|
+
assert type(withLineIfLast) == bool
|
|
114
|
+
|
|
115
|
+
self.Helper__CheckAlive()
|
|
116
|
+
assert type(self.m_CommentData) == PgCfgModel__CommentData
|
|
117
|
+
assert type(self.m_CommentData.m_Parent) == PgCfgModel__FileLineData
|
|
118
|
+
assert type(self.m_CommentData.m_Parent.m_Parent) == PgCfgModel__FileData
|
|
119
|
+
assert (
|
|
120
|
+
type(self.m_CommentData.m_Parent.m_Parent.m_Parent)
|
|
121
|
+
== PgCfgModel__ConfigurationData
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
cfgData = self.m_CommentData.m_Parent.m_Parent.m_Parent
|
|
125
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
126
|
+
|
|
127
|
+
PgCfgModel__DataControllerUtils.Comment__delete(
|
|
128
|
+
cfgData, self.m_CommentData, withLineIfLast
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
# Helper interface ---------------------------------------------------
|
|
132
|
+
def Helper__CheckAlive(self):
|
|
133
|
+
assert self.m_CommentData is not None
|
|
134
|
+
assert type(self.m_CommentData) == PgCfgModel__CommentData
|
|
135
|
+
|
|
136
|
+
if not self.m_CommentData.IsAlive():
|
|
137
|
+
RaiseError.CommentObjectWasDeleted()
|
|
138
|
+
|
|
139
|
+
assert type(self.m_FileLine) == PostgresConfigurationFileLine_Base
|
|
140
|
+
assert isinstance(self.m_FileLine, PostgresConfigurationFileLine)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
144
|
+
# class PostgresConfigurationOption_Base
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
class PostgresConfigurationOption_Base(PostgresConfigurationOption):
|
|
148
|
+
m_FileLine: PostgresConfigurationFileLine_Base
|
|
149
|
+
m_OptionData: PgCfgModel__OptionData
|
|
150
|
+
|
|
151
|
+
# --------------------------------------------------------------------
|
|
152
|
+
def __init__(
|
|
153
|
+
self,
|
|
154
|
+
fileLine: PostgresConfigurationFileLine_Base,
|
|
155
|
+
optionData: PgCfgModel__OptionData,
|
|
156
|
+
):
|
|
157
|
+
assert type(fileLine) == PostgresConfigurationFileLine_Base
|
|
158
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
159
|
+
|
|
160
|
+
super().__init__()
|
|
161
|
+
|
|
162
|
+
self.m_FileLine = fileLine
|
|
163
|
+
self.m_OptionData = optionData
|
|
164
|
+
|
|
165
|
+
# Object interface ---------------------------------------------------
|
|
166
|
+
def get_Configuration(self) -> PostgresConfiguration_Base:
|
|
167
|
+
self.Helper__CheckAlive()
|
|
168
|
+
return self.m_FileLine.get_Configuration()
|
|
169
|
+
|
|
170
|
+
# --------------------------------------------------------------------
|
|
171
|
+
def get_Parent(self) -> PostgresConfigurationFileLine_Base:
|
|
172
|
+
self.Helper__CheckAlive()
|
|
173
|
+
return self.m_FileLine
|
|
174
|
+
|
|
175
|
+
# Option interface ---------------------------------------------------
|
|
176
|
+
def get_Name(self) -> str:
|
|
177
|
+
self.Helper__CheckAlive()
|
|
178
|
+
return self.m_OptionData.m_Name
|
|
179
|
+
|
|
180
|
+
# --------------------------------------------------------------------
|
|
181
|
+
def get_Value(self) -> any:
|
|
182
|
+
self.Helper__CheckAlive()
|
|
183
|
+
|
|
184
|
+
configuration = self.m_FileLine.get_Configuration()
|
|
185
|
+
|
|
186
|
+
assert configuration is not None
|
|
187
|
+
assert isinstance(configuration, PostgresConfiguration_Base)
|
|
188
|
+
assert isinstance(configuration, PgCfgModel__DataHandler)
|
|
189
|
+
|
|
190
|
+
r = PostgresConfigurationController__Base.GetOptionValue(
|
|
191
|
+
configuration, self.m_OptionData, self.m_OptionData.m_Name
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
return r
|
|
195
|
+
|
|
196
|
+
# --------------------------------------------------------------------
|
|
197
|
+
def set_Value(self, value: any) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
198
|
+
self.Helper__CheckAlive()
|
|
199
|
+
|
|
200
|
+
configuration = self.m_FileLine.get_Configuration()
|
|
201
|
+
|
|
202
|
+
assert configuration is not None
|
|
203
|
+
assert isinstance(configuration, PostgresConfiguration_Base)
|
|
204
|
+
assert isinstance(configuration, PgCfgModel__DataHandler)
|
|
205
|
+
|
|
206
|
+
r = PostgresConfigurationController__Base.SetOptionValue(
|
|
207
|
+
configuration,
|
|
208
|
+
self.m_OptionData, # target
|
|
209
|
+
self.m_OptionData.m_Name,
|
|
210
|
+
value,
|
|
211
|
+
None, # offset
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
assert type(r) == PostgresConfigurationSetOptionValueResult_Base
|
|
215
|
+
|
|
216
|
+
assert r.m_OptData is None or r.m_OptData is self.m_OptionData
|
|
217
|
+
assert r.m_Opt is None
|
|
218
|
+
|
|
219
|
+
if r.m_OptData is not None:
|
|
220
|
+
r.m_Opt = self # Optimization
|
|
221
|
+
|
|
222
|
+
return r
|
|
223
|
+
|
|
224
|
+
# --------------------------------------------------------------------
|
|
225
|
+
def set_ValueItem(
|
|
226
|
+
self, value_item: any
|
|
227
|
+
) -> PostgresConfigurationSetOptionValueResult:
|
|
228
|
+
self.Helper__CheckAlive()
|
|
229
|
+
|
|
230
|
+
configuration = self.m_FileLine.get_Configuration()
|
|
231
|
+
|
|
232
|
+
assert configuration is not None
|
|
233
|
+
assert isinstance(configuration, PostgresConfiguration_Base)
|
|
234
|
+
assert isinstance(configuration, PgCfgModel__DataHandler)
|
|
235
|
+
|
|
236
|
+
r = PostgresConfigurationController__Base.SetOptionValueItem(
|
|
237
|
+
configuration,
|
|
238
|
+
self.m_OptionData, # target
|
|
239
|
+
self.m_OptionData.m_Name,
|
|
240
|
+
value_item,
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
assert type(r) == PostgresConfigurationSetOptionValueResult_Base
|
|
244
|
+
|
|
245
|
+
assert r.m_OptData is not None
|
|
246
|
+
assert r.m_OptData is self.m_OptionData
|
|
247
|
+
assert r.m_Opt is None
|
|
248
|
+
|
|
249
|
+
if r.m_OptData is not None:
|
|
250
|
+
r.m_Opt = self # Optimization
|
|
251
|
+
|
|
252
|
+
return r
|
|
253
|
+
|
|
254
|
+
# Helper methods -----------------------------------------------------
|
|
255
|
+
def Helper__CheckAlive(self):
|
|
256
|
+
assert self.m_OptionData is not None
|
|
257
|
+
assert type(self.m_OptionData) == PgCfgModel__OptionData
|
|
258
|
+
|
|
259
|
+
if not self.m_OptionData.IsAlive():
|
|
260
|
+
RaiseError.OptionObjectWasDeleted()
|
|
261
|
+
|
|
262
|
+
assert type(self.m_FileLine) == PostgresConfigurationFileLine_Base
|
|
263
|
+
assert isinstance(self.m_FileLine, PostgresConfigurationFileLine)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
267
|
+
# class PostgresConfigurationInclude_Base
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
class PostgresConfigurationInclude_Base(PostgresConfigurationInclude):
|
|
271
|
+
m_FileLine: PostgresConfigurationFileLine_Base
|
|
272
|
+
m_IncludeData: PgCfgModel__IncludeData
|
|
273
|
+
|
|
274
|
+
# --------------------------------------------------------------------
|
|
275
|
+
def __init__(
|
|
276
|
+
self,
|
|
277
|
+
fileLine: PostgresConfigurationFileLine_Base,
|
|
278
|
+
includeData: PgCfgModel__IncludeData,
|
|
279
|
+
):
|
|
280
|
+
assert type(fileLine) == PostgresConfigurationFileLine_Base
|
|
281
|
+
assert type(includeData) == PgCfgModel__IncludeData
|
|
282
|
+
|
|
283
|
+
super().__init__()
|
|
284
|
+
|
|
285
|
+
self.m_FileLine = fileLine
|
|
286
|
+
self.m_IncludeData = includeData
|
|
287
|
+
|
|
288
|
+
# Object interface ---------------------------------------------------
|
|
289
|
+
def get_Configuration(self) -> PostgresConfiguration_Base:
|
|
290
|
+
self.Helper__CheckAlive()
|
|
291
|
+
return self.m_FileLine.get_Configuration()
|
|
292
|
+
|
|
293
|
+
# --------------------------------------------------------------------
|
|
294
|
+
def get_Parent(self) -> PostgresConfigurationFileLine_Base:
|
|
295
|
+
self.Helper__CheckAlive()
|
|
296
|
+
return self.m_FileLine
|
|
297
|
+
|
|
298
|
+
# Include interface --------------------------------------------------
|
|
299
|
+
def get_File(self) -> PostgresConfigurationIncludedFile_Base:
|
|
300
|
+
self.Helper__CheckAlive()
|
|
301
|
+
|
|
302
|
+
return PostgresConfigurationIncludedFile_Base(self, self.m_IncludeData.m_File)
|
|
303
|
+
|
|
304
|
+
# --------------------------------------------------------------------
|
|
305
|
+
def Delete(self, withLine: bool):
|
|
306
|
+
assert type(withLine) == bool
|
|
307
|
+
|
|
308
|
+
self.Helper__CheckAlive()
|
|
309
|
+
assert type(self.m_IncludeData) == PgCfgModel__IncludeData
|
|
310
|
+
assert type(self.m_IncludeData.m_Parent) == PgCfgModel__FileLineData
|
|
311
|
+
assert type(self.m_IncludeData.m_Parent.m_Parent) == PgCfgModel__FileData
|
|
312
|
+
assert (
|
|
313
|
+
type(self.m_IncludeData.m_Parent.m_Parent.m_Parent)
|
|
314
|
+
== PgCfgModel__ConfigurationData
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
cfgData = self.m_IncludeData.m_Parent.m_Parent.m_Parent
|
|
318
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
319
|
+
|
|
320
|
+
PgCfgModel__DataControllerUtils.Include__delete(
|
|
321
|
+
cfgData, self.m_IncludeData, withLine
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
# Private interface --------------------------------------------------
|
|
325
|
+
def Private__CheckAlive(self):
|
|
326
|
+
self.Helper__CheckAlive()
|
|
327
|
+
|
|
328
|
+
# Helper methods -----------------------------------------------------
|
|
329
|
+
def Helper__CheckAlive(self):
|
|
330
|
+
assert self.m_IncludeData is not None
|
|
331
|
+
assert type(self.m_IncludeData) == PgCfgModel__IncludeData
|
|
332
|
+
|
|
333
|
+
if not self.m_IncludeData.IsAlive():
|
|
334
|
+
RaiseError.IncludeObjectWasDeleted()
|
|
335
|
+
|
|
336
|
+
assert type(self.m_FileLine) == PostgresConfigurationFileLine_Base
|
|
337
|
+
assert isinstance(self.m_FileLine, PostgresConfigurationFileLine)
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
341
|
+
# class PostgresConfigurationFileLine_Base
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
class PostgresConfigurationFileLine_Base(PostgresConfigurationFileLine):
|
|
345
|
+
m_Parent: PostgresConfigurationFile_Base
|
|
346
|
+
m_FileLineData: PgCfgModel__FileLineData
|
|
347
|
+
|
|
348
|
+
# --------------------------------------------------------------------
|
|
349
|
+
def __init__(
|
|
350
|
+
self,
|
|
351
|
+
parent: PostgresConfigurationFile_Base,
|
|
352
|
+
fileLineData: PgCfgModel__FileLineData,
|
|
353
|
+
):
|
|
354
|
+
assert parent is not None
|
|
355
|
+
assert isinstance(parent, PostgresConfigurationFile_Base)
|
|
356
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
357
|
+
|
|
358
|
+
super().__init__()
|
|
359
|
+
|
|
360
|
+
self.m_Parent = parent
|
|
361
|
+
self.m_FileLineData = fileLineData
|
|
362
|
+
|
|
363
|
+
# Object interface ---------------------------------------------------
|
|
364
|
+
def get_Configuration(self) -> PostgresConfiguration_Base:
|
|
365
|
+
self.Helper__CheckAlive()
|
|
366
|
+
assert self.m_Parent is not None
|
|
367
|
+
assert isinstance(self.m_Parent, PostgresConfigurationFile_Base)
|
|
368
|
+
return self.m_Parent.get_Configuration()
|
|
369
|
+
|
|
370
|
+
# --------------------------------------------------------------------
|
|
371
|
+
def get_Parent(self) -> PostgresConfigurationFile_Base:
|
|
372
|
+
self.Helper__CheckAlive()
|
|
373
|
+
assert self.m_Parent is not None
|
|
374
|
+
assert isinstance(self.m_Parent, PostgresConfigurationFile_Base)
|
|
375
|
+
return self.m_Parent
|
|
376
|
+
|
|
377
|
+
# FileLine interface -------------------------------------------------
|
|
378
|
+
def __len__(self) -> int:
|
|
379
|
+
self.Helper__CheckAlive()
|
|
380
|
+
assert type(self.m_FileLineData) == PgCfgModel__FileLineData
|
|
381
|
+
assert type(self.m_FileLineData.m_Items) == list
|
|
382
|
+
return len(self.m_FileLineData.m_Items)
|
|
383
|
+
|
|
384
|
+
# --------------------------------------------------------------------
|
|
385
|
+
def AddComment(
|
|
386
|
+
self, text: str, offset: typing.Optional[int] = None
|
|
387
|
+
) -> PostgresConfigurationComment_Base:
|
|
388
|
+
assert type(text) == str
|
|
389
|
+
assert offset is None or type(offset) == int
|
|
390
|
+
|
|
391
|
+
self.Helper__CheckAlive()
|
|
392
|
+
|
|
393
|
+
DataVerificator.CheckCommentText(text)
|
|
394
|
+
|
|
395
|
+
commentData = PgCfgModel__DataControllerUtils.FileLine__add_Comment(
|
|
396
|
+
self.m_FileLineData, offset, text
|
|
397
|
+
)
|
|
398
|
+
assert commentData is not None
|
|
399
|
+
assert type(commentData) == PgCfgModel__CommentData
|
|
400
|
+
assert commentData.m_Parent is self.m_FileLineData
|
|
401
|
+
assert type(commentData.m_Parent) == PgCfgModel__FileLineData
|
|
402
|
+
assert type(commentData.m_Parent.m_Items) == list
|
|
403
|
+
assert len(commentData.m_Parent.m_Items) > 0
|
|
404
|
+
assert commentData.m_Parent.m_Items[-1].m_Element is commentData
|
|
405
|
+
|
|
406
|
+
try:
|
|
407
|
+
fileLineComment = PostgresConfigurationComment_Base(self, commentData)
|
|
408
|
+
|
|
409
|
+
assert fileLineComment is not None
|
|
410
|
+
assert type(fileLineComment) == PostgresConfigurationComment_Base
|
|
411
|
+
except: # rollback
|
|
412
|
+
cfg = self.m_Parent.get_Configuration()
|
|
413
|
+
assert cfg is not None
|
|
414
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
415
|
+
assert cfg.m_Data is not None
|
|
416
|
+
assert type(cfg.m_Data) == PgCfgModel__ConfigurationData
|
|
417
|
+
|
|
418
|
+
PgCfgModel__DataControllerUtils.Comment__delete(
|
|
419
|
+
cfg.m_Data, commentData, False
|
|
420
|
+
)
|
|
421
|
+
raise
|
|
422
|
+
|
|
423
|
+
assert fileLineComment
|
|
424
|
+
assert type(fileLineComment) == PostgresConfigurationComment_Base
|
|
425
|
+
return fileLineComment
|
|
426
|
+
|
|
427
|
+
# --------------------------------------------------------------------
|
|
428
|
+
def AddOption(
|
|
429
|
+
self, name: str, value: any, offset: typing.Optional[int]
|
|
430
|
+
) -> PostgresConfigurationOption_Base:
|
|
431
|
+
DataVerificator.CheckOptionName(name)
|
|
432
|
+
|
|
433
|
+
assert name is not None
|
|
434
|
+
assert name != ""
|
|
435
|
+
|
|
436
|
+
if value is None:
|
|
437
|
+
RaiseError.NoneValueIsNotSupported()
|
|
438
|
+
|
|
439
|
+
assert value is not None
|
|
440
|
+
|
|
441
|
+
self.Helper__CheckAlive()
|
|
442
|
+
assert isinstance(self.m_Parent, PostgresConfigurationFile_Base)
|
|
443
|
+
|
|
444
|
+
cfg = self.m_Parent.m_Cfg
|
|
445
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
446
|
+
|
|
447
|
+
option = PostgresConfigurationController__Base.AddOption(
|
|
448
|
+
cfg, self.m_FileLineData, name, value, offset
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
assert option is not None
|
|
452
|
+
assert type(option) == PostgresConfigurationOption_Base
|
|
453
|
+
return option
|
|
454
|
+
|
|
455
|
+
# --------------------------------------------------------------------
|
|
456
|
+
def AddInclude(
|
|
457
|
+
self, path: str, offset: typing.Optional[int]
|
|
458
|
+
) -> PostgresConfigurationInclude_Base:
|
|
459
|
+
DataVerificator.CheckStringOfFilePath(path)
|
|
460
|
+
|
|
461
|
+
assert type(path) == str
|
|
462
|
+
assert path != ""
|
|
463
|
+
|
|
464
|
+
self.Helper__CheckAlive()
|
|
465
|
+
|
|
466
|
+
assert isinstance(self.m_Parent, PostgresConfigurationFile_Base)
|
|
467
|
+
|
|
468
|
+
cfg = self.m_Parent.m_Cfg
|
|
469
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
470
|
+
assert type(cfg.m_Data) == PgCfgModel__ConfigurationData
|
|
471
|
+
|
|
472
|
+
# Add/Get file
|
|
473
|
+
# Add include element
|
|
474
|
+
|
|
475
|
+
baseFolder = cfg.m_Data.OsOps.Path_DirName(self.m_FileLineData.m_Parent.m_Path)
|
|
476
|
+
assert type(baseFolder) == str
|
|
477
|
+
|
|
478
|
+
fileData = PgCfgModel__DataControllerUtils.Cfg__GetOrCreateFile__USER(
|
|
479
|
+
cfg.m_Data, baseFolder, path
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
assert fileData is not None
|
|
483
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
484
|
+
|
|
485
|
+
try:
|
|
486
|
+
includeData = PgCfgModel__DataControllerUtils.FileLine__add_Include(
|
|
487
|
+
self.m_FileLineData, path, fileData, offset
|
|
488
|
+
)
|
|
489
|
+
assert includeData is not None
|
|
490
|
+
assert type(includeData) == PgCfgModel__IncludeData
|
|
491
|
+
assert includeData.m_Path == path
|
|
492
|
+
assert includeData.m_File is fileData
|
|
493
|
+
assert includeData.m_Parent == self.m_FileLineData
|
|
494
|
+
|
|
495
|
+
try:
|
|
496
|
+
# -----------
|
|
497
|
+
include = PostgresConfigurationInclude_Base(self, includeData)
|
|
498
|
+
assert include.m_FileLine is self
|
|
499
|
+
assert include.m_IncludeData is includeData
|
|
500
|
+
except: # rollback an include
|
|
501
|
+
PgCfgModel__DataControllerUtils.Include__delete(
|
|
502
|
+
cfg.m_Data, includeData, False
|
|
503
|
+
)
|
|
504
|
+
raise
|
|
505
|
+
except: # TODO: rollback a file
|
|
506
|
+
raise
|
|
507
|
+
|
|
508
|
+
return include
|
|
509
|
+
|
|
510
|
+
# --------------------------------------------------------------------
|
|
511
|
+
def Clear(self) -> None:
|
|
512
|
+
self.Helper__CheckAlive()
|
|
513
|
+
assert type(self.m_FileLineData) == PgCfgModel__FileLineData
|
|
514
|
+
|
|
515
|
+
cfg = self.m_Parent.get_Configuration()
|
|
516
|
+
assert cfg is not None
|
|
517
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
518
|
+
assert cfg.m_Data is not None
|
|
519
|
+
assert type(cfg.m_Data) == PgCfgModel__ConfigurationData
|
|
520
|
+
|
|
521
|
+
PgCfgModel__DataControllerUtils.FileLine__clear(cfg.m_Data, self.m_FileLineData)
|
|
522
|
+
|
|
523
|
+
# Helper methods -----------------------------------------------------
|
|
524
|
+
def Helper__CheckAlive(self):
|
|
525
|
+
assert self.m_FileLineData is not None
|
|
526
|
+
assert type(self.m_FileLineData) == PgCfgModel__FileLineData
|
|
527
|
+
|
|
528
|
+
if not self.m_FileLineData.IsAlive():
|
|
529
|
+
RaiseError.FileLineObjectWasDeleted()
|
|
530
|
+
|
|
531
|
+
assert isinstance(self.m_Parent, PostgresConfigurationFile_Base)
|
|
532
|
+
assert isinstance(self.m_Parent, PostgresConfigurationFile)
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
536
|
+
# class PostgresConfigurationFileLinesIterator_Base
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
class PostgresConfigurationFileLinesIterator_Base(
|
|
540
|
+
PostgresConfigurationFileLinesIterator
|
|
541
|
+
):
|
|
542
|
+
m_Cfg: PostgresConfiguration_Base
|
|
543
|
+
m_FileLineDataIterator: typing.Iterator[PgCfgModel__FileLineData]
|
|
544
|
+
|
|
545
|
+
def __init__(
|
|
546
|
+
self,
|
|
547
|
+
cfg: PostgresConfiguration_Base,
|
|
548
|
+
fileLineDataIterator: typing.Iterator[PgCfgModel__FileLineData],
|
|
549
|
+
):
|
|
550
|
+
assert cfg is not None
|
|
551
|
+
assert fileLineDataIterator is not None
|
|
552
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
553
|
+
assert isinstance(fileLineDataIterator, typing.Iterator)
|
|
554
|
+
|
|
555
|
+
self.m_Cfg = cfg
|
|
556
|
+
self.m_FileLineDataIterator = fileLineDataIterator
|
|
557
|
+
|
|
558
|
+
# interface ----------------------------------------------------------
|
|
559
|
+
def __iter__(self) -> PostgresConfigurationFileLinesIterator_Base:
|
|
560
|
+
assert self.m_Cfg is not None
|
|
561
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
562
|
+
assert self.m_FileLineDataIterator is not None
|
|
563
|
+
assert isinstance(self.m_FileLineDataIterator, typing.Iterator)
|
|
564
|
+
|
|
565
|
+
it = self.m_FileLineDataIterator.__iter__()
|
|
566
|
+
assert it is not None
|
|
567
|
+
assert isinstance(it, typing.Iterator)
|
|
568
|
+
|
|
569
|
+
if it is self.m_FileLineDataIterator:
|
|
570
|
+
return self
|
|
571
|
+
|
|
572
|
+
return __class__(self.m_Cfg, it)
|
|
573
|
+
|
|
574
|
+
# --------------------------------------------------------------------
|
|
575
|
+
def __next__(self) -> PostgresConfigurationFileLine_Base:
|
|
576
|
+
assert self.m_Cfg is not None
|
|
577
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
578
|
+
assert self.m_FileLineDataIterator is not None
|
|
579
|
+
assert isinstance(self.m_FileLineDataIterator, typing.Iterator)
|
|
580
|
+
|
|
581
|
+
fileLineData = self.m_FileLineDataIterator.__next__()
|
|
582
|
+
assert fileLineData is not None
|
|
583
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
584
|
+
|
|
585
|
+
file = PostgresConfigurationFactory_Base.GetObject(self.m_Cfg, fileLineData)
|
|
586
|
+
assert file is not None
|
|
587
|
+
assert isinstance(file, PostgresConfigurationFileLine_Base)
|
|
588
|
+
|
|
589
|
+
return file
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
593
|
+
# class PostgresConfigurationFileLines_Base
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
class PostgresConfigurationFileLines_Base(PostgresConfigurationFileLines):
|
|
597
|
+
m_Cfg: PostgresConfiguration_Base
|
|
598
|
+
m_File: PostgresConfigurationFile_Base
|
|
599
|
+
|
|
600
|
+
# --------------------------------------------------------------------
|
|
601
|
+
def __init__(
|
|
602
|
+
self, cfg: PostgresConfiguration_Base, file: PostgresConfigurationFile_Base
|
|
603
|
+
):
|
|
604
|
+
assert cfg is not None
|
|
605
|
+
assert file is not None
|
|
606
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
607
|
+
assert isinstance(file, PostgresConfigurationFile_Base)
|
|
608
|
+
|
|
609
|
+
self.m_Cfg = cfg
|
|
610
|
+
self.m_File = file
|
|
611
|
+
|
|
612
|
+
# interface ----------------------------------------------------------
|
|
613
|
+
def __len__(self) -> int:
|
|
614
|
+
assert self.m_File is not None
|
|
615
|
+
assert isinstance(self.m_File, PostgresConfigurationFile_Base)
|
|
616
|
+
|
|
617
|
+
fileData = self.m_File.Private__GetFileData()
|
|
618
|
+
assert fileData is not None
|
|
619
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
620
|
+
assert fileData.m_Lines is not None
|
|
621
|
+
assert type(fileData.m_Lines) == list
|
|
622
|
+
|
|
623
|
+
return len(fileData.m_Lines)
|
|
624
|
+
|
|
625
|
+
# --------------------------------------------------------------------
|
|
626
|
+
def __iter__(self) -> PostgresConfigurationFileLinesIterator_Base:
|
|
627
|
+
assert self.m_Cfg is not None
|
|
628
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
629
|
+
assert self.m_File is not None
|
|
630
|
+
assert isinstance(self.m_File, PostgresConfigurationFile_Base)
|
|
631
|
+
|
|
632
|
+
fileData = self.m_File.Private__GetFileData()
|
|
633
|
+
assert fileData is not None
|
|
634
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
635
|
+
assert fileData.m_Lines is not None
|
|
636
|
+
assert type(fileData.m_Lines) == list
|
|
637
|
+
|
|
638
|
+
fileLineDataIterator = fileData.m_Lines.__iter__()
|
|
639
|
+
assert fileLineDataIterator is not None
|
|
640
|
+
assert isinstance(fileLineDataIterator, typing.Iterator)
|
|
641
|
+
|
|
642
|
+
return PostgresConfigurationFileLinesIterator_Base(
|
|
643
|
+
self.m_Cfg, fileLineDataIterator
|
|
644
|
+
)
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
648
|
+
# class PostgresConfigurationFile_Base
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
class PostgresConfigurationFile_Base(PostgresConfigurationFile):
|
|
652
|
+
m_Cfg: PostgresConfiguration_Base
|
|
653
|
+
m_FileData: PgCfgModel__FileData
|
|
654
|
+
|
|
655
|
+
m_Lines: PostgresConfigurationFileLines_Base
|
|
656
|
+
|
|
657
|
+
# --------------------------------------------------------------------
|
|
658
|
+
def __init__(self, cfg: PostgresConfiguration_Base, fileData: PgCfgModel__FileData):
|
|
659
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
660
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
661
|
+
|
|
662
|
+
super().__init__()
|
|
663
|
+
|
|
664
|
+
self.m_Cfg = cfg
|
|
665
|
+
self.m_FileData = fileData
|
|
666
|
+
self.m_Lines = None
|
|
667
|
+
|
|
668
|
+
# Object interface ---------------------------------------------------
|
|
669
|
+
def get_Configuration(self) -> PostgresConfiguration_Base:
|
|
670
|
+
self.Internal__CheckAlive()
|
|
671
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
672
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration)
|
|
673
|
+
return self.m_Cfg
|
|
674
|
+
|
|
675
|
+
# File interface -----------------------------------------------------
|
|
676
|
+
def __len__(self) -> int:
|
|
677
|
+
self.Internal__CheckAlive()
|
|
678
|
+
assert type(self.m_FileData) == PgCfgModel__FileData
|
|
679
|
+
assert type(self.m_FileData.m_Lines) == list
|
|
680
|
+
return len(self.m_FileData.m_Lines)
|
|
681
|
+
|
|
682
|
+
# --------------------------------------------------------------------
|
|
683
|
+
def get_Path(self) -> str:
|
|
684
|
+
self.Internal__CheckAlive()
|
|
685
|
+
assert type(self.m_FileData) == PgCfgModel__FileData
|
|
686
|
+
assert type(self.m_FileData.m_Path) == str
|
|
687
|
+
return self.m_FileData.m_Path
|
|
688
|
+
|
|
689
|
+
# --------------------------------------------------------------------
|
|
690
|
+
def get_Lines(self) -> PostgresConfigurationFileLines_Base:
|
|
691
|
+
self.Internal__CheckAlive()
|
|
692
|
+
|
|
693
|
+
if self.m_Lines is None:
|
|
694
|
+
self.m_Lines = PostgresConfigurationFileLines_Base(self.m_Cfg, self)
|
|
695
|
+
|
|
696
|
+
assert self.m_Lines is not None
|
|
697
|
+
assert type(self.m_Lines) == PostgresConfigurationFileLines_Base
|
|
698
|
+
assert self.m_Lines.m_Cfg is self.m_Cfg
|
|
699
|
+
assert self.m_FileData is self.m_FileData
|
|
700
|
+
|
|
701
|
+
return self.m_Lines
|
|
702
|
+
|
|
703
|
+
# interface ----------------------------------------------------------
|
|
704
|
+
def AddEmptyLine(self) -> PostgresConfigurationFileLine_Base:
|
|
705
|
+
self.Internal__CheckAlive()
|
|
706
|
+
|
|
707
|
+
fileLineData = PgCfgModel__DataControllerUtils.File__add_Line(self.m_FileData)
|
|
708
|
+
|
|
709
|
+
assert fileLineData is not None
|
|
710
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
711
|
+
assert fileLineData.IsAlive()
|
|
712
|
+
assert fileLineData.m_Items is not None
|
|
713
|
+
assert type(fileLineData.m_Items) == list
|
|
714
|
+
assert len(fileLineData.m_Items) == 0
|
|
715
|
+
|
|
716
|
+
assert self.m_FileData is not None
|
|
717
|
+
assert type(self.m_FileData) == PgCfgModel__FileData
|
|
718
|
+
assert self.m_FileData.m_Lines is not None
|
|
719
|
+
assert type(self.m_FileData.m_Lines) == list
|
|
720
|
+
assert len(self.m_FileData.m_Lines) > 0
|
|
721
|
+
assert self.m_FileData.m_Lines[-1] is fileLineData
|
|
722
|
+
|
|
723
|
+
try:
|
|
724
|
+
fileLine = PostgresConfigurationFileLine_Base(self, fileLineData)
|
|
725
|
+
|
|
726
|
+
assert fileLine is not None
|
|
727
|
+
assert type(fileLine) == PostgresConfigurationFileLine_Base
|
|
728
|
+
assert fileLine.m_FileLineData is fileLineData
|
|
729
|
+
assert fileLine.m_Parent is self
|
|
730
|
+
except: # rollback
|
|
731
|
+
PgCfgModel__DataControllerUtils.FileLine__delete(
|
|
732
|
+
self.m_Cfg.m_Data, fileLineData
|
|
733
|
+
)
|
|
734
|
+
raise
|
|
735
|
+
|
|
736
|
+
assert fileLine is not None
|
|
737
|
+
assert type(fileLine) == PostgresConfigurationFileLine_Base
|
|
738
|
+
return fileLine
|
|
739
|
+
|
|
740
|
+
# --------------------------------------------------------------------
|
|
741
|
+
def AddComment(self, text: str) -> PostgresConfigurationComment_Base:
|
|
742
|
+
assert type(text) == str
|
|
743
|
+
|
|
744
|
+
self.Internal__CheckAlive()
|
|
745
|
+
|
|
746
|
+
DataVerificator.CheckCommentText(text)
|
|
747
|
+
|
|
748
|
+
fileLineData = PgCfgModel__DataControllerUtils.File__add_Line(self.m_FileData)
|
|
749
|
+
|
|
750
|
+
assert self.m_FileData is not None
|
|
751
|
+
assert type(self.m_FileData) == PgCfgModel__FileData
|
|
752
|
+
assert self.m_FileData.m_Lines is not None
|
|
753
|
+
assert type(self.m_FileData.m_Lines) == list
|
|
754
|
+
assert len(self.m_FileData.m_Lines) > 0
|
|
755
|
+
assert self.m_FileData.m_Lines[-1] is fileLineData
|
|
756
|
+
|
|
757
|
+
try:
|
|
758
|
+
commentData = PgCfgModel__DataControllerUtils.FileLine__add_Comment(
|
|
759
|
+
fileLineData, None, text
|
|
760
|
+
)
|
|
761
|
+
assert commentData is not None
|
|
762
|
+
assert type(commentData) == PgCfgModel__CommentData
|
|
763
|
+
assert commentData.m_Parent is fileLineData
|
|
764
|
+
assert type(commentData.m_Parent) == PgCfgModel__FileLineData
|
|
765
|
+
assert type(commentData.m_Parent.m_Items) == list
|
|
766
|
+
assert len(commentData.m_Parent.m_Items) == 1
|
|
767
|
+
assert commentData.m_Parent.m_Items[0].m_Element is commentData
|
|
768
|
+
|
|
769
|
+
# -----------------------
|
|
770
|
+
fileLine = PostgresConfigurationFileLine_Base(self, fileLineData)
|
|
771
|
+
|
|
772
|
+
assert fileLine is not None
|
|
773
|
+
assert type(fileLine) == PostgresConfigurationFileLine_Base
|
|
774
|
+
assert fileLine.m_FileLineData is fileLineData
|
|
775
|
+
assert fileLine.m_Parent is self
|
|
776
|
+
|
|
777
|
+
fileLineComment = PostgresConfigurationComment_Base(fileLine, commentData)
|
|
778
|
+
|
|
779
|
+
assert fileLineComment is not None
|
|
780
|
+
assert type(fileLineComment) == PostgresConfigurationComment_Base
|
|
781
|
+
except: # rollback
|
|
782
|
+
PgCfgModel__DataControllerUtils.FileLine__delete(
|
|
783
|
+
self.m_Cfg.m_Data, fileLineData
|
|
784
|
+
)
|
|
785
|
+
raise
|
|
786
|
+
|
|
787
|
+
assert fileLineComment
|
|
788
|
+
assert type(fileLineComment) == PostgresConfigurationComment_Base
|
|
789
|
+
return fileLineComment
|
|
790
|
+
|
|
791
|
+
# --------------------------------------------------------------------
|
|
792
|
+
def AddOption(self, name: str, value: any) -> PostgresConfigurationOption_Base:
|
|
793
|
+
DataVerificator.CheckOptionName(name)
|
|
794
|
+
|
|
795
|
+
assert name is not None
|
|
796
|
+
assert name != ""
|
|
797
|
+
|
|
798
|
+
if value is None:
|
|
799
|
+
RaiseError.NoneValueIsNotSupported()
|
|
800
|
+
|
|
801
|
+
assert value is not None
|
|
802
|
+
|
|
803
|
+
self.Internal__CheckAlive()
|
|
804
|
+
|
|
805
|
+
assert self.m_Cfg is not None
|
|
806
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
807
|
+
|
|
808
|
+
option = PostgresConfigurationController__Base.AddOption(
|
|
809
|
+
self.m_Cfg, self.m_FileData, name, value, None
|
|
810
|
+
)
|
|
811
|
+
|
|
812
|
+
assert option is not None
|
|
813
|
+
assert type(option) == PostgresConfigurationOption_Base
|
|
814
|
+
return option
|
|
815
|
+
|
|
816
|
+
# --------------------------------------------------------------------
|
|
817
|
+
def AddInclude(self, path: str) -> PostgresConfigurationInclude_Base:
|
|
818
|
+
DataVerificator.CheckStringOfFilePath(path)
|
|
819
|
+
|
|
820
|
+
assert type(path) == str
|
|
821
|
+
assert path != ""
|
|
822
|
+
|
|
823
|
+
self.Internal__CheckAlive()
|
|
824
|
+
|
|
825
|
+
assert self.m_Cfg is not None
|
|
826
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
827
|
+
assert type(self.m_Cfg.m_Data) == PgCfgModel__ConfigurationData
|
|
828
|
+
|
|
829
|
+
# Add/Get file
|
|
830
|
+
# Add empty line
|
|
831
|
+
# Add include element
|
|
832
|
+
|
|
833
|
+
baseFolder = self.m_Cfg.m_Data.OsOps.Path_DirName(self.m_FileData.m_Path)
|
|
834
|
+
assert type(baseFolder) == str
|
|
835
|
+
|
|
836
|
+
fileData = PgCfgModel__DataControllerUtils.Cfg__GetOrCreateFile__USER(
|
|
837
|
+
self.m_Cfg.m_Data, baseFolder, path
|
|
838
|
+
)
|
|
839
|
+
|
|
840
|
+
assert fileData is not None
|
|
841
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
842
|
+
|
|
843
|
+
try:
|
|
844
|
+
fileLineData = PgCfgModel__DataControllerUtils.File__add_Line(
|
|
845
|
+
self.m_FileData
|
|
846
|
+
)
|
|
847
|
+
|
|
848
|
+
assert self.m_FileData is not None
|
|
849
|
+
assert type(self.m_FileData) == PgCfgModel__FileData
|
|
850
|
+
assert self.m_FileData.m_Lines is not None
|
|
851
|
+
assert type(self.m_FileData.m_Lines) == list
|
|
852
|
+
assert len(self.m_FileData.m_Lines) > 0
|
|
853
|
+
assert self.m_FileData.m_Lines[-1] is fileLineData
|
|
854
|
+
|
|
855
|
+
try:
|
|
856
|
+
includeData = PgCfgModel__DataControllerUtils.FileLine__add_Include(
|
|
857
|
+
fileLineData, path, fileData, None
|
|
858
|
+
)
|
|
859
|
+
assert includeData is not None
|
|
860
|
+
assert type(includeData) == PgCfgModel__IncludeData
|
|
861
|
+
assert includeData.m_Path == path
|
|
862
|
+
assert includeData.m_File is fileData
|
|
863
|
+
assert includeData.m_Parent == fileLineData
|
|
864
|
+
|
|
865
|
+
# -----------
|
|
866
|
+
fileLine = PostgresConfigurationFileLine_Base(self, fileLineData)
|
|
867
|
+
assert fileLine is not None
|
|
868
|
+
assert type(fileLine) == PostgresConfigurationFileLine_Base
|
|
869
|
+
assert fileLine.m_FileLineData is fileLineData
|
|
870
|
+
assert fileLine.m_Parent is self
|
|
871
|
+
|
|
872
|
+
# -----------
|
|
873
|
+
include = PostgresConfigurationInclude_Base(fileLine, includeData)
|
|
874
|
+
assert include.m_FileLine is fileLine
|
|
875
|
+
assert include.m_IncludeData is includeData
|
|
876
|
+
except: # rollback a line
|
|
877
|
+
PgCfgModel__DataControllerUtils.FileLine__delete(
|
|
878
|
+
self.m_Cfg.m_Data, fileLineData
|
|
879
|
+
)
|
|
880
|
+
raise
|
|
881
|
+
except: # TODO: rollback a file
|
|
882
|
+
raise
|
|
883
|
+
|
|
884
|
+
return include
|
|
885
|
+
|
|
886
|
+
# --------------------------------------------------------------------
|
|
887
|
+
#
|
|
888
|
+
# Method for inserting, updating and deleting of an option.
|
|
889
|
+
#
|
|
890
|
+
# It finds a suitable file or uses/creates default file (auto.conf).
|
|
891
|
+
#
|
|
892
|
+
# Set of None will delete an option from all files.
|
|
893
|
+
#
|
|
894
|
+
# Return:
|
|
895
|
+
# PostgresConfigurationSetOptionValueResult_Base.
|
|
896
|
+
#
|
|
897
|
+
def SetOptionValue(
|
|
898
|
+
self, name: str, value: any
|
|
899
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
900
|
+
self.Internal__CheckAlive()
|
|
901
|
+
|
|
902
|
+
DataVerificator.CheckOptionName(name)
|
|
903
|
+
|
|
904
|
+
result = PostgresConfigurationController__Base.SetOptionValue(
|
|
905
|
+
self.m_Cfg,
|
|
906
|
+
self.m_FileData, # target
|
|
907
|
+
name,
|
|
908
|
+
value,
|
|
909
|
+
None, # offset
|
|
910
|
+
)
|
|
911
|
+
|
|
912
|
+
assert result is not None
|
|
913
|
+
assert type(result) == PostgresConfigurationSetOptionValueResult_Base
|
|
914
|
+
assert isinstance(result, PostgresConfigurationSetOptionValueResult)
|
|
915
|
+
return result
|
|
916
|
+
|
|
917
|
+
# --------------------------------------------------------------------
|
|
918
|
+
#
|
|
919
|
+
# Method for getting a value of option.
|
|
920
|
+
#
|
|
921
|
+
# Return:
|
|
922
|
+
# - Value of option.
|
|
923
|
+
# - None if option is not found in this file.
|
|
924
|
+
#
|
|
925
|
+
def GetOptionValue(self, name: str) -> any:
|
|
926
|
+
self.Internal__CheckAlive()
|
|
927
|
+
|
|
928
|
+
DataVerificator.CheckOptionName(name)
|
|
929
|
+
|
|
930
|
+
r = PostgresConfigurationController__Base.GetOptionValue(
|
|
931
|
+
self.m_Cfg, self.m_FileData, name
|
|
932
|
+
)
|
|
933
|
+
|
|
934
|
+
return r
|
|
935
|
+
|
|
936
|
+
# --------------------------------------------------------------------
|
|
937
|
+
def SetOptionValueItem(
|
|
938
|
+
self, name: str, value_item: any
|
|
939
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
940
|
+
self.Internal__CheckAlive()
|
|
941
|
+
|
|
942
|
+
DataVerificator.CheckOptionName(name)
|
|
943
|
+
|
|
944
|
+
result = PostgresConfigurationController__Base.SetOptionValueItem(
|
|
945
|
+
self.m_Cfg, self.m_FileData, name, value_item # target
|
|
946
|
+
)
|
|
947
|
+
|
|
948
|
+
assert result is not None
|
|
949
|
+
assert type(result) == PostgresConfigurationSetOptionValueResult_Base
|
|
950
|
+
assert isinstance(result, PostgresConfigurationSetOptionValueResult)
|
|
951
|
+
assert result.m_Cfg is self.m_Cfg
|
|
952
|
+
assert result.m_OptData is not None
|
|
953
|
+
assert type(result.m_OptData) == PgCfgModel__OptionData
|
|
954
|
+
assert result.m_OptData.m_Name == name
|
|
955
|
+
return result
|
|
956
|
+
|
|
957
|
+
# PostgresConfigurationFile_Base private interface -------------------
|
|
958
|
+
def Private__GetFileData(self) -> PgCfgModel__FileData:
|
|
959
|
+
self.Internal__CheckAlive()
|
|
960
|
+
return self.m_FileData
|
|
961
|
+
|
|
962
|
+
# Internal interface -------------------------------------------------
|
|
963
|
+
def Internal__CheckAlive(self):
|
|
964
|
+
RaiseError.MethodIsNotImplemented(__class__, "Internal__CheckAlive")
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
968
|
+
# class PostgresConfigurationTopLevelFile_Base
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
class PostgresConfigurationTopLevelFile_Base(PostgresConfigurationFile_Base):
|
|
972
|
+
def __init__(self, cfg: PostgresConfiguration_Base, fileData: PgCfgModel__FileData):
|
|
973
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
974
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
975
|
+
|
|
976
|
+
super().__init__(cfg, fileData)
|
|
977
|
+
|
|
978
|
+
# Object interface ---------------------------------------------------
|
|
979
|
+
def get_Parent(self) -> PostgresConfiguration_Base:
|
|
980
|
+
self.Internal__CheckAlive()
|
|
981
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
982
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration)
|
|
983
|
+
return self.m_Cfg
|
|
984
|
+
|
|
985
|
+
# Internal interface -------------------------------------------------
|
|
986
|
+
def Internal__CheckAlive(self):
|
|
987
|
+
assert self.m_FileData is not None
|
|
988
|
+
assert type(self.m_FileData) == PgCfgModel__FileData
|
|
989
|
+
|
|
990
|
+
if not self.m_FileData.IsAlive():
|
|
991
|
+
RaiseError.FileObjectWasDeleted()
|
|
992
|
+
|
|
993
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
994
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration)
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
998
|
+
# class PostgresConfigurationIncludedFile_Base
|
|
999
|
+
|
|
1000
|
+
|
|
1001
|
+
class PostgresConfigurationIncludedFile_Base(PostgresConfigurationFile_Base):
|
|
1002
|
+
m_Include: PostgresConfigurationInclude_Base
|
|
1003
|
+
|
|
1004
|
+
# --------------------------------------------------------------------
|
|
1005
|
+
def __init__(
|
|
1006
|
+
self, include: PostgresConfigurationInclude_Base, fileData: PgCfgModel__FileData
|
|
1007
|
+
):
|
|
1008
|
+
assert type(include) == PostgresConfigurationInclude_Base
|
|
1009
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
1010
|
+
|
|
1011
|
+
super().__init__(include.get_Configuration(), fileData)
|
|
1012
|
+
|
|
1013
|
+
self.m_Include = include
|
|
1014
|
+
|
|
1015
|
+
# Object interface ---------------------------------------------------
|
|
1016
|
+
def get_Parent(self) -> PostgresConfigurationInclude_Base:
|
|
1017
|
+
self.Internal__CheckAlive()
|
|
1018
|
+
assert isinstance(self.m_Include, PostgresConfigurationInclude_Base)
|
|
1019
|
+
assert isinstance(self.m_Include, PostgresConfigurationInclude)
|
|
1020
|
+
return self.m_Include
|
|
1021
|
+
|
|
1022
|
+
# Internal interface -------------------------------------------------
|
|
1023
|
+
def Internal__CheckAlive(self):
|
|
1024
|
+
assert self.m_FileData is not None
|
|
1025
|
+
assert self.m_Include is not None
|
|
1026
|
+
assert type(self.m_FileData) == PgCfgModel__FileData
|
|
1027
|
+
assert type(self.m_Include) == PostgresConfigurationInclude_Base
|
|
1028
|
+
|
|
1029
|
+
if not self.m_FileData.IsAlive():
|
|
1030
|
+
RaiseError.FileObjectWasDeleted()
|
|
1031
|
+
|
|
1032
|
+
self.m_Include.Private__CheckAlive()
|
|
1033
|
+
|
|
1034
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
1035
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration)
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
1039
|
+
# class PostgresConfigurationSetOptionValueResult_Base
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
class PostgresConfigurationSetOptionValueResult_Base(
|
|
1043
|
+
PostgresConfigurationSetOptionValueResult
|
|
1044
|
+
):
|
|
1045
|
+
m_Cfg: PostgresConfiguration_Base
|
|
1046
|
+
m_Opt: PostgresConfigurationOption_Base
|
|
1047
|
+
m_OptData: PgCfgModel__OptionData
|
|
1048
|
+
m_EventID: PostgresConfigurationSetOptionValueEventID
|
|
1049
|
+
|
|
1050
|
+
# --------------------------------------------------------------------
|
|
1051
|
+
def __init__(
|
|
1052
|
+
self,
|
|
1053
|
+
cfg: PostgresConfiguration_Base,
|
|
1054
|
+
optData: PgCfgModel__OptionData,
|
|
1055
|
+
eventID: PostgresConfigurationSetOptionValueEventID,
|
|
1056
|
+
):
|
|
1057
|
+
assert cfg is None or isinstance(cfg, PostgresConfiguration_Base)
|
|
1058
|
+
assert optData is None or type(optData) == PgCfgModel__OptionData
|
|
1059
|
+
assert (cfg is None) == (optData is None)
|
|
1060
|
+
assert type(eventID) == PostgresConfigurationSetOptionValueEventID
|
|
1061
|
+
|
|
1062
|
+
self.m_Cfg = cfg
|
|
1063
|
+
self.m_Opt = None
|
|
1064
|
+
self.m_OptData = optData
|
|
1065
|
+
self.m_EventID = eventID
|
|
1066
|
+
|
|
1067
|
+
# ---------------------------------------------------------------------
|
|
1068
|
+
def Create__OptWasUpdated(
|
|
1069
|
+
cfg: PostgresConfiguration_Base, optData: PgCfgModel__OptionData
|
|
1070
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
1071
|
+
assert cfg is not None
|
|
1072
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
1073
|
+
assert type(optData) == PgCfgModel__OptionData
|
|
1074
|
+
|
|
1075
|
+
return __class__(
|
|
1076
|
+
cfg, optData, PostgresConfigurationSetOptionValueEventID.OPTION_WAS_UPDATED
|
|
1077
|
+
)
|
|
1078
|
+
|
|
1079
|
+
# ---------------------------------------------------------------------
|
|
1080
|
+
def Create__OptWasAdded(
|
|
1081
|
+
cfg: PostgresConfiguration_Base, optData: PgCfgModel__OptionData
|
|
1082
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
1083
|
+
assert cfg is not None
|
|
1084
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
1085
|
+
assert type(optData) == PgCfgModel__OptionData
|
|
1086
|
+
|
|
1087
|
+
return __class__(
|
|
1088
|
+
cfg, optData, PostgresConfigurationSetOptionValueEventID.OPTION_WAS_ADDED
|
|
1089
|
+
)
|
|
1090
|
+
|
|
1091
|
+
# ---------------------------------------------------------------------
|
|
1092
|
+
def Create__OptWasDeleted() -> PostgresConfigurationSetOptionValueResult_Base:
|
|
1093
|
+
return __class__(
|
|
1094
|
+
None, None, PostgresConfigurationSetOptionValueEventID.OPTION_WAS_DELETED
|
|
1095
|
+
)
|
|
1096
|
+
|
|
1097
|
+
# ---------------------------------------------------------------------
|
|
1098
|
+
def Create__OptValueItemWasAlreadyDefined(
|
|
1099
|
+
cfg: PostgresConfiguration_Base, optData: PgCfgModel__OptionData
|
|
1100
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
1101
|
+
assert cfg is not None
|
|
1102
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
1103
|
+
assert type(optData) == PgCfgModel__OptionData
|
|
1104
|
+
|
|
1105
|
+
return __class__(
|
|
1106
|
+
cfg,
|
|
1107
|
+
optData,
|
|
1108
|
+
PostgresConfigurationSetOptionValueEventID.VALUE_ITEM_WAS_ALREADY_DEFINED,
|
|
1109
|
+
)
|
|
1110
|
+
|
|
1111
|
+
# ---------------------------------------------------------------------
|
|
1112
|
+
def Create__OptValueItemWasAdded(
|
|
1113
|
+
cfg: PostgresConfiguration_Base, optData: PgCfgModel__OptionData
|
|
1114
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
1115
|
+
assert cfg is not None
|
|
1116
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
1117
|
+
assert type(optData) == PgCfgModel__OptionData
|
|
1118
|
+
|
|
1119
|
+
return __class__(
|
|
1120
|
+
cfg,
|
|
1121
|
+
optData,
|
|
1122
|
+
PostgresConfigurationSetOptionValueEventID.VALUE_ITEM_WAS_ADDED,
|
|
1123
|
+
)
|
|
1124
|
+
|
|
1125
|
+
# ---------------------------------------------------------------------
|
|
1126
|
+
@property
|
|
1127
|
+
def Option(self) -> PostgresConfigurationOption_Base:
|
|
1128
|
+
assert self.m_Cfg is None or isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
1129
|
+
assert self.m_OptData is None or type(self.m_OptData) == PgCfgModel__OptionData
|
|
1130
|
+
assert (self.m_Cfg is None) == (self.m_OptData is None)
|
|
1131
|
+
assert type(self.m_EventID) == PostgresConfigurationSetOptionValueEventID
|
|
1132
|
+
|
|
1133
|
+
if self.m_OptData is None:
|
|
1134
|
+
assert (
|
|
1135
|
+
self.m_EventID
|
|
1136
|
+
== PostgresConfigurationSetOptionValueEventID.OPTION_WAS_DELETED
|
|
1137
|
+
or self.m_EventID == PostgresConfigurationSetOptionValueEventID.NONE
|
|
1138
|
+
)
|
|
1139
|
+
|
|
1140
|
+
assert self.m_Opt is None
|
|
1141
|
+
return None
|
|
1142
|
+
|
|
1143
|
+
assert (
|
|
1144
|
+
self.m_EventID
|
|
1145
|
+
== PostgresConfigurationSetOptionValueEventID.OPTION_WAS_ADDED
|
|
1146
|
+
or self.m_EventID
|
|
1147
|
+
== PostgresConfigurationSetOptionValueEventID.OPTION_WAS_UPDATED
|
|
1148
|
+
or self.m_EventID
|
|
1149
|
+
== PostgresConfigurationSetOptionValueEventID.VALUE_ITEM_WAS_ADDED
|
|
1150
|
+
or self.m_EventID
|
|
1151
|
+
== PostgresConfigurationSetOptionValueEventID.VALUE_ITEM_WAS_ALREADY_DEFINED
|
|
1152
|
+
)
|
|
1153
|
+
|
|
1154
|
+
if self.m_Opt is None:
|
|
1155
|
+
self.m_Opt = PostgresConfigurationFactory_Base.GetObject(
|
|
1156
|
+
self.m_Cfg, self.m_OptData
|
|
1157
|
+
)
|
|
1158
|
+
|
|
1159
|
+
assert self.m_Opt is not None
|
|
1160
|
+
assert type(self.m_Opt) == PostgresConfigurationOption_Base
|
|
1161
|
+
return self.m_Opt
|
|
1162
|
+
|
|
1163
|
+
# ---------------------------------------------------------------------
|
|
1164
|
+
@property
|
|
1165
|
+
def EventID(self) -> PostgresConfigurationSetOptionValueEventID:
|
|
1166
|
+
assert type(self.m_EventID) == PostgresConfigurationSetOptionValueEventID
|
|
1167
|
+
return self.m_EventID
|
|
1168
|
+
|
|
1169
|
+
|
|
1170
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
1171
|
+
# class PostgresConfiguration_Base__AllFilesIterator
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
class PostgresConfiguration_Base__AllFilesIterator(PostgresConfigurationFilesIterator):
|
|
1175
|
+
m_Cfg: PostgresConfiguration_Base
|
|
1176
|
+
m_FileDataIterator: typing.Iterator[PgCfgModel__FileData]
|
|
1177
|
+
|
|
1178
|
+
# --------------------------------------------------------------------
|
|
1179
|
+
def __init__(
|
|
1180
|
+
self,
|
|
1181
|
+
cfg: PostgresConfiguration_Base,
|
|
1182
|
+
fileDataIterator: typing.Iterator[PgCfgModel__FileData],
|
|
1183
|
+
):
|
|
1184
|
+
assert cfg is not None
|
|
1185
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
1186
|
+
assert fileDataIterator is not None
|
|
1187
|
+
assert isinstance(fileDataIterator, typing.Iterator)
|
|
1188
|
+
|
|
1189
|
+
self.m_Cfg = cfg
|
|
1190
|
+
self.m_FileDataIterator = fileDataIterator
|
|
1191
|
+
|
|
1192
|
+
# interface ----------------------------------------------------------
|
|
1193
|
+
def __iter__(self) -> PostgresConfiguration_Base__AllFilesIterator:
|
|
1194
|
+
assert self.m_Cfg is not None
|
|
1195
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
1196
|
+
assert self.m_FileDataIterator is not None
|
|
1197
|
+
assert isinstance(self.m_FileDataIterator, typing.Iterator)
|
|
1198
|
+
|
|
1199
|
+
it = self.m_FileDataIterator.__iter__()
|
|
1200
|
+
assert it is not None
|
|
1201
|
+
assert isinstance(it, typing.Iterator)
|
|
1202
|
+
|
|
1203
|
+
if it is self.m_FileDataIterator:
|
|
1204
|
+
return self
|
|
1205
|
+
|
|
1206
|
+
return __class__(self.m_Cfg, it)
|
|
1207
|
+
|
|
1208
|
+
# --------------------------------------------------------------------
|
|
1209
|
+
def __next__(self) -> PostgresConfigurationFile_Base:
|
|
1210
|
+
assert self.m_Cfg is not None
|
|
1211
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
1212
|
+
assert self.m_FileDataIterator is not None
|
|
1213
|
+
assert isinstance(self.m_FileDataIterator, typing.Iterator)
|
|
1214
|
+
|
|
1215
|
+
fileData = self.m_FileDataIterator.__next__()
|
|
1216
|
+
assert fileData is not None
|
|
1217
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
1218
|
+
|
|
1219
|
+
file = PostgresConfigurationFactory_Base.GetObject(self.m_Cfg, fileData)
|
|
1220
|
+
assert file is not None
|
|
1221
|
+
assert isinstance(file, PostgresConfigurationFile_Base)
|
|
1222
|
+
|
|
1223
|
+
return file
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
1227
|
+
# class PostgresConfiguration_Base__AllFiles
|
|
1228
|
+
|
|
1229
|
+
|
|
1230
|
+
class PostgresConfiguration_Base__AllFiles(PostgresConfigurationFiles):
|
|
1231
|
+
m_Cfg: PostgresConfiguration_Base
|
|
1232
|
+
|
|
1233
|
+
# --------------------------------------------------------------------
|
|
1234
|
+
def __init__(self, cfg: PostgresConfiguration_Base):
|
|
1235
|
+
assert cfg is not None
|
|
1236
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
1237
|
+
self.m_Cfg = cfg
|
|
1238
|
+
|
|
1239
|
+
# PostgresConfigurationFiles interface -------------------------------
|
|
1240
|
+
def __len__(self) -> int:
|
|
1241
|
+
assert self.m_Cfg is not None
|
|
1242
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
1243
|
+
assert type(self.m_Cfg.m_Data) == PgCfgModel__ConfigurationData
|
|
1244
|
+
assert type(self.m_Cfg.m_Data.m_AllFilesByName) == dict
|
|
1245
|
+
return len(self.m_Cfg.m_Data.m_AllFilesByName.values())
|
|
1246
|
+
|
|
1247
|
+
# --------------------------------------------------------------------
|
|
1248
|
+
def __iter__(self) -> PostgresConfiguration_Base__AllFilesIterator:
|
|
1249
|
+
assert self.m_Cfg is not None
|
|
1250
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
1251
|
+
assert type(self.m_Cfg.m_Data) == PgCfgModel__ConfigurationData
|
|
1252
|
+
assert type(self.m_Cfg.m_Data.m_AllFilesByName) == dict
|
|
1253
|
+
|
|
1254
|
+
fileDataIterator = self.m_Cfg.m_Data.m_AllFilesByName.values().__iter__()
|
|
1255
|
+
assert fileDataIterator is not None
|
|
1256
|
+
assert isinstance(fileDataIterator, typing.Iterator)
|
|
1257
|
+
|
|
1258
|
+
return PostgresConfiguration_Base__AllFilesIterator(
|
|
1259
|
+
self.m_Cfg, fileDataIterator
|
|
1260
|
+
)
|
|
1261
|
+
|
|
1262
|
+
# --------------------------------------------------------------------
|
|
1263
|
+
def GetFileByName(self, file_name: str) -> PostgresConfigurationFile_Base:
|
|
1264
|
+
assert self.m_Cfg is not None
|
|
1265
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
1266
|
+
assert type(self.m_Cfg.m_Data) == PgCfgModel__ConfigurationData
|
|
1267
|
+
assert type(self.m_Cfg.m_Data.m_AllFilesByName) == dict
|
|
1268
|
+
|
|
1269
|
+
file_name2 = self.m_Cfg.m_Data.OsOps.Path_NormCase(file_name)
|
|
1270
|
+
|
|
1271
|
+
if not (file_name2 in self.m_Cfg.m_Data.m_AllFilesByName.keys()):
|
|
1272
|
+
RaiseError.UnknownFileName(file_name)
|
|
1273
|
+
|
|
1274
|
+
indexData = self.m_Cfg.m_Data.m_AllFilesByName[file_name2]
|
|
1275
|
+
|
|
1276
|
+
assert indexData is not None
|
|
1277
|
+
|
|
1278
|
+
typeOfIndexData = type(indexData)
|
|
1279
|
+
|
|
1280
|
+
if typeOfIndexData == PgCfgModel__FileData:
|
|
1281
|
+
assert self.m_Cfg.m_Data.OsOps.Path_BaseName(indexData.m_Path) == file_name2
|
|
1282
|
+
file = PostgresConfigurationFactory_Base.GetObject(self.m_Cfg, indexData)
|
|
1283
|
+
assert file is not None
|
|
1284
|
+
assert isinstance(file, PostgresConfigurationFile_Base)
|
|
1285
|
+
return file
|
|
1286
|
+
|
|
1287
|
+
if typeOfIndexData == list:
|
|
1288
|
+
assert len(typeOfIndexData) > 1
|
|
1289
|
+
RaiseError.MultipleDefOfFileIsFound(file_name, len(indexData))
|
|
1290
|
+
|
|
1291
|
+
BugCheckError.UnkFileObjectDataType(file_name, typeOfIndexData)
|
|
1292
|
+
|
|
1293
|
+
|
|
1294
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
1295
|
+
# class PostgresConfiguration_Base__AllOptionsIterator
|
|
1296
|
+
|
|
1297
|
+
|
|
1298
|
+
class PostgresConfiguration_Base__AllOptionsIterator(
|
|
1299
|
+
PostgresConfigurationOptionsIterator
|
|
1300
|
+
):
|
|
1301
|
+
m_Cfg: PostgresConfiguration_Base
|
|
1302
|
+
m_OptionDataIterator: typing.Iterator[PgCfgModel__OptionData]
|
|
1303
|
+
|
|
1304
|
+
# --------------------------------------------------------------------
|
|
1305
|
+
def __init__(
|
|
1306
|
+
self,
|
|
1307
|
+
cfg: PostgresConfiguration_Base,
|
|
1308
|
+
optionDataIterator: typing.Iterator[PgCfgModel__OptionData],
|
|
1309
|
+
):
|
|
1310
|
+
assert cfg is not None
|
|
1311
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
1312
|
+
assert optionDataIterator is not None
|
|
1313
|
+
assert isinstance(optionDataIterator, typing.Iterator)
|
|
1314
|
+
|
|
1315
|
+
self.m_Cfg = cfg
|
|
1316
|
+
self.m_OptionDataIterator = optionDataIterator
|
|
1317
|
+
|
|
1318
|
+
# interface ----------------------------------------------------------
|
|
1319
|
+
def __iter__(self) -> PostgresConfiguration_Base__AllOptionsIterator:
|
|
1320
|
+
assert self.m_Cfg is not None
|
|
1321
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
1322
|
+
assert self.m_OptionDataIterator is not None
|
|
1323
|
+
assert isinstance(self.m_OptionDataIterator, typing.Iterator)
|
|
1324
|
+
|
|
1325
|
+
it = self.m_OptionDataIterator.__iter__()
|
|
1326
|
+
assert it is not None
|
|
1327
|
+
assert isinstance(it, typing.Iterator)
|
|
1328
|
+
|
|
1329
|
+
if it is self.m_OptionDataIterator:
|
|
1330
|
+
return self
|
|
1331
|
+
|
|
1332
|
+
return __class__(self.m_Cfg, it)
|
|
1333
|
+
|
|
1334
|
+
# --------------------------------------------------------------------
|
|
1335
|
+
def __next__(self) -> PostgresConfigurationFile_Base:
|
|
1336
|
+
assert self.m_Cfg is not None
|
|
1337
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
1338
|
+
assert self.m_OptionDataIterator is not None
|
|
1339
|
+
assert isinstance(self.m_OptionDataIterator, typing.Iterator)
|
|
1340
|
+
|
|
1341
|
+
optionData = self.m_OptionDataIterator.__next__()
|
|
1342
|
+
assert optionData is not None
|
|
1343
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
1344
|
+
|
|
1345
|
+
option = PostgresConfigurationFactory_Base.GetObject(self.m_Cfg, optionData)
|
|
1346
|
+
assert option is not None
|
|
1347
|
+
assert isinstance(option, PostgresConfigurationOption_Base)
|
|
1348
|
+
|
|
1349
|
+
return option
|
|
1350
|
+
|
|
1351
|
+
|
|
1352
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
1353
|
+
# class PostgresConfiguration_Base__AllOptions
|
|
1354
|
+
|
|
1355
|
+
|
|
1356
|
+
class PostgresConfiguration_Base__AllOptions(PostgresConfigurationOptions):
|
|
1357
|
+
m_Cfg: PostgresConfiguration_Base
|
|
1358
|
+
|
|
1359
|
+
# --------------------------------------------------------------------
|
|
1360
|
+
def __init__(self, cfg: PostgresConfiguration_Base):
|
|
1361
|
+
assert cfg is not None
|
|
1362
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
1363
|
+
self.m_Cfg = cfg
|
|
1364
|
+
|
|
1365
|
+
# PostgresConfigurationOptions interface -----------------------------
|
|
1366
|
+
def __len__(self) -> int:
|
|
1367
|
+
assert self.m_Cfg is not None
|
|
1368
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
1369
|
+
assert type(self.m_Cfg.m_Data) == PgCfgModel__ConfigurationData
|
|
1370
|
+
assert type(self.m_Cfg.m_Data.m_AllOptionsByName) == dict
|
|
1371
|
+
return len(self.m_Cfg.m_Data.m_AllOptionsByName.values())
|
|
1372
|
+
|
|
1373
|
+
# --------------------------------------------------------------------
|
|
1374
|
+
def __iter__(self) -> PostgresConfiguration_Base__AllFilesIterator:
|
|
1375
|
+
assert self.m_Cfg is not None
|
|
1376
|
+
assert isinstance(self.m_Cfg, PostgresConfiguration_Base)
|
|
1377
|
+
assert type(self.m_Cfg.m_Data) == PgCfgModel__ConfigurationData
|
|
1378
|
+
assert type(self.m_Cfg.m_Data.m_AllOptionsByName) == dict
|
|
1379
|
+
|
|
1380
|
+
optionDataIterator = self.m_Cfg.m_Data.m_AllOptionsByName.values().__iter__()
|
|
1381
|
+
assert optionDataIterator is not None
|
|
1382
|
+
assert isinstance(optionDataIterator, typing.Iterator)
|
|
1383
|
+
|
|
1384
|
+
return PostgresConfiguration_Base__AllOptionsIterator(
|
|
1385
|
+
self.m_Cfg, optionDataIterator
|
|
1386
|
+
)
|
|
1387
|
+
|
|
1388
|
+
|
|
1389
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
1390
|
+
# class PostgresConfiguration_Base
|
|
1391
|
+
|
|
1392
|
+
|
|
1393
|
+
class PostgresConfiguration_Base(PostgresConfiguration, PgCfgModel__DataHandler):
|
|
1394
|
+
m_Data: PgCfgModel__ConfigurationData
|
|
1395
|
+
|
|
1396
|
+
m_AllFiles: PostgresConfiguration_Base__AllFiles
|
|
1397
|
+
m_AllOptions: PostgresConfiguration_Base__AllOptions
|
|
1398
|
+
|
|
1399
|
+
# --------------------------------------------------------------------
|
|
1400
|
+
def __init__(self, data_dir: str, osOps: ConfigurationOsOps):
|
|
1401
|
+
assert type(data_dir) == str # noqa: E721
|
|
1402
|
+
assert isinstance(osOps, ConfigurationOsOps)
|
|
1403
|
+
|
|
1404
|
+
super(PostgresConfiguration, self).__init__()
|
|
1405
|
+
super(PgCfgModel__DataHandler, self).__init__()
|
|
1406
|
+
|
|
1407
|
+
self.m_Data = PgCfgModel__ConfigurationData(data_dir, osOps)
|
|
1408
|
+
self.m_AllFiles = None
|
|
1409
|
+
self.m_AllOptions = None
|
|
1410
|
+
|
|
1411
|
+
# interface ----------------------------------------------------------
|
|
1412
|
+
def get_Configuration(self) -> PostgresConfiguration_Base:
|
|
1413
|
+
return self
|
|
1414
|
+
|
|
1415
|
+
# --------------------------------------------------------------------
|
|
1416
|
+
def get_Parent(self) -> PostgresConfigurationObject:
|
|
1417
|
+
return None
|
|
1418
|
+
|
|
1419
|
+
# PostgresConfiguration interface ------------------------------------
|
|
1420
|
+
def AddTopLevelFile(self, path: str) -> PostgresConfigurationTopLevelFile_Base:
|
|
1421
|
+
assert type(path) == str
|
|
1422
|
+
assert path != ""
|
|
1423
|
+
assert type(self.m_Data) == PgCfgModel__ConfigurationData # noqa: E721
|
|
1424
|
+
assert isinstance(self.m_Data.OsOps, ConfigurationOsOps)
|
|
1425
|
+
assert self.m_Data.OsOps.Path_BaseName(path) != ""
|
|
1426
|
+
|
|
1427
|
+
fileData = PgCfgModel__DataControllerUtils.Cfg__CreateAndAddTopLevelFile__USER(
|
|
1428
|
+
self.m_Data, path
|
|
1429
|
+
)
|
|
1430
|
+
|
|
1431
|
+
try:
|
|
1432
|
+
file = PostgresConfigurationFactory_Base.GetObject(self, fileData)
|
|
1433
|
+
|
|
1434
|
+
assert file is not None
|
|
1435
|
+
assert type(file) == PostgresConfigurationTopLevelFile_Base
|
|
1436
|
+
except: # rollback
|
|
1437
|
+
raise
|
|
1438
|
+
|
|
1439
|
+
assert file is not None
|
|
1440
|
+
assert type(file) == PostgresConfigurationTopLevelFile_Base
|
|
1441
|
+
return file
|
|
1442
|
+
|
|
1443
|
+
# --------------------------------------------------------------------
|
|
1444
|
+
def AddOption(self, name: str, value: any) -> PostgresConfigurationOption_Base:
|
|
1445
|
+
DataVerificator.CheckOptionName(name)
|
|
1446
|
+
|
|
1447
|
+
assert name is not None
|
|
1448
|
+
assert name != ""
|
|
1449
|
+
|
|
1450
|
+
if value is None:
|
|
1451
|
+
RaiseError.NoneValueIsNotSupported()
|
|
1452
|
+
|
|
1453
|
+
option = PostgresConfigurationController__Base.AddOption(
|
|
1454
|
+
self, None, name, value, None
|
|
1455
|
+
)
|
|
1456
|
+
|
|
1457
|
+
assert option is not None
|
|
1458
|
+
assert type(option) == PostgresConfigurationOption_Base
|
|
1459
|
+
assert isinstance(option, PostgresConfigurationOption_Base)
|
|
1460
|
+
assert isinstance(option, PostgresConfigurationOption)
|
|
1461
|
+
return option
|
|
1462
|
+
|
|
1463
|
+
# --------------------------------------------------------------------
|
|
1464
|
+
def SetOptionValue(
|
|
1465
|
+
self, name: str, value: any
|
|
1466
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
1467
|
+
DataVerificator.CheckOptionName(name)
|
|
1468
|
+
|
|
1469
|
+
result = PostgresConfigurationController__Base.SetOptionValue(
|
|
1470
|
+
self,
|
|
1471
|
+
None, # target
|
|
1472
|
+
name,
|
|
1473
|
+
value,
|
|
1474
|
+
None, # offset
|
|
1475
|
+
)
|
|
1476
|
+
|
|
1477
|
+
assert result is not None
|
|
1478
|
+
assert type(result) == PostgresConfigurationSetOptionValueResult_Base
|
|
1479
|
+
assert isinstance(result, PostgresConfigurationSetOptionValueResult)
|
|
1480
|
+
return result
|
|
1481
|
+
|
|
1482
|
+
# --------------------------------------------------------------------
|
|
1483
|
+
def GetOptionValue(self, name: str) -> any:
|
|
1484
|
+
DataVerificator.CheckOptionName(name)
|
|
1485
|
+
|
|
1486
|
+
r = PostgresConfigurationController__Base.GetOptionValue(self, None, name)
|
|
1487
|
+
|
|
1488
|
+
return r
|
|
1489
|
+
|
|
1490
|
+
# --------------------------------------------------------------------
|
|
1491
|
+
def SetOptionValueItem(
|
|
1492
|
+
self, name: str, value_item: any
|
|
1493
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
1494
|
+
DataVerificator.CheckOptionName(name)
|
|
1495
|
+
|
|
1496
|
+
result = PostgresConfigurationController__Base.SetOptionValueItem(
|
|
1497
|
+
self, None, name, value_item # target
|
|
1498
|
+
)
|
|
1499
|
+
|
|
1500
|
+
assert result is not None
|
|
1501
|
+
assert type(result) == PostgresConfigurationSetOptionValueResult_Base
|
|
1502
|
+
assert isinstance(result, PostgresConfigurationSetOptionValueResult_Base)
|
|
1503
|
+
|
|
1504
|
+
return result
|
|
1505
|
+
|
|
1506
|
+
# --------------------------------------------------------------------
|
|
1507
|
+
def get_AllFiles(self) -> PostgresConfiguration_Base__AllFiles:
|
|
1508
|
+
assert self.m_Data is not None
|
|
1509
|
+
assert type(self.m_Data) == PgCfgModel__ConfigurationData
|
|
1510
|
+
|
|
1511
|
+
if self.m_AllFiles is None:
|
|
1512
|
+
self.m_AllFiles = PostgresConfiguration_Base__AllFiles(self)
|
|
1513
|
+
|
|
1514
|
+
assert self.m_AllFiles is not None
|
|
1515
|
+
assert type(self.m_AllFiles) == PostgresConfiguration_Base__AllFiles
|
|
1516
|
+
assert self.m_AllFiles.m_Cfg is self
|
|
1517
|
+
return self.m_AllFiles
|
|
1518
|
+
|
|
1519
|
+
# --------------------------------------------------------------------
|
|
1520
|
+
def get_AllOptions(self) -> PostgresConfiguration_Base__AllOptions:
|
|
1521
|
+
assert self.m_Data is not None
|
|
1522
|
+
assert type(self.m_Data) == PgCfgModel__ConfigurationData
|
|
1523
|
+
|
|
1524
|
+
if self.m_AllOptions is None:
|
|
1525
|
+
self.m_AllOptions = PostgresConfiguration_Base__AllOptions(self)
|
|
1526
|
+
|
|
1527
|
+
assert self.m_AllOptions is not None
|
|
1528
|
+
assert type(self.m_AllOptions) == PostgresConfiguration_Base__AllOptions
|
|
1529
|
+
assert self.m_AllOptions.m_Cfg is self
|
|
1530
|
+
return self.m_AllOptions
|
|
1531
|
+
|
|
1532
|
+
# DataHandler interface ----------------------------------------------
|
|
1533
|
+
def DataHandler__SetOptionValue__Simple(
|
|
1534
|
+
self,
|
|
1535
|
+
targetData: typing.Union[None, PgCfgModel__FileData, PgCfgModel__OptionData],
|
|
1536
|
+
optionName: str,
|
|
1537
|
+
optionValue: any,
|
|
1538
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
1539
|
+
assert (
|
|
1540
|
+
targetData is None
|
|
1541
|
+
or type(targetData) == PgCfgModel__FileData
|
|
1542
|
+
or type(targetData) == PgCfgModel__OptionData
|
|
1543
|
+
)
|
|
1544
|
+
assert type(optionName) == str
|
|
1545
|
+
assert optionValue is not None
|
|
1546
|
+
|
|
1547
|
+
# ------------------------------------------------
|
|
1548
|
+
if targetData is None:
|
|
1549
|
+
return self.Helper__SetSimpleOptionValue__Common(optionName, optionValue)
|
|
1550
|
+
|
|
1551
|
+
# ------------------------------------------------
|
|
1552
|
+
assert targetData is not None
|
|
1553
|
+
|
|
1554
|
+
typeOfTarget = type(targetData)
|
|
1555
|
+
|
|
1556
|
+
if typeOfTarget == PgCfgModel__OptionData:
|
|
1557
|
+
return self.Helper__SetSimpleOptionValue__Exact(targetData, optionValue)
|
|
1558
|
+
|
|
1559
|
+
if typeOfTarget == PgCfgModel__FileData:
|
|
1560
|
+
return self.Helper__SetSimpleOptionValue__File(
|
|
1561
|
+
targetData, optionName, optionValue
|
|
1562
|
+
)
|
|
1563
|
+
|
|
1564
|
+
# ------------------------------------------------
|
|
1565
|
+
BugCheckError.UnkObjectDataType(typeOfTarget)
|
|
1566
|
+
|
|
1567
|
+
# --------------------------------------------------------------------
|
|
1568
|
+
def DataHandler__GetOptionValue__Simple(
|
|
1569
|
+
self,
|
|
1570
|
+
sourceData: typing.Union[None, PgCfgModel__FileData, PgCfgModel__OptionData],
|
|
1571
|
+
optionName: str,
|
|
1572
|
+
) -> any:
|
|
1573
|
+
assert (
|
|
1574
|
+
sourceData is None
|
|
1575
|
+
or type(sourceData) == PgCfgModel__FileData
|
|
1576
|
+
or type(sourceData) == PgCfgModel__OptionData
|
|
1577
|
+
)
|
|
1578
|
+
assert type(optionName) == str
|
|
1579
|
+
|
|
1580
|
+
# -------------------------------------- ROOT
|
|
1581
|
+
if sourceData is None:
|
|
1582
|
+
optionData = self.Helper__FindSimpleOption(
|
|
1583
|
+
self.m_Data.m_AllOptionsByName, optionName
|
|
1584
|
+
)
|
|
1585
|
+
|
|
1586
|
+
if optionData is not None:
|
|
1587
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
1588
|
+
assert optionData.IsAlive()
|
|
1589
|
+
assert optionData.m_Value is not None
|
|
1590
|
+
return self.Helper__PrepareGetValue(
|
|
1591
|
+
optionData.m_Name, optionData.m_Value
|
|
1592
|
+
)
|
|
1593
|
+
|
|
1594
|
+
return None
|
|
1595
|
+
|
|
1596
|
+
typeOfSource = type(sourceData)
|
|
1597
|
+
|
|
1598
|
+
# -------------------------------------- OPTION DATA
|
|
1599
|
+
if typeOfSource == PgCfgModel__OptionData:
|
|
1600
|
+
optionData: PgCfgModel__OptionData = sourceData
|
|
1601
|
+
|
|
1602
|
+
assert optionData.IsAlive()
|
|
1603
|
+
assert optionData.m_Value is not None
|
|
1604
|
+
assert optionData.m_Name == optionName
|
|
1605
|
+
return self.Helper__PrepareGetValue(optionData.m_Name, optionData.m_Value)
|
|
1606
|
+
|
|
1607
|
+
# -------------------------------------- FILE DATA
|
|
1608
|
+
if typeOfSource == PgCfgModel__FileData:
|
|
1609
|
+
fileData: PgCfgModel__FileData = sourceData
|
|
1610
|
+
|
|
1611
|
+
assert fileData.IsAlive()
|
|
1612
|
+
assert fileData.m_OptionsByName is not None
|
|
1613
|
+
assert type(fileData.m_OptionsByName) == dict
|
|
1614
|
+
|
|
1615
|
+
optionData = self.Helper__FindSimpleOption(
|
|
1616
|
+
fileData.m_OptionsByName, optionName
|
|
1617
|
+
)
|
|
1618
|
+
|
|
1619
|
+
if optionData is not None:
|
|
1620
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
1621
|
+
assert optionData.IsAlive()
|
|
1622
|
+
assert optionData.m_Value is not None
|
|
1623
|
+
return self.Helper__PrepareGetValue(
|
|
1624
|
+
optionData.m_Name, optionData.m_Value
|
|
1625
|
+
)
|
|
1626
|
+
|
|
1627
|
+
return None
|
|
1628
|
+
|
|
1629
|
+
BugCheckError.UnkObjectDataType(typeOfSource)
|
|
1630
|
+
|
|
1631
|
+
# --------------------------------------------------------------------
|
|
1632
|
+
def DataHandler__GetOptionValue__UnionList(
|
|
1633
|
+
self,
|
|
1634
|
+
sourceData: typing.Union[
|
|
1635
|
+
None, PgCfgModel__FileLineData, PgCfgModel__OptionData
|
|
1636
|
+
],
|
|
1637
|
+
optionName: str,
|
|
1638
|
+
) -> any:
|
|
1639
|
+
assert (
|
|
1640
|
+
sourceData is None
|
|
1641
|
+
or type(sourceData) == PgCfgModel__FileData
|
|
1642
|
+
or type(sourceData) == PgCfgModel__OptionData
|
|
1643
|
+
)
|
|
1644
|
+
assert type(optionName) == str
|
|
1645
|
+
|
|
1646
|
+
# -------------------------------------- ROOT
|
|
1647
|
+
if sourceData is None:
|
|
1648
|
+
unionList = self.Helper__AggregateAllOptionValues(
|
|
1649
|
+
self.m_Data.m_AllOptionsByName, optionName
|
|
1650
|
+
)
|
|
1651
|
+
|
|
1652
|
+
if unionList is None:
|
|
1653
|
+
return None
|
|
1654
|
+
|
|
1655
|
+
assert type(unionList) == list
|
|
1656
|
+
return self.Helper__PrepareGetValue(optionName, unionList)
|
|
1657
|
+
|
|
1658
|
+
typeOfSource = type(sourceData)
|
|
1659
|
+
|
|
1660
|
+
# -------------------------------------- OPTION DATA
|
|
1661
|
+
if typeOfSource == PgCfgModel__OptionData:
|
|
1662
|
+
optionData: PgCfgModel__OptionData = sourceData
|
|
1663
|
+
|
|
1664
|
+
assert optionData.IsAlive()
|
|
1665
|
+
assert optionData.m_Value is not None
|
|
1666
|
+
self.Debug__CheckOurObjectData(optionData)
|
|
1667
|
+
assert optionData.m_Name == optionName
|
|
1668
|
+
return self.Helper__PrepareGetValue(optionData.m_Name, optionData.m_Value)
|
|
1669
|
+
|
|
1670
|
+
# -------------------------------------- FILE DATA
|
|
1671
|
+
if typeOfSource == PgCfgModel__FileData:
|
|
1672
|
+
sourceFileData: PgCfgModel__FileData = sourceData
|
|
1673
|
+
|
|
1674
|
+
assert type(sourceFileData) == PgCfgModel__FileData
|
|
1675
|
+
assert sourceFileData.IsAlive()
|
|
1676
|
+
assert sourceFileData.m_OptionsByName is not None
|
|
1677
|
+
assert type(sourceFileData.m_OptionsByName) == dict
|
|
1678
|
+
|
|
1679
|
+
typeOfOption = type(optionName)
|
|
1680
|
+
|
|
1681
|
+
if typeOfOption == str:
|
|
1682
|
+
unionList = self.Helper__AggregateAllOptionValues(
|
|
1683
|
+
sourceFileData.m_OptionsByName, optionName
|
|
1684
|
+
)
|
|
1685
|
+
|
|
1686
|
+
if unionList is None:
|
|
1687
|
+
return None
|
|
1688
|
+
|
|
1689
|
+
assert type(unionList) == list
|
|
1690
|
+
return self.Helper__PrepareGetValue(optionName, unionList)
|
|
1691
|
+
|
|
1692
|
+
BugCheckError.UnkObjectDataType(typeOfOption)
|
|
1693
|
+
|
|
1694
|
+
BugCheckError.UnkObjectDataType(typeOfSource)
|
|
1695
|
+
|
|
1696
|
+
# --------------------------------------------------------------------
|
|
1697
|
+
def DataHandler__ResetOption(
|
|
1698
|
+
self,
|
|
1699
|
+
targetData: typing.Union[None, PgCfgModel__FileData, PgCfgModel__OptionData],
|
|
1700
|
+
optionName: str,
|
|
1701
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
1702
|
+
assert (
|
|
1703
|
+
targetData is None
|
|
1704
|
+
or type(targetData) == PgCfgModel__FileData
|
|
1705
|
+
or type(targetData) == PgCfgModel__OptionData
|
|
1706
|
+
)
|
|
1707
|
+
assert type(optionName) == str
|
|
1708
|
+
|
|
1709
|
+
# -------------------------------- target is NONE
|
|
1710
|
+
if targetData is None:
|
|
1711
|
+
eventID = self.Helper__FindAndDeleteOption(
|
|
1712
|
+
self.m_Data.m_AllOptionsByName, optionName
|
|
1713
|
+
)
|
|
1714
|
+
|
|
1715
|
+
assert (
|
|
1716
|
+
eventID == PostgresConfigurationSetOptionValueEventID.NONE
|
|
1717
|
+
or PostgresConfigurationSetOptionValueEventID.OPTION_WAS_DELETED
|
|
1718
|
+
)
|
|
1719
|
+
|
|
1720
|
+
return PostgresConfigurationSetOptionValueResult_Base(None, None, eventID)
|
|
1721
|
+
|
|
1722
|
+
# -------------------------------- target is FileData or OptionData
|
|
1723
|
+
typeOfTarget = type(targetData)
|
|
1724
|
+
|
|
1725
|
+
if typeOfTarget == PgCfgModel__OptionData:
|
|
1726
|
+
self.Debug__CheckOurObjectData(targetData)
|
|
1727
|
+
|
|
1728
|
+
PgCfgModel__DataControllerUtils.Option__delete(
|
|
1729
|
+
self.m_Data, targetData, True
|
|
1730
|
+
)
|
|
1731
|
+
|
|
1732
|
+
return (
|
|
1733
|
+
PostgresConfigurationSetOptionValueResult_Base.Create__OptWasDeleted()
|
|
1734
|
+
)
|
|
1735
|
+
|
|
1736
|
+
if typeOfTarget is PgCfgModel__FileData:
|
|
1737
|
+
assert type(targetData) == PgCfgModel__FileData
|
|
1738
|
+
|
|
1739
|
+
eventID = self.Helper__FindAndDeleteOption(
|
|
1740
|
+
targetData.m_OptionsByName, optionName
|
|
1741
|
+
)
|
|
1742
|
+
|
|
1743
|
+
assert (
|
|
1744
|
+
eventID == PostgresConfigurationSetOptionValueEventID.NONE
|
|
1745
|
+
or PostgresConfigurationSetOptionValueEventID.OPTION_WAS_DELETED
|
|
1746
|
+
)
|
|
1747
|
+
|
|
1748
|
+
return PostgresConfigurationSetOptionValueResult_Base(None, None, eventID)
|
|
1749
|
+
|
|
1750
|
+
BugCheckError.UnkObjectDataType(typeOfTarget)
|
|
1751
|
+
|
|
1752
|
+
# --------------------------------------------------------------------
|
|
1753
|
+
def DataHandler__AddSimpleOption(
|
|
1754
|
+
self,
|
|
1755
|
+
target: typing.Union[None, PgCfgModel__FileData, PgCfgModel__FileLineData],
|
|
1756
|
+
optionOffset: typing.Optional[int],
|
|
1757
|
+
optionName: str,
|
|
1758
|
+
optionValue: any,
|
|
1759
|
+
) -> PostgresConfigurationOption_Base:
|
|
1760
|
+
assert (
|
|
1761
|
+
target is None
|
|
1762
|
+
or type(target) == PgCfgModel__FileData
|
|
1763
|
+
or type(target) == PgCfgModel__FileLineData
|
|
1764
|
+
)
|
|
1765
|
+
assert optionOffset is None or type(optionOffset) == int
|
|
1766
|
+
assert type(optionName) == str
|
|
1767
|
+
assert optionValue is not None
|
|
1768
|
+
|
|
1769
|
+
assert self.m_Data is not None
|
|
1770
|
+
assert type(self.m_Data) == PgCfgModel__ConfigurationData
|
|
1771
|
+
assert self.m_Data.m_AllOptionsByName is not None
|
|
1772
|
+
assert type(self.m_Data.m_AllOptionsByName) == dict
|
|
1773
|
+
|
|
1774
|
+
typeOfTarget = type(target)
|
|
1775
|
+
|
|
1776
|
+
if typeOfTarget == PgCfgModel__FileLineData:
|
|
1777
|
+
return self.Helper__AddSimpleOption__FileLine(
|
|
1778
|
+
target, optionOffset, optionName, optionValue
|
|
1779
|
+
)
|
|
1780
|
+
|
|
1781
|
+
assert optionOffset is None
|
|
1782
|
+
|
|
1783
|
+
if typeOfTarget == PgCfgModel__FileData:
|
|
1784
|
+
return self.Helper__AddSimpleOption__File(target, optionName, optionValue)
|
|
1785
|
+
|
|
1786
|
+
if target is None:
|
|
1787
|
+
return self.Helper__AddSimpleOption__Common(optionName, optionValue)
|
|
1788
|
+
|
|
1789
|
+
BugCheckError.UnkObjectDataType(typeOfTarget)
|
|
1790
|
+
|
|
1791
|
+
# --------------------------------------------------------------------
|
|
1792
|
+
def DataHandler__SetUniqueOptionValueItem(
|
|
1793
|
+
self,
|
|
1794
|
+
targetData: typing.Union[None, PgCfgModel__FileData, PgCfgModel__OptionData],
|
|
1795
|
+
optionName: str,
|
|
1796
|
+
optionValueItem: any,
|
|
1797
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
1798
|
+
assert (
|
|
1799
|
+
targetData is None
|
|
1800
|
+
or type(targetData) == PgCfgModel__FileData
|
|
1801
|
+
or type(targetData) == PgCfgModel__OptionData
|
|
1802
|
+
)
|
|
1803
|
+
assert type(optionName) == str
|
|
1804
|
+
assert optionValueItem is not None
|
|
1805
|
+
|
|
1806
|
+
# -------------------------------- target is NONE
|
|
1807
|
+
if targetData is None:
|
|
1808
|
+
return self.Helper__SetUniqueOptionValueItem__Common(
|
|
1809
|
+
optionName, optionValueItem
|
|
1810
|
+
)
|
|
1811
|
+
|
|
1812
|
+
# --------------------------------
|
|
1813
|
+
typeOfTarget = type(targetData)
|
|
1814
|
+
|
|
1815
|
+
# -------------------------------- target is OPTION DATA
|
|
1816
|
+
if typeOfTarget is PgCfgModel__OptionData:
|
|
1817
|
+
assert targetData.m_Name == optionName
|
|
1818
|
+
|
|
1819
|
+
return self.Helper__SetUniqueOptionValueItem__Exact(
|
|
1820
|
+
targetData, optionValueItem
|
|
1821
|
+
)
|
|
1822
|
+
|
|
1823
|
+
# -------------------------------- target is FILE DATA
|
|
1824
|
+
if typeOfTarget is PgCfgModel__FileData:
|
|
1825
|
+
return self.Helper__SetUniqueOptionValueItem__File(
|
|
1826
|
+
targetData, optionName, optionValueItem
|
|
1827
|
+
)
|
|
1828
|
+
|
|
1829
|
+
BugCheckError.UnkObjectDataType(typeOfTarget)
|
|
1830
|
+
|
|
1831
|
+
# Internal interface -------------------------------------------------
|
|
1832
|
+
def Internal__GetAutoConfFileName(self) -> str:
|
|
1833
|
+
RaiseError.MethodIsNotImplemented(__class__, "Internal__GetAutoConfFile")
|
|
1834
|
+
|
|
1835
|
+
# --------------------------------------------------------------------
|
|
1836
|
+
def Internal__GetOptionHandlerToPrepareSetValue(
|
|
1837
|
+
self, name: str
|
|
1838
|
+
) -> PgCfgModel__OptionHandlerToPrepareSetValue:
|
|
1839
|
+
assert type(name) == str
|
|
1840
|
+
RaiseError.MethodIsNotImplemented(
|
|
1841
|
+
__class__, "Internal__GetOptionHandlerToPrepareSetValue"
|
|
1842
|
+
)
|
|
1843
|
+
|
|
1844
|
+
# --------------------------------------------------------------------
|
|
1845
|
+
def Internal__GetOptionHandlerToPrepareSetValueItem(
|
|
1846
|
+
self, name: str
|
|
1847
|
+
) -> PgCfgModel__OptionHandlerToPrepareSetValueItem:
|
|
1848
|
+
assert type(name) == str
|
|
1849
|
+
RaiseError.MethodIsNotImplemented(
|
|
1850
|
+
__class__, "Internal__GetOptionHandlerToPrepareSetValueItem"
|
|
1851
|
+
)
|
|
1852
|
+
|
|
1853
|
+
# --------------------------------------------------------------------
|
|
1854
|
+
def Internal__GetOptionHandlerToPrepareGetValue(
|
|
1855
|
+
self, name: str
|
|
1856
|
+
) -> PgCfgModel__OptionHandlerToPrepareGetValue:
|
|
1857
|
+
assert type(name) == str
|
|
1858
|
+
RaiseError.MethodIsNotImplemented(
|
|
1859
|
+
__class__, "Internal__GetOptionHandlerToPrepareGetValue"
|
|
1860
|
+
)
|
|
1861
|
+
|
|
1862
|
+
# --------------------------------------------------------------------
|
|
1863
|
+
def Internal__GetOptionHandlerToSetValue(
|
|
1864
|
+
self, name: str
|
|
1865
|
+
) -> PgCfgModel__OptionHandlerToSetValue:
|
|
1866
|
+
assert type(name) == str
|
|
1867
|
+
RaiseError.MethodIsNotImplemented(
|
|
1868
|
+
__class__, "Internal__GetOptionHandlerToSetValue"
|
|
1869
|
+
)
|
|
1870
|
+
|
|
1871
|
+
# --------------------------------------------------------------------
|
|
1872
|
+
def Internal__GetOptionHandlerToGetValue(
|
|
1873
|
+
self, name: str
|
|
1874
|
+
) -> PgCfgModel__OptionHandlerToGetValue:
|
|
1875
|
+
assert type(name) == str
|
|
1876
|
+
RaiseError.MethodIsNotImplemented(
|
|
1877
|
+
__class__, "Internal__GetOptionHandlerToGetValue"
|
|
1878
|
+
)
|
|
1879
|
+
|
|
1880
|
+
# --------------------------------------------------------------------
|
|
1881
|
+
def Internal__GetOptionHandlerToAddOption(
|
|
1882
|
+
self, name: str
|
|
1883
|
+
) -> PgCfgModel__OptionHandlerToAddOption:
|
|
1884
|
+
assert type(name) == str
|
|
1885
|
+
RaiseError.MethodIsNotImplemented(
|
|
1886
|
+
__class__, "Internal__GetOptionHandlerToAddOption"
|
|
1887
|
+
)
|
|
1888
|
+
|
|
1889
|
+
# --------------------------------------------------------------------
|
|
1890
|
+
def Internal__GetOptionHandlerToSetValueItem(
|
|
1891
|
+
self, name: str
|
|
1892
|
+
) -> PgCfgModel__OptionHandlerToSetValueItem:
|
|
1893
|
+
assert type(name) == str
|
|
1894
|
+
RaiseError.MethodIsNotImplemented(
|
|
1895
|
+
__class__, "Internal__GetOptionHandlerToSetValueItem"
|
|
1896
|
+
)
|
|
1897
|
+
|
|
1898
|
+
# --------------------------------------------------------------------
|
|
1899
|
+
def Internal__GetOptionHandlerToWrite(
|
|
1900
|
+
self, name: str
|
|
1901
|
+
) -> PgCfgModel__OptionHandlerToWrite:
|
|
1902
|
+
assert type(name) == str
|
|
1903
|
+
RaiseError.MethodIsNotImplemented(
|
|
1904
|
+
__class__, "Internal__GetOptionHandlerToWrite"
|
|
1905
|
+
)
|
|
1906
|
+
|
|
1907
|
+
# helper methods -----------------------------------------------------
|
|
1908
|
+
def Helper__FindSimpleOption(
|
|
1909
|
+
self, allOptionsByName: dict[str, PgCfgModel__OptionData], optionName: str
|
|
1910
|
+
) -> typing.Optional[PgCfgModel__OptionData]:
|
|
1911
|
+
assert type(allOptionsByName) == dict
|
|
1912
|
+
assert type(optionName) == str
|
|
1913
|
+
|
|
1914
|
+
if not (optionName in allOptionsByName.keys()):
|
|
1915
|
+
return None
|
|
1916
|
+
|
|
1917
|
+
data = allOptionsByName[optionName]
|
|
1918
|
+
|
|
1919
|
+
assert data is not None
|
|
1920
|
+
|
|
1921
|
+
if type(data) == PgCfgModel__OptionData:
|
|
1922
|
+
assert data.IsAlive()
|
|
1923
|
+
assert data.m_Name == optionName
|
|
1924
|
+
self.Debug__CheckOurObjectData(data)
|
|
1925
|
+
return data
|
|
1926
|
+
|
|
1927
|
+
if type(data) == list:
|
|
1928
|
+
assert len(data) > 1
|
|
1929
|
+
BugCheckError.MultipleDefOfOptionIsFound(optionName, len(data))
|
|
1930
|
+
|
|
1931
|
+
BugCheckError.UnkOptObjectDataType(optionName, type(data))
|
|
1932
|
+
|
|
1933
|
+
# --------------------------------------------------------------------
|
|
1934
|
+
def Helper__AggregateAllOptionValues(
|
|
1935
|
+
self, allOptionsByName: dict[str, PgCfgModel__OptionData], optionName: str
|
|
1936
|
+
) -> list:
|
|
1937
|
+
assert type(allOptionsByName) == dict
|
|
1938
|
+
assert type(optionName) == str
|
|
1939
|
+
|
|
1940
|
+
if not (optionName in allOptionsByName.keys()):
|
|
1941
|
+
return None
|
|
1942
|
+
|
|
1943
|
+
data = allOptionsByName[optionName]
|
|
1944
|
+
assert data is not None
|
|
1945
|
+
|
|
1946
|
+
typeOfData = type(data)
|
|
1947
|
+
|
|
1948
|
+
if typeOfData == PgCfgModel__OptionData:
|
|
1949
|
+
assert data.IsAlive()
|
|
1950
|
+
assert data.m_Name == optionName
|
|
1951
|
+
assert data.m_Value is not None
|
|
1952
|
+
assert type(data.m_Value) == list
|
|
1953
|
+
return data.m_Value
|
|
1954
|
+
|
|
1955
|
+
if typeOfData == list:
|
|
1956
|
+
assert type(data) == list
|
|
1957
|
+
data = data.copy()
|
|
1958
|
+
assert type(data) == list
|
|
1959
|
+
|
|
1960
|
+
result = []
|
|
1961
|
+
|
|
1962
|
+
for optionData in data:
|
|
1963
|
+
assert optionData is not None
|
|
1964
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
1965
|
+
assert optionData.m_Name == optionName
|
|
1966
|
+
assert optionData.IsAlive()
|
|
1967
|
+
assert optionData.m_Value is not None
|
|
1968
|
+
assert type(optionData.m_Value) == list
|
|
1969
|
+
|
|
1970
|
+
result.extend(self.m_Data)
|
|
1971
|
+
|
|
1972
|
+
assert result is not None
|
|
1973
|
+
assert type(result) == list
|
|
1974
|
+
|
|
1975
|
+
return result
|
|
1976
|
+
|
|
1977
|
+
# Unknown type of option data in dictionary
|
|
1978
|
+
|
|
1979
|
+
assert type(optionName) == str
|
|
1980
|
+
BugCheckError.UnkOptObjectDataType(optionName, typeOfData)
|
|
1981
|
+
|
|
1982
|
+
# --------------------------------------------------------------------
|
|
1983
|
+
def Helper__FindAndDeleteOption(
|
|
1984
|
+
self, allOptionsByName: dict[str, PgCfgModel__OptionData], optionName: str
|
|
1985
|
+
) -> PostgresConfigurationSetOptionValueEventID:
|
|
1986
|
+
assert type(allOptionsByName) == dict
|
|
1987
|
+
assert type(optionName) == str
|
|
1988
|
+
|
|
1989
|
+
if not (optionName in allOptionsByName.keys()):
|
|
1990
|
+
return PostgresConfigurationSetOptionValueEventID.NONE
|
|
1991
|
+
|
|
1992
|
+
data = allOptionsByName[optionName]
|
|
1993
|
+
assert data is not None
|
|
1994
|
+
|
|
1995
|
+
typeOfData = type(data)
|
|
1996
|
+
|
|
1997
|
+
if typeOfData == PgCfgModel__OptionData:
|
|
1998
|
+
assert data.IsAlive()
|
|
1999
|
+
assert data.m_Name == optionName
|
|
2000
|
+
|
|
2001
|
+
PgCfgModel__DataControllerUtils.Option__delete(self.m_Data, data, True)
|
|
2002
|
+
|
|
2003
|
+
return PostgresConfigurationSetOptionValueEventID.OPTION_WAS_DELETED
|
|
2004
|
+
|
|
2005
|
+
if typeOfData == list:
|
|
2006
|
+
assert type(data) == list
|
|
2007
|
+
data = data.copy()
|
|
2008
|
+
assert type(data) == list
|
|
2009
|
+
|
|
2010
|
+
for optionData in data:
|
|
2011
|
+
assert optionData is not None
|
|
2012
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2013
|
+
assert optionData.IsAlive()
|
|
2014
|
+
assert optionData.m_Name == optionName
|
|
2015
|
+
|
|
2016
|
+
PgCfgModel__DataControllerUtils.Option__delete(
|
|
2017
|
+
self.m_Data, optionData, True
|
|
2018
|
+
)
|
|
2019
|
+
|
|
2020
|
+
# [2025-01-02] It is expected
|
|
2021
|
+
assert not (optionName in allOptionsByName.keys())
|
|
2022
|
+
|
|
2023
|
+
return PostgresConfigurationSetOptionValueEventID.OPTION_WAS_DELETED
|
|
2024
|
+
|
|
2025
|
+
# Unknown type of option data in dictionary
|
|
2026
|
+
|
|
2027
|
+
assert type(optionName) == str
|
|
2028
|
+
BugCheckError.UnkOptObjectDataType(optionName, typeOfData)
|
|
2029
|
+
|
|
2030
|
+
# --------------------------------------------------------------------
|
|
2031
|
+
# returns tuple[FileData, Bool_signal_about_creating_a_new_file]
|
|
2032
|
+
def Helper__GetFileForSimpleOption(
|
|
2033
|
+
self, option_name: str
|
|
2034
|
+
) -> tuple[PgCfgModel__FileData, bool]:
|
|
2035
|
+
assert type(option_name) == str
|
|
2036
|
+
assert option_name != ""
|
|
2037
|
+
|
|
2038
|
+
option_name_parts = option_name.split(".")
|
|
2039
|
+
|
|
2040
|
+
assert type(option_name_parts) == list
|
|
2041
|
+
assert len(option_name_parts) > 0
|
|
2042
|
+
|
|
2043
|
+
if len(option_name_parts) > 1:
|
|
2044
|
+
specFileName = "postgresql." + ".".join(option_name_parts[:-1]) + ".conf"
|
|
2045
|
+
assert type(specFileName) == str
|
|
2046
|
+
|
|
2047
|
+
fileData = self.Helper__FindFile(specFileName)
|
|
2048
|
+
|
|
2049
|
+
if fileData is not None:
|
|
2050
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
2051
|
+
return (fileData, False)
|
|
2052
|
+
|
|
2053
|
+
# Let's use standard "postgresql.auto.conf"
|
|
2054
|
+
|
|
2055
|
+
fileData = self.Helper__FindFile(self.Internal__GetAutoConfFileName())
|
|
2056
|
+
|
|
2057
|
+
if fileData is not None:
|
|
2058
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
2059
|
+
return (fileData, False)
|
|
2060
|
+
|
|
2061
|
+
assert fileData is None
|
|
2062
|
+
|
|
2063
|
+
fileData = PgCfgModel__DataControllerUtils.Cfg__CreateAndAddTopLevelFile__AUTO(
|
|
2064
|
+
self.m_Data, self.Internal__GetAutoConfFileName()
|
|
2065
|
+
)
|
|
2066
|
+
|
|
2067
|
+
assert fileData is not None
|
|
2068
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
2069
|
+
|
|
2070
|
+
return (fileData, True)
|
|
2071
|
+
|
|
2072
|
+
# --------------------------------------------------------------------
|
|
2073
|
+
def Helper__FindFile(self, file_name: str) -> PgCfgModel__FileData:
|
|
2074
|
+
assert type(file_name) == str
|
|
2075
|
+
assert file_name != ""
|
|
2076
|
+
assert type(self.m_Data) == PgCfgModel__ConfigurationData # noqa: E721
|
|
2077
|
+
assert isinstance(self.m_Data.OsOps, ConfigurationOsOps)
|
|
2078
|
+
assert self.m_Data.OsOps.Path_BaseName(file_name) == file_name
|
|
2079
|
+
|
|
2080
|
+
assert type(self.m_Data) == PgCfgModel__ConfigurationData
|
|
2081
|
+
assert type(self.m_Data.m_AllFilesByName) == dict
|
|
2082
|
+
|
|
2083
|
+
file_name_n = self.m_Data.OsOps.Path_NormCase(file_name)
|
|
2084
|
+
|
|
2085
|
+
if not (file_name_n in self.m_Data.m_AllFilesByName.keys()):
|
|
2086
|
+
return None
|
|
2087
|
+
|
|
2088
|
+
data = self.m_Data.m_AllFilesByName[file_name_n]
|
|
2089
|
+
|
|
2090
|
+
assert data is not None
|
|
2091
|
+
|
|
2092
|
+
if type(data) == PgCfgModel__FileData:
|
|
2093
|
+
return data
|
|
2094
|
+
|
|
2095
|
+
if type(data) == list:
|
|
2096
|
+
assert len(data) > 1
|
|
2097
|
+
BugCheckError.MultipleDefOfFileIsFound(file_name_n, len(data))
|
|
2098
|
+
|
|
2099
|
+
BugCheckError.UnkFileObjectDataType(file_name_n, type(data))
|
|
2100
|
+
|
|
2101
|
+
# --------------------------------------------------------------------
|
|
2102
|
+
def Helper__PrepareGetValue(self, optionName: str, optionValue: any) -> any:
|
|
2103
|
+
assert optionName is not None
|
|
2104
|
+
assert optionValue is not None
|
|
2105
|
+
assert type(optionName) == str
|
|
2106
|
+
|
|
2107
|
+
prepareHandler = self.Internal__GetOptionHandlerToPrepareGetValue(optionName)
|
|
2108
|
+
assert prepareHandler is not None
|
|
2109
|
+
assert isinstance(prepareHandler, PgCfgModel__OptionHandlerToPrepareGetValue)
|
|
2110
|
+
|
|
2111
|
+
prepareCtx = PgCfgModel__OptionHandlerCtxPrepareToGetValue(
|
|
2112
|
+
self, optionName, optionValue
|
|
2113
|
+
)
|
|
2114
|
+
|
|
2115
|
+
return prepareHandler.PrepareGetValue(prepareCtx)
|
|
2116
|
+
|
|
2117
|
+
# --------------------------------------------------------------------
|
|
2118
|
+
def Helper__AddSimpleOption__Common(
|
|
2119
|
+
self,
|
|
2120
|
+
optionName: str,
|
|
2121
|
+
optionValue: any,
|
|
2122
|
+
) -> PostgresConfigurationOption_Base:
|
|
2123
|
+
assert type(optionName) == str
|
|
2124
|
+
assert optionValue is not None
|
|
2125
|
+
|
|
2126
|
+
assert self.m_Data is not None
|
|
2127
|
+
assert type(self.m_Data) == PgCfgModel__ConfigurationData
|
|
2128
|
+
assert self.m_Data.m_AllOptionsByName is not None
|
|
2129
|
+
assert type(self.m_Data.m_AllOptionsByName) == dict
|
|
2130
|
+
|
|
2131
|
+
if optionName in self.m_Data.m_AllOptionsByName.keys():
|
|
2132
|
+
assert self.m_Data.m_AllOptionsByName[optionName] is not None
|
|
2133
|
+
indexItem = self.m_Data.m_AllOptionsByName[optionName]
|
|
2134
|
+
optionData = Helpers.ExtractFirstOptionFromIndexItem(optionName, indexItem)
|
|
2135
|
+
|
|
2136
|
+
assert optionData is not None
|
|
2137
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2138
|
+
assert optionData.IsAlive()
|
|
2139
|
+
assert optionData.get_Parent() is not None
|
|
2140
|
+
assert type(optionData.get_Parent()) == PgCfgModel__FileLineData
|
|
2141
|
+
|
|
2142
|
+
anotherFileData = optionData.get_Parent().get_Parent()
|
|
2143
|
+
|
|
2144
|
+
assert anotherFileData is not None
|
|
2145
|
+
assert type(anotherFileData) == PgCfgModel__FileData
|
|
2146
|
+
|
|
2147
|
+
RaiseError.OptionIsAlreadyExistInFile(anotherFileData.m_Path, optionName)
|
|
2148
|
+
|
|
2149
|
+
# OK. Let's add this option
|
|
2150
|
+
assert optionValue is not None
|
|
2151
|
+
|
|
2152
|
+
# Let's select the file to append this new option
|
|
2153
|
+
getFileData_r = self.Helper__GetFileForSimpleOption(optionName)
|
|
2154
|
+
|
|
2155
|
+
assert type(getFileData_r) == tuple
|
|
2156
|
+
assert len(getFileData_r) == 2
|
|
2157
|
+
|
|
2158
|
+
assert type(getFileData_r[0]) == PgCfgModel__FileData
|
|
2159
|
+
assert type(getFileData_r[1]) == bool
|
|
2160
|
+
|
|
2161
|
+
fileData = getFileData_r[0]
|
|
2162
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
2163
|
+
|
|
2164
|
+
try:
|
|
2165
|
+
# may raise
|
|
2166
|
+
optionData = PgCfgModel__DataControllerUtils.File__add_Option(
|
|
2167
|
+
self.m_Data, fileData, optionName, optionValue
|
|
2168
|
+
)
|
|
2169
|
+
|
|
2170
|
+
assert optionData is not None
|
|
2171
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2172
|
+
|
|
2173
|
+
assert optionName in self.m_Data.m_AllOptionsByName.keys()
|
|
2174
|
+
assert optionName in fileData.m_OptionsByName.keys()
|
|
2175
|
+
|
|
2176
|
+
try:
|
|
2177
|
+
# may raise
|
|
2178
|
+
option = PostgresConfigurationFactory_Base.GetObject(self, optionData)
|
|
2179
|
+
|
|
2180
|
+
assert option is not None
|
|
2181
|
+
assert type(option) == PostgresConfigurationOption_Base
|
|
2182
|
+
assert option.m_OptionData is optionData
|
|
2183
|
+
except: # rollback line with option
|
|
2184
|
+
assert optionData.IsAlive()
|
|
2185
|
+
|
|
2186
|
+
PgCfgModel__DataControllerUtils.FileLine__delete(
|
|
2187
|
+
self.m_Data, optionData.get_Parent()
|
|
2188
|
+
)
|
|
2189
|
+
|
|
2190
|
+
assert not optionData.IsAlive()
|
|
2191
|
+
|
|
2192
|
+
assert not (optionName in self.m_Data.m_AllOptionsByName.keys())
|
|
2193
|
+
assert not (optionName in fileData.m_OptionsByName.keys())
|
|
2194
|
+
raise
|
|
2195
|
+
except: # rollback file
|
|
2196
|
+
assert type(getFileData_r) == tuple
|
|
2197
|
+
assert len(getFileData_r) == 2
|
|
2198
|
+
|
|
2199
|
+
assert type(getFileData_r[0]) == PgCfgModel__FileData
|
|
2200
|
+
assert type(getFileData_r[1]) == bool
|
|
2201
|
+
|
|
2202
|
+
if getFileData_r[1]:
|
|
2203
|
+
pass # TODO: delete file
|
|
2204
|
+
|
|
2205
|
+
raise
|
|
2206
|
+
|
|
2207
|
+
assert option is not None
|
|
2208
|
+
assert type(option) == PostgresConfigurationOption_Base
|
|
2209
|
+
assert option.m_OptionData is optionData
|
|
2210
|
+
assert option.m_OptionData.IsAlive()
|
|
2211
|
+
return option
|
|
2212
|
+
|
|
2213
|
+
# --------------------------------------------------------------------
|
|
2214
|
+
def Helper__AddSimpleOption__FileLine(
|
|
2215
|
+
self,
|
|
2216
|
+
fileLineData: PgCfgModel__FileLineData,
|
|
2217
|
+
optionOffset: typing.Optional[int],
|
|
2218
|
+
optionName: str,
|
|
2219
|
+
optionValue: any,
|
|
2220
|
+
):
|
|
2221
|
+
assert fileLineData is not None
|
|
2222
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
2223
|
+
assert optionOffset is None or type(optionOffset) == int
|
|
2224
|
+
assert type(optionName) == str
|
|
2225
|
+
assert optionValue is not None
|
|
2226
|
+
|
|
2227
|
+
assert self.m_Data is not None
|
|
2228
|
+
assert type(self.m_Data) == PgCfgModel__ConfigurationData
|
|
2229
|
+
assert self.m_Data.m_AllOptionsByName is not None
|
|
2230
|
+
assert type(self.m_Data.m_AllOptionsByName) == dict
|
|
2231
|
+
|
|
2232
|
+
fileData = fileLineData.m_Parent
|
|
2233
|
+
assert fileData is not None
|
|
2234
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
2235
|
+
|
|
2236
|
+
assert fileData.m_OptionsByName is not None
|
|
2237
|
+
assert type(fileData.m_OptionsByName) == dict
|
|
2238
|
+
|
|
2239
|
+
if optionName in fileData.m_OptionsByName.keys():
|
|
2240
|
+
assert fileData.m_OptionsByName[optionName] is not None
|
|
2241
|
+
RaiseError.OptionIsAlreadyExistInThisFile(fileData.m_Path, optionName)
|
|
2242
|
+
|
|
2243
|
+
if optionName in self.m_Data.m_AllOptionsByName.keys():
|
|
2244
|
+
assert self.m_Data.m_AllOptionsByName[optionName] is not None
|
|
2245
|
+
indexItem = self.m_Data.m_AllOptionsByName[optionName]
|
|
2246
|
+
optionData = Helpers.ExtractFirstOptionFromIndexItem(optionName, indexItem)
|
|
2247
|
+
|
|
2248
|
+
assert optionData is not None
|
|
2249
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2250
|
+
assert optionData.IsAlive()
|
|
2251
|
+
assert optionData.m_Name == optionName
|
|
2252
|
+
assert optionData.get_Parent() is not None
|
|
2253
|
+
assert type(optionData.get_Parent()) == PgCfgModel__FileLineData
|
|
2254
|
+
|
|
2255
|
+
anotherFileData = optionData.get_Parent().get_Parent()
|
|
2256
|
+
|
|
2257
|
+
assert anotherFileData is not None
|
|
2258
|
+
assert type(anotherFileData) == PgCfgModel__FileData
|
|
2259
|
+
assert anotherFileData is not fileData
|
|
2260
|
+
|
|
2261
|
+
RaiseError.OptionIsAlreadyExistInAnotherFile(
|
|
2262
|
+
anotherFileData.m_Path, optionName
|
|
2263
|
+
)
|
|
2264
|
+
|
|
2265
|
+
assert not (optionName in fileData.m_OptionsByName.keys())
|
|
2266
|
+
assert not (optionName in self.m_Data.m_AllOptionsByName.keys())
|
|
2267
|
+
|
|
2268
|
+
# OK. Let's add this option
|
|
2269
|
+
assert optionValue is not None
|
|
2270
|
+
|
|
2271
|
+
optionData = PgCfgModel__DataControllerUtils.FileLine__add_Option(
|
|
2272
|
+
self.m_Data, fileLineData, optionName, optionValue, optionOffset
|
|
2273
|
+
)
|
|
2274
|
+
|
|
2275
|
+
assert optionData is not None
|
|
2276
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2277
|
+
|
|
2278
|
+
assert optionName in fileData.m_OptionsByName.keys()
|
|
2279
|
+
assert optionName in self.m_Data.m_AllOptionsByName.keys()
|
|
2280
|
+
|
|
2281
|
+
try:
|
|
2282
|
+
option = PostgresConfigurationFactory_Base.GetObject(self, optionData)
|
|
2283
|
+
|
|
2284
|
+
assert option is not None
|
|
2285
|
+
assert type(option) == PostgresConfigurationOption_Base
|
|
2286
|
+
assert option.m_OptionData is optionData
|
|
2287
|
+
except:
|
|
2288
|
+
PgCfgModel__DataControllerUtils.Option__delete(self.m_Data, optionData())
|
|
2289
|
+
|
|
2290
|
+
assert not optionData.IsAlive()
|
|
2291
|
+
assert not (optionName in fileData.m_OptionsByName.keys())
|
|
2292
|
+
assert not (optionName in self.m_Data.m_AllOptionsByName.keys())
|
|
2293
|
+
raise
|
|
2294
|
+
|
|
2295
|
+
assert option is not None
|
|
2296
|
+
assert type(option) == PostgresConfigurationOption_Base
|
|
2297
|
+
assert option.m_OptionData is optionData
|
|
2298
|
+
assert option.m_OptionData.IsAlive()
|
|
2299
|
+
return option
|
|
2300
|
+
|
|
2301
|
+
# --------------------------------------------------------------------
|
|
2302
|
+
def Helper__AddSimpleOption__File(
|
|
2303
|
+
self,
|
|
2304
|
+
fileData: PgCfgModel__FileData,
|
|
2305
|
+
optionName: str,
|
|
2306
|
+
optionValue: any,
|
|
2307
|
+
):
|
|
2308
|
+
assert fileData is not None
|
|
2309
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
2310
|
+
assert type(optionName) == str
|
|
2311
|
+
assert optionValue is not None
|
|
2312
|
+
|
|
2313
|
+
assert self.m_Data is not None
|
|
2314
|
+
assert type(self.m_Data) == PgCfgModel__ConfigurationData
|
|
2315
|
+
assert self.m_Data.m_AllOptionsByName is not None
|
|
2316
|
+
assert type(self.m_Data.m_AllOptionsByName) == dict
|
|
2317
|
+
|
|
2318
|
+
assert fileData.m_OptionsByName is not None
|
|
2319
|
+
assert type(fileData.m_OptionsByName) == dict
|
|
2320
|
+
|
|
2321
|
+
if optionName in fileData.m_OptionsByName.keys():
|
|
2322
|
+
assert fileData.m_OptionsByName[optionName] is not None
|
|
2323
|
+
RaiseError.OptionIsAlreadyExistInThisFile(fileData.m_Path, optionName)
|
|
2324
|
+
|
|
2325
|
+
if optionName in self.m_Data.m_AllOptionsByName.keys():
|
|
2326
|
+
assert self.m_Data.m_AllOptionsByName[optionName] is not None
|
|
2327
|
+
indexItem = self.m_Data.m_AllOptionsByName[optionName]
|
|
2328
|
+
optionData = Helpers.ExtractFirstOptionFromIndexItem(optionName, indexItem)
|
|
2329
|
+
|
|
2330
|
+
assert optionData is not None
|
|
2331
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2332
|
+
assert optionData.IsAlive()
|
|
2333
|
+
assert optionData.m_Name == optionName
|
|
2334
|
+
assert optionData.get_Parent() is not None
|
|
2335
|
+
assert type(optionData.get_Parent()) == PgCfgModel__FileLineData
|
|
2336
|
+
|
|
2337
|
+
anotherFileData = optionData.get_Parent().get_Parent()
|
|
2338
|
+
|
|
2339
|
+
assert anotherFileData is not None
|
|
2340
|
+
assert type(anotherFileData) == PgCfgModel__FileData
|
|
2341
|
+
assert anotherFileData is not fileData
|
|
2342
|
+
|
|
2343
|
+
RaiseError.OptionIsAlreadyExistInAnotherFile(
|
|
2344
|
+
anotherFileData.m_Path, optionName
|
|
2345
|
+
)
|
|
2346
|
+
|
|
2347
|
+
assert not (optionName in fileData.m_OptionsByName.keys())
|
|
2348
|
+
assert not (optionName in self.m_Data.m_AllOptionsByName.keys())
|
|
2349
|
+
|
|
2350
|
+
# OK. Let's add this option
|
|
2351
|
+
assert optionValue is not None
|
|
2352
|
+
|
|
2353
|
+
optionData = PgCfgModel__DataControllerUtils.File__add_Option(
|
|
2354
|
+
self.m_Data, fileData, optionName, optionValue
|
|
2355
|
+
)
|
|
2356
|
+
|
|
2357
|
+
assert optionData is not None
|
|
2358
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2359
|
+
|
|
2360
|
+
assert optionName in fileData.m_OptionsByName.keys()
|
|
2361
|
+
assert optionName in self.m_Data.m_AllOptionsByName.keys()
|
|
2362
|
+
|
|
2363
|
+
try:
|
|
2364
|
+
option = PostgresConfigurationFactory_Base.GetObject(self, optionData)
|
|
2365
|
+
|
|
2366
|
+
assert option is not None
|
|
2367
|
+
assert type(option) == PostgresConfigurationOption_Base
|
|
2368
|
+
assert option.m_OptionData is optionData
|
|
2369
|
+
except:
|
|
2370
|
+
PgCfgModel__DataControllerUtils.FileLine__delete(
|
|
2371
|
+
self.m_Data, optionData.get_Parent()
|
|
2372
|
+
)
|
|
2373
|
+
|
|
2374
|
+
assert not optionData.IsAlive()
|
|
2375
|
+
assert not (optionName in fileData.m_OptionsByName.keys())
|
|
2376
|
+
assert not (optionName in self.m_Data.m_AllOptionsByName.keys())
|
|
2377
|
+
raise
|
|
2378
|
+
|
|
2379
|
+
assert option is not None
|
|
2380
|
+
assert type(option) == PostgresConfigurationOption_Base
|
|
2381
|
+
assert option.m_OptionData is optionData
|
|
2382
|
+
assert option.m_OptionData.IsAlive()
|
|
2383
|
+
return option
|
|
2384
|
+
|
|
2385
|
+
# --------------------------------------------------------------------
|
|
2386
|
+
def Helper__SetSimpleOptionValue__Common(
|
|
2387
|
+
self,
|
|
2388
|
+
optionName: str,
|
|
2389
|
+
optionValue: any,
|
|
2390
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
2391
|
+
assert type(optionName) == str
|
|
2392
|
+
assert optionValue is not None
|
|
2393
|
+
|
|
2394
|
+
assert self.m_Data is not None
|
|
2395
|
+
assert type(self.m_Data) == PgCfgModel__ConfigurationData
|
|
2396
|
+
assert type(self.m_Data.m_AllOptionsByName) == dict
|
|
2397
|
+
|
|
2398
|
+
# ------------------------------------------------
|
|
2399
|
+
optionData = self.Helper__FindSimpleOption(
|
|
2400
|
+
self.m_Data.m_AllOptionsByName, optionName
|
|
2401
|
+
)
|
|
2402
|
+
|
|
2403
|
+
if optionData is not None:
|
|
2404
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2405
|
+
assert optionData.IsAlive()
|
|
2406
|
+
assert optionData.m_Name == optionName
|
|
2407
|
+
|
|
2408
|
+
PgCfgModel__DataControllerUtils.Option__set_Value(optionData, optionValue)
|
|
2409
|
+
|
|
2410
|
+
return PostgresConfigurationSetOptionValueResult_Base.Create__OptWasUpdated(
|
|
2411
|
+
self, optionData
|
|
2412
|
+
)
|
|
2413
|
+
|
|
2414
|
+
assert optionData is None
|
|
2415
|
+
|
|
2416
|
+
result = self.Helper__FinalRegSimpleOptionValue__Common(optionName, optionValue)
|
|
2417
|
+
|
|
2418
|
+
assert result is not None
|
|
2419
|
+
assert type(result) == PostgresConfigurationSetOptionValueResult_Base
|
|
2420
|
+
assert isinstance(result, PostgresConfigurationSetOptionValueResult)
|
|
2421
|
+
assert (
|
|
2422
|
+
result.m_EventID
|
|
2423
|
+
== PostgresConfigurationSetOptionValueEventID.OPTION_WAS_ADDED
|
|
2424
|
+
)
|
|
2425
|
+
assert result.m_OptData is not None
|
|
2426
|
+
assert type(result.m_OptData) == PgCfgModel__OptionData
|
|
2427
|
+
assert result.m_Cfg is self
|
|
2428
|
+
|
|
2429
|
+
return result
|
|
2430
|
+
|
|
2431
|
+
# --------------------------------------------------------------------
|
|
2432
|
+
def Helper__SetSimpleOptionValue__File(
|
|
2433
|
+
self,
|
|
2434
|
+
fileData: PgCfgModel__FileData,
|
|
2435
|
+
optionName: str,
|
|
2436
|
+
optionValue: any,
|
|
2437
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
2438
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
2439
|
+
assert type(fileData.m_OptionsByName) == dict
|
|
2440
|
+
assert type(optionName) == str
|
|
2441
|
+
assert optionValue is not None
|
|
2442
|
+
|
|
2443
|
+
# ------------------------------------------------
|
|
2444
|
+
optionData = self.Helper__FindSimpleOption(fileData.m_OptionsByName, optionName)
|
|
2445
|
+
|
|
2446
|
+
if optionData is not None:
|
|
2447
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2448
|
+
assert optionData.IsAlive()
|
|
2449
|
+
assert optionData.m_Name == optionName
|
|
2450
|
+
|
|
2451
|
+
PgCfgModel__DataControllerUtils.Option__set_Value(optionData, optionValue)
|
|
2452
|
+
|
|
2453
|
+
return PostgresConfigurationSetOptionValueResult_Base.Create__OptWasUpdated(
|
|
2454
|
+
self, optionData
|
|
2455
|
+
)
|
|
2456
|
+
|
|
2457
|
+
assert optionData is None
|
|
2458
|
+
|
|
2459
|
+
# Let's append this new option
|
|
2460
|
+
if optionName in self.m_Data.m_AllOptionsByName.keys():
|
|
2461
|
+
optionData = Helpers.ExtractFirstOptionFromIndexItem(
|
|
2462
|
+
optionName, self.m_Data.m_AllOptionsByName[optionName]
|
|
2463
|
+
)
|
|
2464
|
+
|
|
2465
|
+
assert optionData is not None
|
|
2466
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2467
|
+
assert optionData.IsAlive()
|
|
2468
|
+
assert optionData.m_Name == optionName
|
|
2469
|
+
assert type(optionData.m_Parent) == PgCfgModel__FileLineData
|
|
2470
|
+
assert optionData.m_Parent.IsAlive()
|
|
2471
|
+
assert type(optionData.m_Parent.m_Parent) == PgCfgModel__FileData
|
|
2472
|
+
assert optionData.m_Parent.m_Parent.IsAlive()
|
|
2473
|
+
|
|
2474
|
+
RaiseError.OptionIsAlreadyExistInAnotherFile(
|
|
2475
|
+
optionData.m_Parent.m_Parent.m_Path, optionName
|
|
2476
|
+
)
|
|
2477
|
+
|
|
2478
|
+
result = self.Helper__FinalRegSimpleOptionValue__File(
|
|
2479
|
+
fileData, optionName, optionValue
|
|
2480
|
+
)
|
|
2481
|
+
|
|
2482
|
+
assert result is not None
|
|
2483
|
+
assert type(result) == PostgresConfigurationSetOptionValueResult_Base
|
|
2484
|
+
assert (
|
|
2485
|
+
result.m_EventID
|
|
2486
|
+
== PostgresConfigurationSetOptionValueEventID.OPTION_WAS_ADDED
|
|
2487
|
+
)
|
|
2488
|
+
assert result.m_OptData is not None
|
|
2489
|
+
assert type(result.m_OptData) == PgCfgModel__OptionData
|
|
2490
|
+
assert result.m_OptData.IsAlive()
|
|
2491
|
+
assert result.m_OptData.m_Name == optionName
|
|
2492
|
+
return result
|
|
2493
|
+
|
|
2494
|
+
# --------------------------------------------------------------------
|
|
2495
|
+
def Helper__SetSimpleOptionValue__Exact(
|
|
2496
|
+
self,
|
|
2497
|
+
optionData: PgCfgModel__OptionData,
|
|
2498
|
+
optionValue: any,
|
|
2499
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
2500
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2501
|
+
assert optionData.IsAlive()
|
|
2502
|
+
assert optionValue is not None
|
|
2503
|
+
|
|
2504
|
+
# ------------------------------------------------
|
|
2505
|
+
self.Debug__CheckOurObjectData(optionData)
|
|
2506
|
+
|
|
2507
|
+
# ------------------------------------------------
|
|
2508
|
+
PgCfgModel__DataControllerUtils.Option__set_Value(optionData, optionValue)
|
|
2509
|
+
|
|
2510
|
+
return PostgresConfigurationSetOptionValueResult_Base.Create__OptWasUpdated(
|
|
2511
|
+
self, optionData
|
|
2512
|
+
)
|
|
2513
|
+
|
|
2514
|
+
# --------------------------------------------------------------------
|
|
2515
|
+
def Helper__SetUniqueOptionValueItem__Common(
|
|
2516
|
+
self,
|
|
2517
|
+
optionName: str,
|
|
2518
|
+
optionValueItem: any,
|
|
2519
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
2520
|
+
assert type(optionName) == str
|
|
2521
|
+
assert optionValueItem is not None
|
|
2522
|
+
|
|
2523
|
+
assert self.m_Data is not None
|
|
2524
|
+
assert type(self.m_Data) == PgCfgModel__ConfigurationData
|
|
2525
|
+
assert type(self.m_Data.m_AllOptionsByName) == dict
|
|
2526
|
+
|
|
2527
|
+
# ------------------------------------------------
|
|
2528
|
+
while True:
|
|
2529
|
+
if not (optionName in self.m_Data.m_AllOptionsByName.keys()):
|
|
2530
|
+
break
|
|
2531
|
+
|
|
2532
|
+
data = self.m_Data.m_AllOptionsByName[optionName]
|
|
2533
|
+
|
|
2534
|
+
typeOfData = type(data)
|
|
2535
|
+
|
|
2536
|
+
if typeOfData == PgCfgModel__OptionData:
|
|
2537
|
+
assert type(data) == PgCfgModel__OptionData
|
|
2538
|
+
assert data.m_Name == optionName
|
|
2539
|
+
assert data.m_Value is not None
|
|
2540
|
+
assert type(data.m_Value) == list
|
|
2541
|
+
|
|
2542
|
+
if __class__.Helper__DoesOptionValueAlreadyHaveThisUniqueItem(
|
|
2543
|
+
data, optionValueItem
|
|
2544
|
+
):
|
|
2545
|
+
return PostgresConfigurationSetOptionValueResult_Base.Create__OptValueItemWasAlreadyDefined(
|
|
2546
|
+
self, data
|
|
2547
|
+
)
|
|
2548
|
+
|
|
2549
|
+
PgCfgModel__DataControllerUtils.Option__add_ValueItem(
|
|
2550
|
+
data, optionValueItem
|
|
2551
|
+
)
|
|
2552
|
+
|
|
2553
|
+
return PostgresConfigurationSetOptionValueResult_Base.Create__OptValueItemWasAdded(
|
|
2554
|
+
self, data
|
|
2555
|
+
)
|
|
2556
|
+
|
|
2557
|
+
if typeOfData == list:
|
|
2558
|
+
assert type(data) == list
|
|
2559
|
+
assert len(data) > 1
|
|
2560
|
+
|
|
2561
|
+
for optionData in data:
|
|
2562
|
+
assert optionData is not None
|
|
2563
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2564
|
+
assert optionData.m_Name == optionName
|
|
2565
|
+
assert optionData.m_Value is not None
|
|
2566
|
+
assert type(optionData.m_Value) == list
|
|
2567
|
+
|
|
2568
|
+
if __class__.Helper__DoesOptionValueAlreadyHaveThisUniqueItem(
|
|
2569
|
+
optionData, optionValueItem
|
|
2570
|
+
):
|
|
2571
|
+
return PostgresConfigurationSetOptionValueResult_Base.Create__OptWithThisValueItemAlreadyExist(
|
|
2572
|
+
self, optionData
|
|
2573
|
+
)
|
|
2574
|
+
|
|
2575
|
+
# [2025-01-07] Postgres does not able to join multiple list
|
|
2576
|
+
# TODO: We have to take into account overriding the values of postgresql.conf
|
|
2577
|
+
BugCheckError.MultipleDefOfOptionIsFound(optionName, len(data))
|
|
2578
|
+
|
|
2579
|
+
BugCheckError.UnkOptObjectDataType(optionName, typeOfData)
|
|
2580
|
+
|
|
2581
|
+
# ------------------------------------------------
|
|
2582
|
+
assert not (optionName in self.m_Data.m_AllOptionsByName.keys())
|
|
2583
|
+
|
|
2584
|
+
# OK. Let's add a new option with list that contains our optionValueItem
|
|
2585
|
+
|
|
2586
|
+
result = self.Helper__FinalRegSimpleOptionValue__Common(
|
|
2587
|
+
optionName, [optionValueItem]
|
|
2588
|
+
)
|
|
2589
|
+
|
|
2590
|
+
assert result is not None
|
|
2591
|
+
assert type(result) == PostgresConfigurationSetOptionValueResult_Base
|
|
2592
|
+
assert isinstance(result, PostgresConfigurationSetOptionValueResult)
|
|
2593
|
+
assert (
|
|
2594
|
+
result.m_EventID
|
|
2595
|
+
== PostgresConfigurationSetOptionValueEventID.OPTION_WAS_ADDED
|
|
2596
|
+
)
|
|
2597
|
+
assert result.m_OptData is not None
|
|
2598
|
+
assert type(result.m_OptData) == PgCfgModel__OptionData
|
|
2599
|
+
assert result.m_OptData.m_Name == optionName
|
|
2600
|
+
assert result.m_Cfg is self
|
|
2601
|
+
|
|
2602
|
+
return result
|
|
2603
|
+
|
|
2604
|
+
# --------------------------------------------------------------------
|
|
2605
|
+
def Helper__SetUniqueOptionValueItem__Exact(
|
|
2606
|
+
self,
|
|
2607
|
+
optionData: PgCfgModel__OptionData,
|
|
2608
|
+
optionValueItem: any,
|
|
2609
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
2610
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2611
|
+
assert optionData.IsAlive()
|
|
2612
|
+
assert optionValueItem is not None
|
|
2613
|
+
|
|
2614
|
+
return self.Helper__SetUniqueOptionPreparedValueItem__Exact(
|
|
2615
|
+
optionData, optionValueItem
|
|
2616
|
+
)
|
|
2617
|
+
|
|
2618
|
+
# --------------------------------------------------------------------
|
|
2619
|
+
def Helper__SetUniqueOptionPreparedValueItem__Exact(
|
|
2620
|
+
self,
|
|
2621
|
+
optionData: PgCfgModel__OptionData,
|
|
2622
|
+
optionPreparedValueItem: any,
|
|
2623
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
2624
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2625
|
+
assert optionData.IsAlive()
|
|
2626
|
+
assert optionData.m_Value is not None
|
|
2627
|
+
assert type(optionData.m_Value) == list
|
|
2628
|
+
assert optionPreparedValueItem is not None
|
|
2629
|
+
|
|
2630
|
+
# ------------------------------------------------
|
|
2631
|
+
if __class__.Helper__DoesOptionValueAlreadyHaveThisUniqueItem(
|
|
2632
|
+
optionData, optionPreparedValueItem
|
|
2633
|
+
):
|
|
2634
|
+
return PostgresConfigurationSetOptionValueResult_Base.Create__OptValueItemWasAlreadyDefined(
|
|
2635
|
+
self, optionData
|
|
2636
|
+
)
|
|
2637
|
+
|
|
2638
|
+
# ------------------------------------------------
|
|
2639
|
+
self.Debug__CheckOurObjectData(optionData)
|
|
2640
|
+
|
|
2641
|
+
assert optionData.m_Name in self.m_Data.m_AllOptionsByName.keys()
|
|
2642
|
+
|
|
2643
|
+
data = self.m_Data.m_AllOptionsByName[optionData.m_Name]
|
|
2644
|
+
|
|
2645
|
+
typeOfData = type(data)
|
|
2646
|
+
|
|
2647
|
+
if typeOfData == PgCfgModel__OptionData:
|
|
2648
|
+
assert type(data) == PgCfgModel__OptionData
|
|
2649
|
+
# It is the single property!
|
|
2650
|
+
assert data is optionData
|
|
2651
|
+
assert type(data.m_Value) == list
|
|
2652
|
+
|
|
2653
|
+
PgCfgModel__DataControllerUtils.Option__add_ValueItem(
|
|
2654
|
+
data, optionPreparedValueItem
|
|
2655
|
+
)
|
|
2656
|
+
|
|
2657
|
+
return PostgresConfigurationSetOptionValueResult_Base.Create__OptValueItemWasAdded(
|
|
2658
|
+
self, data
|
|
2659
|
+
)
|
|
2660
|
+
|
|
2661
|
+
if typeOfData == list:
|
|
2662
|
+
assert type(data) == list
|
|
2663
|
+
assert len(data) > 1
|
|
2664
|
+
|
|
2665
|
+
for optionData2 in data:
|
|
2666
|
+
if optionData2 is optionData:
|
|
2667
|
+
continue
|
|
2668
|
+
|
|
2669
|
+
assert optionData2 is not None
|
|
2670
|
+
assert type(optionData2) == PgCfgModel__OptionData
|
|
2671
|
+
assert optionData2.IsAlive()
|
|
2672
|
+
assert optionData2.m_Name == optionData.m_Name
|
|
2673
|
+
assert optionData2.m_Value is not None
|
|
2674
|
+
assert type(optionData2.m_Value) == list
|
|
2675
|
+
assert optionData2.m_Parent.IsAlive()
|
|
2676
|
+
|
|
2677
|
+
fileData2 = optionData2.m_Parent.m_Parent
|
|
2678
|
+
assert type(fileData2) == PgCfgModel__FileData
|
|
2679
|
+
assert fileData2.IsAlive()
|
|
2680
|
+
|
|
2681
|
+
if __class__.Helper__DoesOptionValueAlreadyHaveThisUniqueItem(
|
|
2682
|
+
optionData2.m_Value, optionPreparedValueItem
|
|
2683
|
+
):
|
|
2684
|
+
RaiseError.OptionValueItemIsAlreadyDefined(
|
|
2685
|
+
fileData2.m_Path, optionData2.m_Name, optionPreparedValueItem
|
|
2686
|
+
)
|
|
2687
|
+
|
|
2688
|
+
# [2025-01-07] Postgres does not able to join multiple list
|
|
2689
|
+
# TODO: We have to take into account overriding the values of postgresql.conf
|
|
2690
|
+
BugCheckError.MultipleDefOfOptionIsFound(optionData.m_Name, len(data))
|
|
2691
|
+
|
|
2692
|
+
assert typeOfData != PgCfgModel__OptionData
|
|
2693
|
+
assert typeOfData != list
|
|
2694
|
+
|
|
2695
|
+
BugCheckError.UnkOptObjectDataType(optionData.m_Name, typeOfData)
|
|
2696
|
+
|
|
2697
|
+
# --------------------------------------------------------------------
|
|
2698
|
+
def Helper__SetUniqueOptionValueItem__File(
|
|
2699
|
+
self,
|
|
2700
|
+
fileData: PgCfgModel__FileData,
|
|
2701
|
+
optionName: str,
|
|
2702
|
+
optionValueItem: any,
|
|
2703
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
2704
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
2705
|
+
assert type(optionName) == str
|
|
2706
|
+
assert fileData.IsAlive()
|
|
2707
|
+
assert optionValueItem is not None
|
|
2708
|
+
|
|
2709
|
+
assert self.m_Data is not None
|
|
2710
|
+
assert type(self.m_Data) == PgCfgModel__ConfigurationData
|
|
2711
|
+
assert type(self.m_Data.m_AllOptionsByName) == dict
|
|
2712
|
+
|
|
2713
|
+
assert fileData.m_OptionsByName is not None
|
|
2714
|
+
assert type(fileData.m_OptionsByName) == dict
|
|
2715
|
+
|
|
2716
|
+
# ------------------------------------------------
|
|
2717
|
+
C_BUGCHECK_SRC = __class__.__name__ + "::Helper__SetUniqueOptionValueItem__File"
|
|
2718
|
+
|
|
2719
|
+
# ------------------------------------------------
|
|
2720
|
+
while True:
|
|
2721
|
+
if not (optionName in self.m_Data.m_AllOptionsByName.keys()):
|
|
2722
|
+
# It is an absolutely new option
|
|
2723
|
+
assert not (optionName in fileData.m_OptionsByName.keys())
|
|
2724
|
+
break
|
|
2725
|
+
|
|
2726
|
+
if optionName in fileData.m_OptionsByName.keys():
|
|
2727
|
+
data = fileData.m_OptionsByName[optionName]
|
|
2728
|
+
assert data is not None
|
|
2729
|
+
|
|
2730
|
+
typeOfData = type(data)
|
|
2731
|
+
|
|
2732
|
+
if typeOfData == PgCfgModel__OptionData:
|
|
2733
|
+
assert data.IsAlive()
|
|
2734
|
+
assert data.m_Name == optionName
|
|
2735
|
+
assert data.m_Value is not None
|
|
2736
|
+
assert type(data.m_Value) == list
|
|
2737
|
+
|
|
2738
|
+
if __class__.Helper__DoesOptionValueAlreadyHaveThisUniqueItem(
|
|
2739
|
+
data, optionValueItem
|
|
2740
|
+
):
|
|
2741
|
+
return PostgresConfigurationSetOptionValueResult_Base.Create__OptValueItemWasAlreadyDefined(
|
|
2742
|
+
self, data
|
|
2743
|
+
)
|
|
2744
|
+
|
|
2745
|
+
# this option value does not have this item
|
|
2746
|
+
|
|
2747
|
+
return self.Helper__SetUniqueOptionPreparedValueItem__Exact(
|
|
2748
|
+
data, optionValueItem
|
|
2749
|
+
)
|
|
2750
|
+
|
|
2751
|
+
assert typeOfData != PgCfgModel__OptionData
|
|
2752
|
+
|
|
2753
|
+
if typeOfData == list:
|
|
2754
|
+
assert type(data) == list
|
|
2755
|
+
assert len(data) > 1
|
|
2756
|
+
|
|
2757
|
+
for optionData in data:
|
|
2758
|
+
assert optionData is not None
|
|
2759
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2760
|
+
assert optionData.IsAlive()
|
|
2761
|
+
assert optionData.m_Name == optionName
|
|
2762
|
+
assert optionData.m_Value is not None
|
|
2763
|
+
assert type(optionData.m_Value) == list
|
|
2764
|
+
|
|
2765
|
+
if __class__.Helper__DoesOptionValueAlreadyHaveThisUniqueItem(
|
|
2766
|
+
optionData, optionValueItem
|
|
2767
|
+
):
|
|
2768
|
+
return PostgresConfigurationSetOptionValueResult_Base.Create__OptValueItemWasAlreadyDefined(
|
|
2769
|
+
self, optionData
|
|
2770
|
+
)
|
|
2771
|
+
|
|
2772
|
+
# Our optionValueItem is not found
|
|
2773
|
+
# Postgres does not support a concatention of option lists
|
|
2774
|
+
BugCheckError.MultipleDefOfOptionIsFound(optionName, len(data))
|
|
2775
|
+
|
|
2776
|
+
assert typeOfData != list
|
|
2777
|
+
|
|
2778
|
+
BugCheckError.UnkOptObjectDataType(optionName, typeOfData)
|
|
2779
|
+
|
|
2780
|
+
assert not (optionName in fileData.m_OptionsByName.keys())
|
|
2781
|
+
|
|
2782
|
+
assert optionName in self.m_Data.m_AllOptionsByName.keys()
|
|
2783
|
+
|
|
2784
|
+
data = self.m_Data.m_AllOptionsByName[optionName]
|
|
2785
|
+
assert data is not None
|
|
2786
|
+
|
|
2787
|
+
typeOfData = type(data)
|
|
2788
|
+
|
|
2789
|
+
if typeOfData == PgCfgModel__OptionData:
|
|
2790
|
+
assert type(data) == PgCfgModel__OptionData
|
|
2791
|
+
assert data.IsAlive()
|
|
2792
|
+
assert data.m_Name == optionName
|
|
2793
|
+
assert data.m_Value is not None
|
|
2794
|
+
assert type(data.m_Value) == list
|
|
2795
|
+
assert data.get_Parent().IsAlive()
|
|
2796
|
+
|
|
2797
|
+
fileData2 = data.get_Parent().get_Parent()
|
|
2798
|
+
assert fileData2 is not None
|
|
2799
|
+
assert type(fileData2) == PgCfgModel__FileData
|
|
2800
|
+
assert fileData2.IsAlive()
|
|
2801
|
+
assert not (fileData2 is fileData)
|
|
2802
|
+
|
|
2803
|
+
if __class__.Helper__DoesOptionValueAlreadyHaveThisUniqueItem(
|
|
2804
|
+
data, optionValueItem
|
|
2805
|
+
):
|
|
2806
|
+
RaiseError.OptionValueItemIsAlreadyDefinedInAnotherFile(
|
|
2807
|
+
fileData2.m_Path, optionName, optionValueItem
|
|
2808
|
+
)
|
|
2809
|
+
|
|
2810
|
+
RaiseError.OptionIsAlreadyExistInAnotherFile(
|
|
2811
|
+
fileData2.m_Path, optionName
|
|
2812
|
+
)
|
|
2813
|
+
|
|
2814
|
+
if typeOfData == list:
|
|
2815
|
+
assert type(data) == list
|
|
2816
|
+
assert len(data) > 1
|
|
2817
|
+
|
|
2818
|
+
for optionData2 in data:
|
|
2819
|
+
assert optionData2 is not None
|
|
2820
|
+
assert type(optionData2) == PgCfgModel__OptionData
|
|
2821
|
+
assert optionData2.IsAlive()
|
|
2822
|
+
assert optionData2.m_Name == optionName
|
|
2823
|
+
assert optionData2.m_Value is not None
|
|
2824
|
+
assert type(optionData2.m_Value) == list
|
|
2825
|
+
|
|
2826
|
+
fileData2 = optionData2.get_Parent().get_Parent()
|
|
2827
|
+
assert fileData2 is not None
|
|
2828
|
+
assert type(fileData2) == PgCfgModel__FileData
|
|
2829
|
+
assert fileData2.IsAlive()
|
|
2830
|
+
assert not (fileData2 is fileData)
|
|
2831
|
+
|
|
2832
|
+
if __class__.Helper__DoesOptionValueAlreadyHaveThisUniqueItem(
|
|
2833
|
+
optionData2, optionValueItem
|
|
2834
|
+
):
|
|
2835
|
+
RaiseError.OptionValueItemIsAlreadyDefinedInAnotherFile(
|
|
2836
|
+
fileData2.m_Path, optionName, optionValueItem
|
|
2837
|
+
)
|
|
2838
|
+
|
|
2839
|
+
RaiseError.OptionIsAlreadyExistInAnotherFile(
|
|
2840
|
+
fileData2.m_Path, optionName
|
|
2841
|
+
)
|
|
2842
|
+
|
|
2843
|
+
BugCheckError.UnexpectedSituation(
|
|
2844
|
+
C_BUGCHECK_SRC, "#001", "optionName=[{0}].".format(optionName)
|
|
2845
|
+
)
|
|
2846
|
+
|
|
2847
|
+
BugCheckError.UnkOptObjectDataType(optionName, typeOfData)
|
|
2848
|
+
|
|
2849
|
+
assert not (optionName is fileData.m_OptionsByName.keys())
|
|
2850
|
+
assert not (optionName in self.m_Data.m_AllOptionsByName.keys())
|
|
2851
|
+
|
|
2852
|
+
result = self.Helper__FinalRegSimpleOptionValue__File(
|
|
2853
|
+
fileData, optionName, [optionValueItem]
|
|
2854
|
+
)
|
|
2855
|
+
|
|
2856
|
+
assert result is not None
|
|
2857
|
+
assert type(result) == PostgresConfigurationSetOptionValueResult_Base
|
|
2858
|
+
assert (
|
|
2859
|
+
result.m_EventID
|
|
2860
|
+
== PostgresConfigurationSetOptionValueEventID.OPTION_WAS_ADDED
|
|
2861
|
+
)
|
|
2862
|
+
assert result.m_OptData is not None
|
|
2863
|
+
assert type(result.m_OptData) == PgCfgModel__OptionData
|
|
2864
|
+
assert result.m_OptData.IsAlive()
|
|
2865
|
+
assert result.m_OptData.m_Name == optionName
|
|
2866
|
+
return result
|
|
2867
|
+
|
|
2868
|
+
# --------------------------------------------------------------------
|
|
2869
|
+
def Helper__FinalRegSimpleOptionValue__Common(
|
|
2870
|
+
self,
|
|
2871
|
+
optionName: str,
|
|
2872
|
+
preparedOptionValue: any,
|
|
2873
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
2874
|
+
assert type(optionName) == str
|
|
2875
|
+
assert preparedOptionValue is not None
|
|
2876
|
+
|
|
2877
|
+
assert self.m_Data is not None
|
|
2878
|
+
assert type(self.m_Data) == PgCfgModel__ConfigurationData
|
|
2879
|
+
assert type(self.m_Data.m_AllOptionsByName) == dict
|
|
2880
|
+
|
|
2881
|
+
assert not (optionName in self.m_Data.m_AllOptionsByName.keys())
|
|
2882
|
+
|
|
2883
|
+
# Select the file to append this new option
|
|
2884
|
+
getFileData_r = self.Helper__GetFileForSimpleOption(optionName)
|
|
2885
|
+
|
|
2886
|
+
assert getFileData_r is not None
|
|
2887
|
+
assert type(getFileData_r) == tuple
|
|
2888
|
+
assert len(getFileData_r) == 2
|
|
2889
|
+
assert type(getFileData_r[0]) == PgCfgModel__FileData
|
|
2890
|
+
assert type(getFileData_r[1]) == bool
|
|
2891
|
+
|
|
2892
|
+
fileData = getFileData_r[0]
|
|
2893
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
2894
|
+
|
|
2895
|
+
try:
|
|
2896
|
+
result = self.Helper__FinalRegSimpleOptionValue__File(
|
|
2897
|
+
fileData, optionName, preparedOptionValue
|
|
2898
|
+
)
|
|
2899
|
+
except: # rollback file
|
|
2900
|
+
assert type(getFileData_r) == tuple
|
|
2901
|
+
assert len(getFileData_r) == 2
|
|
2902
|
+
|
|
2903
|
+
assert type(getFileData_r[0]) == PgCfgModel__FileData
|
|
2904
|
+
assert type(getFileData_r[1]) == bool
|
|
2905
|
+
|
|
2906
|
+
if getFileData_r[1]:
|
|
2907
|
+
pass # TODO: delete file
|
|
2908
|
+
|
|
2909
|
+
raise
|
|
2910
|
+
|
|
2911
|
+
assert result is not None
|
|
2912
|
+
assert type(result) == PostgresConfigurationSetOptionValueResult_Base
|
|
2913
|
+
assert (
|
|
2914
|
+
result.m_EventID
|
|
2915
|
+
== PostgresConfigurationSetOptionValueEventID.OPTION_WAS_ADDED
|
|
2916
|
+
)
|
|
2917
|
+
assert result.m_OptData is not None
|
|
2918
|
+
assert type(result.m_OptData) == PgCfgModel__OptionData
|
|
2919
|
+
assert result.m_OptData.IsAlive()
|
|
2920
|
+
assert result.m_OptData.m_Name == optionName
|
|
2921
|
+
return result
|
|
2922
|
+
|
|
2923
|
+
# --------------------------------------------------------------------
|
|
2924
|
+
def Helper__FinalRegSimpleOptionValue__File(
|
|
2925
|
+
self,
|
|
2926
|
+
fileData: PgCfgModel__FileData,
|
|
2927
|
+
optionName: str,
|
|
2928
|
+
preparedOptionValue: any,
|
|
2929
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
2930
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
2931
|
+
assert type(optionName) == str
|
|
2932
|
+
assert preparedOptionValue is not None
|
|
2933
|
+
|
|
2934
|
+
assert self.m_Data is not None
|
|
2935
|
+
assert type(self.m_Data) == PgCfgModel__ConfigurationData
|
|
2936
|
+
assert type(self.m_Data.m_AllOptionsByName) == dict
|
|
2937
|
+
|
|
2938
|
+
assert not (optionName in fileData.m_OptionsByName.keys())
|
|
2939
|
+
assert not (optionName in self.m_Data.m_AllOptionsByName.keys())
|
|
2940
|
+
|
|
2941
|
+
optionData = PgCfgModel__DataControllerUtils.File__add_Option(
|
|
2942
|
+
self.m_Data, fileData, optionName, preparedOptionValue
|
|
2943
|
+
)
|
|
2944
|
+
|
|
2945
|
+
assert optionData is not None
|
|
2946
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2947
|
+
assert optionData.IsAlive()
|
|
2948
|
+
assert optionData.m_Name == optionName
|
|
2949
|
+
assert type(optionData.m_Parent) == PgCfgModel__FileLineData
|
|
2950
|
+
assert optionData.m_Parent.m_Parent is fileData
|
|
2951
|
+
assert optionName in fileData.m_OptionsByName.keys()
|
|
2952
|
+
assert optionName in self.m_Data.m_AllOptionsByName.keys()
|
|
2953
|
+
|
|
2954
|
+
try:
|
|
2955
|
+
result = PostgresConfigurationSetOptionValueResult_Base.Create__OptWasAdded(
|
|
2956
|
+
self, optionData
|
|
2957
|
+
)
|
|
2958
|
+
assert result is not None
|
|
2959
|
+
assert type(result) == PostgresConfigurationSetOptionValueResult_Base
|
|
2960
|
+
assert (
|
|
2961
|
+
result.m_EventID
|
|
2962
|
+
== PostgresConfigurationSetOptionValueEventID.OPTION_WAS_ADDED
|
|
2963
|
+
)
|
|
2964
|
+
assert result.m_OptData is optionData
|
|
2965
|
+
except: # rollback line with option
|
|
2966
|
+
assert optionData.IsAlive()
|
|
2967
|
+
|
|
2968
|
+
PgCfgModel__DataControllerUtils.FileLine__delete(
|
|
2969
|
+
self.m_Data, optionData.get_Parent()
|
|
2970
|
+
)
|
|
2971
|
+
|
|
2972
|
+
assert not optionData.IsAlive()
|
|
2973
|
+
|
|
2974
|
+
assert not (optionName in fileData.m_OptionsByName.keys())
|
|
2975
|
+
assert not (optionName in self.m_Data.m_AllOptionsByName.keys())
|
|
2976
|
+
raise
|
|
2977
|
+
|
|
2978
|
+
assert result is not None
|
|
2979
|
+
assert type(result) == PostgresConfigurationSetOptionValueResult_Base
|
|
2980
|
+
assert (
|
|
2981
|
+
result.m_EventID
|
|
2982
|
+
== PostgresConfigurationSetOptionValueEventID.OPTION_WAS_ADDED
|
|
2983
|
+
)
|
|
2984
|
+
assert result.m_OptData is optionData
|
|
2985
|
+
|
|
2986
|
+
return result
|
|
2987
|
+
|
|
2988
|
+
# --------------------------------------------------------------------
|
|
2989
|
+
def Helper__DoesOptionValueAlreadyHaveThisUniqueItem(
|
|
2990
|
+
optionData: PgCfgModel__OptionData, optionValueItem: any
|
|
2991
|
+
) -> bool:
|
|
2992
|
+
assert optionData is not None
|
|
2993
|
+
assert optionValueItem is not None
|
|
2994
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
2995
|
+
assert optionData.IsAlive()
|
|
2996
|
+
assert optionData.m_Value is not None
|
|
2997
|
+
assert type(optionData.m_Value) == list
|
|
2998
|
+
|
|
2999
|
+
return Helpers.DoesContainerContainsValue__NotNullAndExact(
|
|
3000
|
+
optionData.m_Value, optionValueItem
|
|
3001
|
+
)
|
|
3002
|
+
|
|
3003
|
+
# Debug methods ------------------------------------------------------
|
|
3004
|
+
def Debug__CheckOurObjectData(self, data: PgCfgModel__ObjectData):
|
|
3005
|
+
assert data is not None
|
|
3006
|
+
assert isinstance(data, PgCfgModel__ObjectData)
|
|
3007
|
+
|
|
3008
|
+
stack: typing.Set[PgCfgModel__ObjectData] = set()
|
|
3009
|
+
assert type(stack) == set
|
|
3010
|
+
|
|
3011
|
+
ptr = data
|
|
3012
|
+
while ptr is not self.m_Data:
|
|
3013
|
+
assert ptr is not None
|
|
3014
|
+
assert isinstance(ptr, PgCfgModel__ObjectData)
|
|
3015
|
+
assert not (ptr in stack)
|
|
3016
|
+
stack.add(ptr)
|
|
3017
|
+
ptr = ptr.get_Parent()
|
|
3018
|
+
|
|
3019
|
+
|
|
3020
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
3021
|
+
# class PostgresConfigurationFactory_Base
|
|
3022
|
+
|
|
3023
|
+
|
|
3024
|
+
class PostgresConfigurationFactory_Base:
|
|
3025
|
+
def GetObject(
|
|
3026
|
+
cfg: PostgresConfiguration_Base, objectData: PgCfgModel__ObjectData
|
|
3027
|
+
) -> PostgresConfigurationObject:
|
|
3028
|
+
assert cfg is not None
|
|
3029
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
3030
|
+
assert objectData is not None
|
|
3031
|
+
assert isinstance(objectData, PgCfgModel__ObjectData)
|
|
3032
|
+
|
|
3033
|
+
# Build stack
|
|
3034
|
+
stack: typing.List[PostgresConfigurationObject] = []
|
|
3035
|
+
|
|
3036
|
+
while True:
|
|
3037
|
+
stack.append(objectData)
|
|
3038
|
+
|
|
3039
|
+
objectData = objectData.get_Parent()
|
|
3040
|
+
|
|
3041
|
+
if objectData is None:
|
|
3042
|
+
break
|
|
3043
|
+
|
|
3044
|
+
assert isinstance(objectData, PgCfgModel__ObjectData)
|
|
3045
|
+
|
|
3046
|
+
assert type(stack) == list
|
|
3047
|
+
assert len(stack) > 0
|
|
3048
|
+
|
|
3049
|
+
# Build ConfigurationObjects
|
|
3050
|
+
|
|
3051
|
+
cfgObject: PostgresConfigurationObject = None
|
|
3052
|
+
|
|
3053
|
+
while True:
|
|
3054
|
+
assert len(stack) > 0
|
|
3055
|
+
assert stack[-1] is not None
|
|
3056
|
+
assert isinstance(stack[-1], PgCfgModel__ObjectData)
|
|
3057
|
+
|
|
3058
|
+
cfgObject = __class__.Helper__CreateObject(cfg, stack[-1], cfgObject)
|
|
3059
|
+
assert cfgObject is not None
|
|
3060
|
+
assert isinstance(cfgObject, PostgresConfigurationObject)
|
|
3061
|
+
|
|
3062
|
+
stack.pop()
|
|
3063
|
+
|
|
3064
|
+
if len(stack) == 0:
|
|
3065
|
+
break
|
|
3066
|
+
|
|
3067
|
+
return cfgObject
|
|
3068
|
+
|
|
3069
|
+
# --------------------------------------------------------------------
|
|
3070
|
+
def Helper__CreateObject(
|
|
3071
|
+
cfg: PostgresConfiguration_Base,
|
|
3072
|
+
objectData: PgCfgModel__ObjectData,
|
|
3073
|
+
objectParent: PostgresConfigurationObject,
|
|
3074
|
+
) -> PostgresConfigurationObject:
|
|
3075
|
+
assert cfg is not None
|
|
3076
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
3077
|
+
assert objectData is not None
|
|
3078
|
+
assert isinstance(objectData, PgCfgModel__ObjectData)
|
|
3079
|
+
assert objectParent is None or isinstance(
|
|
3080
|
+
objectParent, PostgresConfigurationObject
|
|
3081
|
+
)
|
|
3082
|
+
|
|
3083
|
+
typeOfObjectData = type(objectData)
|
|
3084
|
+
assert typeOfObjectData is not None
|
|
3085
|
+
|
|
3086
|
+
if typeOfObjectData == PgCfgModel__ConfigurationData:
|
|
3087
|
+
assert objectData is cfg.m_Data
|
|
3088
|
+
return cfg
|
|
3089
|
+
|
|
3090
|
+
if typeOfObjectData == PgCfgModel__FileData:
|
|
3091
|
+
return __class__.Helper__CreateFile(objectData, objectParent)
|
|
3092
|
+
|
|
3093
|
+
if typeOfObjectData == PgCfgModel__FileLineData:
|
|
3094
|
+
return __class__.Helper__CreateFileLine(objectData, objectParent)
|
|
3095
|
+
|
|
3096
|
+
if typeOfObjectData == PgCfgModel__OptionData:
|
|
3097
|
+
return __class__.Helper__CreateOption(objectData, objectParent)
|
|
3098
|
+
|
|
3099
|
+
BugCheckError.UnkObjectDataType(typeOfObjectData)
|
|
3100
|
+
|
|
3101
|
+
# --------------------------------------------------------------------
|
|
3102
|
+
def Helper__CreateFile(
|
|
3103
|
+
objectData: PgCfgModel__FileData,
|
|
3104
|
+
objectParent: PostgresConfigurationObject,
|
|
3105
|
+
) -> PostgresConfigurationFile_Base:
|
|
3106
|
+
assert objectData is not None
|
|
3107
|
+
assert objectParent is not None
|
|
3108
|
+
assert type(objectData) == PgCfgModel__FileData
|
|
3109
|
+
assert isinstance(objectParent, PostgresConfigurationObject)
|
|
3110
|
+
|
|
3111
|
+
if isinstance(objectParent, PostgresConfiguration_Base):
|
|
3112
|
+
return PostgresConfigurationTopLevelFile_Base(objectParent, objectData)
|
|
3113
|
+
|
|
3114
|
+
assert not isinstance(objectParent, PostgresConfiguration)
|
|
3115
|
+
|
|
3116
|
+
RaiseError.MethodIsNotImplemented(__class__, "Helper__CreateFile")
|
|
3117
|
+
|
|
3118
|
+
# --------------------------------------------------------------------
|
|
3119
|
+
def Helper__CreateFileLine(
|
|
3120
|
+
objectData: PgCfgModel__FileLineData,
|
|
3121
|
+
objectParent: PostgresConfigurationObject,
|
|
3122
|
+
) -> PostgresConfigurationFile_Base:
|
|
3123
|
+
assert objectData is not None
|
|
3124
|
+
assert objectParent is not None
|
|
3125
|
+
assert type(objectData) == PgCfgModel__FileLineData
|
|
3126
|
+
assert isinstance(objectParent, PostgresConfigurationFile_Base)
|
|
3127
|
+
|
|
3128
|
+
return PostgresConfigurationFileLine_Base(objectParent, objectData)
|
|
3129
|
+
|
|
3130
|
+
# --------------------------------------------------------------------
|
|
3131
|
+
def Helper__CreateFileLineComment(
|
|
3132
|
+
fileLineDataItem: PgCfgModel__FileLineData.tagItem,
|
|
3133
|
+
fileLine: PostgresConfigurationObject,
|
|
3134
|
+
) -> PostgresConfigurationFile_Base:
|
|
3135
|
+
assert fileLineDataItem is not None
|
|
3136
|
+
assert fileLine is not None
|
|
3137
|
+
assert type(fileLineDataItem) == PgCfgModel__FileLineData.tagItem
|
|
3138
|
+
assert isinstance(fileLine, PostgresConfigurationFileLine_Base)
|
|
3139
|
+
|
|
3140
|
+
return PostgresConfigurationComment_Base(fileLine, fileLineDataItem)
|
|
3141
|
+
|
|
3142
|
+
# --------------------------------------------------------------------
|
|
3143
|
+
def Helper__CreateOption(
|
|
3144
|
+
objectData: PgCfgModel__OptionData,
|
|
3145
|
+
objectParent: PostgresConfigurationObject,
|
|
3146
|
+
) -> PostgresConfigurationFile_Base:
|
|
3147
|
+
assert objectData is not None
|
|
3148
|
+
assert objectParent is not None
|
|
3149
|
+
assert type(objectData) == PgCfgModel__OptionData
|
|
3150
|
+
assert isinstance(objectParent, PostgresConfigurationFileLine_Base)
|
|
3151
|
+
|
|
3152
|
+
return PostgresConfigurationOption_Base(objectParent, objectData)
|
|
3153
|
+
|
|
3154
|
+
|
|
3155
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
3156
|
+
# class PostgresConfigurationReader_Base
|
|
3157
|
+
|
|
3158
|
+
|
|
3159
|
+
class PostgresConfigurationReader_Base:
|
|
3160
|
+
def LoadConfigurationFile(
|
|
3161
|
+
cfg: PostgresConfiguration_Base, filePath: str
|
|
3162
|
+
) -> PostgresConfigurationTopLevelFile_Base:
|
|
3163
|
+
assert cfg is not None
|
|
3164
|
+
|
|
3165
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
3166
|
+
assert type(filePath) == str
|
|
3167
|
+
assert filePath != ""
|
|
3168
|
+
|
|
3169
|
+
existFileDatas: typing.Dict[str, PgCfgModel__FileData] = dict()
|
|
3170
|
+
|
|
3171
|
+
for fileName in cfg.m_Data.m_AllFilesByName.keys():
|
|
3172
|
+
assert type(fileName) == str
|
|
3173
|
+
assert fileName != ""
|
|
3174
|
+
|
|
3175
|
+
indexData = cfg.m_Data.m_AllFilesByName[fileName]
|
|
3176
|
+
assert indexData is not None
|
|
3177
|
+
|
|
3178
|
+
typeOfIndexData = type(indexData)
|
|
3179
|
+
|
|
3180
|
+
if typeOfIndexData == PgCfgModel__FileData:
|
|
3181
|
+
fileData: PgCfgModel__FileData = indexData
|
|
3182
|
+
assert type(fileData.m_Path) == str
|
|
3183
|
+
assert not (fileData.m_Path in existFileDatas.keys())
|
|
3184
|
+
existFileDatas[fileData.m_Path] = fileData
|
|
3185
|
+
continue
|
|
3186
|
+
|
|
3187
|
+
if typeOfIndexData == list:
|
|
3188
|
+
for fileData in indexData:
|
|
3189
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
3190
|
+
assert type(fileData.m_Path) == str
|
|
3191
|
+
assert not (fileData.m_Path in existFileDatas.keys())
|
|
3192
|
+
existFileDatas[fileData.m_Path] = fileData
|
|
3193
|
+
continue
|
|
3194
|
+
continue
|
|
3195
|
+
|
|
3196
|
+
BugCheckError.UnkFileObjectDataType(fileName, typeOfIndexData)
|
|
3197
|
+
|
|
3198
|
+
# ----------------------------------------------------------------
|
|
3199
|
+
filePath_n = Helpers.NormalizeFilePath(cfg.m_Data.OsOps, cfg.m_Data.m_DataDir, filePath)
|
|
3200
|
+
assert type(filePath_n) == str
|
|
3201
|
+
|
|
3202
|
+
if filePath_n in existFileDatas:
|
|
3203
|
+
return PostgresConfigurationFactory_Base.GetObject(
|
|
3204
|
+
cfg, existFileDatas[filePath_n]
|
|
3205
|
+
)
|
|
3206
|
+
|
|
3207
|
+
# ----------------------------------------------------------------
|
|
3208
|
+
rootFile = cfg.AddTopLevelFile(filePath)
|
|
3209
|
+
assert type(rootFile) == PostgresConfigurationTopLevelFile_Base
|
|
3210
|
+
assert type(rootFile.m_FileData) == PgCfgModel__FileData
|
|
3211
|
+
assert type(rootFile.m_FileData.m_Lines) == list
|
|
3212
|
+
assert rootFile.m_FileData.m_Status == PgCfgModel__FileStatus.IS_NEW
|
|
3213
|
+
assert rootFile.m_FileData.m_LastModifiedTimestamp is None
|
|
3214
|
+
assert len(rootFile.m_FileData.m_Lines) == 0
|
|
3215
|
+
|
|
3216
|
+
queuedFileDatas: typing.Set[PgCfgModel__FileData] = set()
|
|
3217
|
+
|
|
3218
|
+
queuedFileDatas.add(rootFile.m_FileData)
|
|
3219
|
+
|
|
3220
|
+
while len(queuedFileDatas) != 0:
|
|
3221
|
+
currentFileData = queuedFileDatas.pop()
|
|
3222
|
+
assert isinstance(currentFileData, PgCfgModel__FileData)
|
|
3223
|
+
|
|
3224
|
+
# load content
|
|
3225
|
+
# process content
|
|
3226
|
+
|
|
3227
|
+
with cfg.m_Data.OsOps.OpenFileToRead(currentFileData.m_Path) as f:
|
|
3228
|
+
assert isinstance(f, ConfigurationOsFile)
|
|
3229
|
+
currentFile = PostgresConfigurationFactory_Base.GetObject(
|
|
3230
|
+
cfg, currentFileData
|
|
3231
|
+
)
|
|
3232
|
+
__class__.Helper__LoadFileContent(currentFile, f) # raise
|
|
3233
|
+
|
|
3234
|
+
lastMDate = f.GetModificationTS()
|
|
3235
|
+
assert type(lastMDate) == datetime.datetime
|
|
3236
|
+
|
|
3237
|
+
currentFileData.m_LastModifiedTimestamp = lastMDate
|
|
3238
|
+
currentFileData.m_Status = PgCfgModel__FileStatus.EXISTS
|
|
3239
|
+
|
|
3240
|
+
assert not (currentFileData.m_Path in existFileDatas.keys())
|
|
3241
|
+
existFileDatas[currentFileData.m_Path] = currentFileData
|
|
3242
|
+
|
|
3243
|
+
# enumerate all the includes
|
|
3244
|
+
for fileLineData in currentFileData.m_Lines:
|
|
3245
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
3246
|
+
assert type(fileLineData.m_Items) == list
|
|
3247
|
+
|
|
3248
|
+
for fileLineItem in fileLineData.m_Items:
|
|
3249
|
+
assert type(fileLineItem) == PgCfgModel__FileLineData.tagItem
|
|
3250
|
+
|
|
3251
|
+
fileLineElementData = fileLineItem.m_Element
|
|
3252
|
+
|
|
3253
|
+
typeOfFileLineElementData = type(fileLineElementData)
|
|
3254
|
+
|
|
3255
|
+
if typeOfFileLineElementData == PgCfgModel__CommentData:
|
|
3256
|
+
continue
|
|
3257
|
+
|
|
3258
|
+
if typeOfFileLineElementData == PgCfgModel__OptionData:
|
|
3259
|
+
continue
|
|
3260
|
+
|
|
3261
|
+
if typeOfFileLineElementData == PgCfgModel__IncludeData:
|
|
3262
|
+
# look at existFileDatas
|
|
3263
|
+
includeData: PgCfgModel__IncludeData = fileLineElementData
|
|
3264
|
+
assert type(includeData.m_File) == PgCfgModel__FileData
|
|
3265
|
+
assert type(includeData.m_File.m_Path) == str
|
|
3266
|
+
|
|
3267
|
+
if includeData.m_File.m_Path in existFileDatas:
|
|
3268
|
+
continue # it is an old file
|
|
3269
|
+
|
|
3270
|
+
assert (
|
|
3271
|
+
includeData.m_File.m_Status == PgCfgModel__FileStatus.IS_NEW
|
|
3272
|
+
)
|
|
3273
|
+
assert includeData.m_File.m_LastModifiedTimestamp is None
|
|
3274
|
+
|
|
3275
|
+
if includeData.m_File in queuedFileDatas:
|
|
3276
|
+
continue # already in queue
|
|
3277
|
+
|
|
3278
|
+
queuedFileDatas.add(includeData.m_File)
|
|
3279
|
+
continue
|
|
3280
|
+
|
|
3281
|
+
BugCheckError.UnkObjectDataType(typeOfFileLineElementData)
|
|
3282
|
+
|
|
3283
|
+
assert len(queuedFileDatas) == 0
|
|
3284
|
+
assert isinstance(rootFile, PostgresConfigurationTopLevelFile_Base)
|
|
3285
|
+
|
|
3286
|
+
return rootFile
|
|
3287
|
+
|
|
3288
|
+
# --------------------------------------------------------------------
|
|
3289
|
+
def LoadFileContent(
|
|
3290
|
+
file: PostgresConfigurationFile_Base, fileContent: ConfigurationFileReader
|
|
3291
|
+
) -> None:
|
|
3292
|
+
assert isinstance(file, PostgresConfigurationFile_Base)
|
|
3293
|
+
assert isinstance(fileContent, ConfigurationFileReader)
|
|
3294
|
+
|
|
3295
|
+
return __class__.Helper__LoadFileContent(file, fileContent)
|
|
3296
|
+
|
|
3297
|
+
# Helper methods -----------------------------------------------------
|
|
3298
|
+
def Helper__LoadFileContent(
|
|
3299
|
+
file: PostgresConfigurationFile_Base, fileContent: ConfigurationFileReader
|
|
3300
|
+
) -> None:
|
|
3301
|
+
assert isinstance(file, PostgresConfigurationFile_Base)
|
|
3302
|
+
assert isinstance(fileContent, ConfigurationFileReader)
|
|
3303
|
+
|
|
3304
|
+
lineReader = ReadUtils__LineReader()
|
|
3305
|
+
|
|
3306
|
+
while True:
|
|
3307
|
+
lineData = fileContent.ReadLine()
|
|
3308
|
+
|
|
3309
|
+
if not lineData:
|
|
3310
|
+
assert lineData is None
|
|
3311
|
+
break
|
|
3312
|
+
|
|
3313
|
+
assert type(lineData) == str
|
|
3314
|
+
|
|
3315
|
+
lineReader.SetData(lineData)
|
|
3316
|
+
|
|
3317
|
+
__class__.Helper__ProcessLineData(file, lineReader)
|
|
3318
|
+
|
|
3319
|
+
# --------------------------------------------------------------------
|
|
3320
|
+
def Helper__ProcessLineData(
|
|
3321
|
+
file: PostgresConfigurationFile_Base, lineReader: ReadUtils__LineReader
|
|
3322
|
+
):
|
|
3323
|
+
assert isinstance(file, PostgresConfigurationFile_Base)
|
|
3324
|
+
assert type(lineReader) == ReadUtils__LineReader
|
|
3325
|
+
|
|
3326
|
+
fileLine = file.AddEmptyLine()
|
|
3327
|
+
assert type(fileLine) == PostgresConfigurationFileLine_Base
|
|
3328
|
+
|
|
3329
|
+
ch: typing.Optional[str]
|
|
3330
|
+
|
|
3331
|
+
while True:
|
|
3332
|
+
# skeep spaces
|
|
3333
|
+
while True:
|
|
3334
|
+
ch = lineReader.ReadSymbol()
|
|
3335
|
+
if ch is None:
|
|
3336
|
+
return
|
|
3337
|
+
|
|
3338
|
+
if ReadUtils.IsSpace(ch):
|
|
3339
|
+
continue
|
|
3340
|
+
|
|
3341
|
+
break
|
|
3342
|
+
|
|
3343
|
+
assert not ReadUtils.IsSpace(ch)
|
|
3344
|
+
|
|
3345
|
+
if ReadUtils.IsEOL(ch):
|
|
3346
|
+
return
|
|
3347
|
+
|
|
3348
|
+
if ch == "#":
|
|
3349
|
+
return __class__.Helper__ProcessLineData__Comment(fileLine, lineReader)
|
|
3350
|
+
|
|
3351
|
+
if len(fileLine) == 0 and ReadUtils.IsValidSeqCh1(ch):
|
|
3352
|
+
# Read sequence
|
|
3353
|
+
sequenceOffset = lineReader.GetColOffset()
|
|
3354
|
+
sequence = ch
|
|
3355
|
+
|
|
3356
|
+
while True:
|
|
3357
|
+
ch = lineReader.ReadSymbol()
|
|
3358
|
+
|
|
3359
|
+
if not ch:
|
|
3360
|
+
assert ch is None
|
|
3361
|
+
break
|
|
3362
|
+
|
|
3363
|
+
assert type(ch) == str
|
|
3364
|
+
|
|
3365
|
+
if ReadUtils.IsValidSeqCh2(ch):
|
|
3366
|
+
sequence += ch
|
|
3367
|
+
continue
|
|
3368
|
+
|
|
3369
|
+
if ch == ".":
|
|
3370
|
+
sequence += ch
|
|
3371
|
+
continue
|
|
3372
|
+
|
|
3373
|
+
break
|
|
3374
|
+
|
|
3375
|
+
if sequence.lower() == "include":
|
|
3376
|
+
if ch is not None:
|
|
3377
|
+
lineReader.StepBack()
|
|
3378
|
+
|
|
3379
|
+
__class__.Helper__ProcessLineData__Include(
|
|
3380
|
+
fileLine, lineReader, sequenceOffset
|
|
3381
|
+
)
|
|
3382
|
+
else:
|
|
3383
|
+
if ch is not None:
|
|
3384
|
+
lineReader.StepBack()
|
|
3385
|
+
|
|
3386
|
+
__class__.Helper__ProcessLineData__Option(
|
|
3387
|
+
fileLine, lineReader, sequenceOffset, sequence
|
|
3388
|
+
)
|
|
3389
|
+
continue
|
|
3390
|
+
|
|
3391
|
+
RaiseError.CfgReader__UnexpectedSymbol(
|
|
3392
|
+
lineReader.GetLineNum(), lineReader.GetColNum(), ch
|
|
3393
|
+
)
|
|
3394
|
+
|
|
3395
|
+
# --------------------------------------------------------------------
|
|
3396
|
+
def Helper__ProcessLineData__Comment(
|
|
3397
|
+
fileLine: PostgresConfigurationFileLine_Base, lineReader: ReadUtils__LineReader
|
|
3398
|
+
):
|
|
3399
|
+
assert type(fileLine) == PostgresConfigurationFileLine_Base
|
|
3400
|
+
assert type(lineReader) == ReadUtils__LineReader
|
|
3401
|
+
|
|
3402
|
+
commentText = ""
|
|
3403
|
+
commentOffset = lineReader.GetColOffset()
|
|
3404
|
+
|
|
3405
|
+
while True:
|
|
3406
|
+
ch = lineReader.ReadSymbol()
|
|
3407
|
+
|
|
3408
|
+
if not ch:
|
|
3409
|
+
assert ch is None
|
|
3410
|
+
break
|
|
3411
|
+
|
|
3412
|
+
assert type(ch) == str
|
|
3413
|
+
|
|
3414
|
+
if ReadUtils.IsEOL(ch):
|
|
3415
|
+
break
|
|
3416
|
+
commentText += ch
|
|
3417
|
+
|
|
3418
|
+
fileLine.AddComment(commentText, commentOffset)
|
|
3419
|
+
|
|
3420
|
+
# --------------------------------------------------------------------
|
|
3421
|
+
def Helper__ProcessLineData__Include(
|
|
3422
|
+
fileLine: PostgresConfigurationFileLine_Base,
|
|
3423
|
+
lineReader: ReadUtils__LineReader,
|
|
3424
|
+
includeOffset: int,
|
|
3425
|
+
):
|
|
3426
|
+
assert type(fileLine) == PostgresConfigurationFileLine_Base
|
|
3427
|
+
assert type(lineReader) == ReadUtils__LineReader
|
|
3428
|
+
assert type(includeOffset) == int
|
|
3429
|
+
assert includeOffset >= 0
|
|
3430
|
+
|
|
3431
|
+
# find first quote
|
|
3432
|
+
while True:
|
|
3433
|
+
ch = lineReader.ReadSymbol()
|
|
3434
|
+
|
|
3435
|
+
if ch is None or ReadUtils.IsEOL(ch) or ch == "#":
|
|
3436
|
+
RaiseError.CfgReader__IncludeWithoutPath(lineReader.GetLineNum())
|
|
3437
|
+
|
|
3438
|
+
if ReadUtils.IsSpace(ch):
|
|
3439
|
+
continue
|
|
3440
|
+
|
|
3441
|
+
if ch == "'":
|
|
3442
|
+
break
|
|
3443
|
+
|
|
3444
|
+
RaiseError.CfgReader__UnexpectedSymbol(
|
|
3445
|
+
lineReader.GetLineNum(), lineReader.GetColNum(), ch
|
|
3446
|
+
)
|
|
3447
|
+
|
|
3448
|
+
# OK. First quote is found!
|
|
3449
|
+
|
|
3450
|
+
# Let's process this quoted string
|
|
3451
|
+
filePath = ""
|
|
3452
|
+
|
|
3453
|
+
while True:
|
|
3454
|
+
ch = lineReader.ReadSymbol()
|
|
3455
|
+
|
|
3456
|
+
if ch is None or ReadUtils.IsEOL(ch):
|
|
3457
|
+
RaiseError.CfgReader__EndOfIncludePathIsNotFound(
|
|
3458
|
+
lineReader.GetLineNum()
|
|
3459
|
+
)
|
|
3460
|
+
break
|
|
3461
|
+
|
|
3462
|
+
if ch == "'":
|
|
3463
|
+
ch2 = lineReader.ReadSymbol()
|
|
3464
|
+
|
|
3465
|
+
if ch2 is None:
|
|
3466
|
+
break
|
|
3467
|
+
|
|
3468
|
+
if ReadUtils.IsEOL(ch2):
|
|
3469
|
+
lineReader.StepBack()
|
|
3470
|
+
break
|
|
3471
|
+
|
|
3472
|
+
if ch2 == "'":
|
|
3473
|
+
filePath += ch
|
|
3474
|
+
continue
|
|
3475
|
+
|
|
3476
|
+
break
|
|
3477
|
+
|
|
3478
|
+
if ch == "\\":
|
|
3479
|
+
ch = lineReader.ReadSymbol()
|
|
3480
|
+
|
|
3481
|
+
if ch is None or ReadUtils.IsEOL(ch):
|
|
3482
|
+
RaiseError.CfgReader__IncompletedEscapeInInclude(
|
|
3483
|
+
lineReader.GetLineNum()
|
|
3484
|
+
)
|
|
3485
|
+
|
|
3486
|
+
if ch == "b":
|
|
3487
|
+
filePath += "\b"
|
|
3488
|
+
elif ch == "f":
|
|
3489
|
+
filePath += "\f"
|
|
3490
|
+
elif ch == "n":
|
|
3491
|
+
filePath += "\n"
|
|
3492
|
+
elif ch == "r":
|
|
3493
|
+
filePath += "\r"
|
|
3494
|
+
elif ch == "t":
|
|
3495
|
+
filePath += "\t"
|
|
3496
|
+
elif ch == "'":
|
|
3497
|
+
filePath += "'"
|
|
3498
|
+
elif ch == '"':
|
|
3499
|
+
filePath += '"'
|
|
3500
|
+
elif ch >= "0" and ch <= "7": # octNumber
|
|
3501
|
+
octVal = 0
|
|
3502
|
+
|
|
3503
|
+
octVal_n = 1
|
|
3504
|
+
|
|
3505
|
+
while True:
|
|
3506
|
+
d = int(ord(ch) - ord("0"))
|
|
3507
|
+
assert d >= 0 and d <= 7
|
|
3508
|
+
|
|
3509
|
+
octVal = (octVal * 8) + d
|
|
3510
|
+
|
|
3511
|
+
if octVal_n == 3:
|
|
3512
|
+
break
|
|
3513
|
+
|
|
3514
|
+
ch = lineReader.ReadSymbol()
|
|
3515
|
+
|
|
3516
|
+
if ch is None:
|
|
3517
|
+
break
|
|
3518
|
+
|
|
3519
|
+
if not (ch >= "0" and ch <= "7"):
|
|
3520
|
+
lineReader.StepBack()
|
|
3521
|
+
break
|
|
3522
|
+
|
|
3523
|
+
octVal_n += 1
|
|
3524
|
+
continue
|
|
3525
|
+
|
|
3526
|
+
filePath += chr(octVal)
|
|
3527
|
+
else:
|
|
3528
|
+
RaiseError.CfgReader__UnknownEscapedSymbolInInclude(
|
|
3529
|
+
lineReader.GetLineNum(), lineReader.GetColNum(), ch
|
|
3530
|
+
)
|
|
3531
|
+
|
|
3532
|
+
continue
|
|
3533
|
+
|
|
3534
|
+
filePath += ch
|
|
3535
|
+
continue
|
|
3536
|
+
|
|
3537
|
+
assert type(filePath) == str
|
|
3538
|
+
|
|
3539
|
+
if len(filePath) == 0:
|
|
3540
|
+
RaiseError.CfgReader__IncludeHasEmptyPath(lineReader.GetLineNum())
|
|
3541
|
+
|
|
3542
|
+
fileLine.AddInclude(filePath, includeOffset)
|
|
3543
|
+
|
|
3544
|
+
# --------------------------------------------------------------------
|
|
3545
|
+
def Helper__ProcessLineData__Option(
|
|
3546
|
+
fileLine: PostgresConfigurationFileLine_Base,
|
|
3547
|
+
lineReader: ReadUtils__LineReader,
|
|
3548
|
+
optionOffset: int,
|
|
3549
|
+
optionName: str,
|
|
3550
|
+
):
|
|
3551
|
+
assert type(fileLine) == PostgresConfigurationFileLine_Base
|
|
3552
|
+
assert type(lineReader) == ReadUtils__LineReader
|
|
3553
|
+
assert type(optionOffset) == int
|
|
3554
|
+
assert type(optionName) == str
|
|
3555
|
+
assert optionName != ""
|
|
3556
|
+
|
|
3557
|
+
# skeep spaces
|
|
3558
|
+
spaceIsDetected = False
|
|
3559
|
+
|
|
3560
|
+
while True:
|
|
3561
|
+
ch = lineReader.ReadSymbol()
|
|
3562
|
+
if ch is None or ReadUtils.IsEOL(ch) or ch == "#":
|
|
3563
|
+
RaiseError.CfgReader__OptionWithoutValue(
|
|
3564
|
+
optionName, lineReader.GetLineNum()
|
|
3565
|
+
)
|
|
3566
|
+
|
|
3567
|
+
if ReadUtils.IsSpace(ch):
|
|
3568
|
+
spaceIsDetected = True
|
|
3569
|
+
continue
|
|
3570
|
+
|
|
3571
|
+
if ch == "=":
|
|
3572
|
+
while True:
|
|
3573
|
+
ch = lineReader.ReadSymbol()
|
|
3574
|
+
|
|
3575
|
+
if ch is None or ReadUtils.IsEOL(ch) or ch == "#":
|
|
3576
|
+
RaiseError.CfgReader__OptionWithoutValue(
|
|
3577
|
+
optionName, lineReader.GetLineNum()
|
|
3578
|
+
)
|
|
3579
|
+
|
|
3580
|
+
if ReadUtils.IsSpace(ch):
|
|
3581
|
+
continue
|
|
3582
|
+
|
|
3583
|
+
break
|
|
3584
|
+
break
|
|
3585
|
+
|
|
3586
|
+
if spaceIsDetected:
|
|
3587
|
+
break
|
|
3588
|
+
|
|
3589
|
+
RaiseError.CfgReader__UnexpectedSymbol(
|
|
3590
|
+
lineReader.GetLineNum(), lineReader.GetColNum(), ch
|
|
3591
|
+
)
|
|
3592
|
+
|
|
3593
|
+
# ch is the first symbol of option value.
|
|
3594
|
+
|
|
3595
|
+
if ch == "'":
|
|
3596
|
+
__class__.Helper__ProcessLineData__Option__Quoted(
|
|
3597
|
+
fileLine, lineReader, optionOffset, optionName
|
|
3598
|
+
)
|
|
3599
|
+
else:
|
|
3600
|
+
lineReader.StepBack()
|
|
3601
|
+
|
|
3602
|
+
__class__.Helper__ProcessLineData__Option__Generic(
|
|
3603
|
+
fileLine, lineReader, optionOffset, optionName
|
|
3604
|
+
)
|
|
3605
|
+
|
|
3606
|
+
# --------------------------------------------------------------------
|
|
3607
|
+
def Helper__ProcessLineData__Option__Quoted(
|
|
3608
|
+
fileLine: PostgresConfigurationFileLine_Base,
|
|
3609
|
+
lineReader: ReadUtils__LineReader,
|
|
3610
|
+
optionOffset: int,
|
|
3611
|
+
optionName: str,
|
|
3612
|
+
):
|
|
3613
|
+
assert type(fileLine) == PostgresConfigurationFileLine_Base
|
|
3614
|
+
assert type(lineReader) == ReadUtils__LineReader
|
|
3615
|
+
assert type(optionOffset) == int
|
|
3616
|
+
assert type(optionName) == str
|
|
3617
|
+
assert optionName != ""
|
|
3618
|
+
|
|
3619
|
+
optionValue = ""
|
|
3620
|
+
|
|
3621
|
+
while True:
|
|
3622
|
+
ch = lineReader.ReadSymbol()
|
|
3623
|
+
|
|
3624
|
+
if ch is None or ReadUtils.IsEOL(ch):
|
|
3625
|
+
RaiseError.CfgReader__EndQuotedOptionValueIsNotFound(
|
|
3626
|
+
optionName, lineReader.GetLineNum()
|
|
3627
|
+
)
|
|
3628
|
+
break
|
|
3629
|
+
|
|
3630
|
+
if ch == "'":
|
|
3631
|
+
ch2 = lineReader.ReadSymbol()
|
|
3632
|
+
|
|
3633
|
+
if ch2 is None:
|
|
3634
|
+
break
|
|
3635
|
+
|
|
3636
|
+
if ReadUtils.IsEOL(ch2):
|
|
3637
|
+
lineReader.StepBack()
|
|
3638
|
+
break
|
|
3639
|
+
|
|
3640
|
+
if ch2 == "'":
|
|
3641
|
+
optionValue += ch
|
|
3642
|
+
continue
|
|
3643
|
+
|
|
3644
|
+
break
|
|
3645
|
+
|
|
3646
|
+
if ch == "\\":
|
|
3647
|
+
ch = lineReader.ReadSymbol()
|
|
3648
|
+
|
|
3649
|
+
if ch is None or ReadUtils.IsEOL(ch):
|
|
3650
|
+
RaiseError.CfgReader__IncompletedEscapeInQuotedOptionValue(
|
|
3651
|
+
optionName, lineReader.GetLineNum()
|
|
3652
|
+
)
|
|
3653
|
+
|
|
3654
|
+
if ch == "b":
|
|
3655
|
+
optionValue += "\b"
|
|
3656
|
+
elif ch == "f":
|
|
3657
|
+
optionValue += "\f"
|
|
3658
|
+
elif ch == "n":
|
|
3659
|
+
optionValue += "\n"
|
|
3660
|
+
elif ch == "r":
|
|
3661
|
+
optionValue += "\r"
|
|
3662
|
+
elif ch == "t":
|
|
3663
|
+
optionValue += "\t"
|
|
3664
|
+
elif ch == "'":
|
|
3665
|
+
optionValue += "'"
|
|
3666
|
+
elif ch == '"':
|
|
3667
|
+
optionValue += '"'
|
|
3668
|
+
elif ch >= "0" and ch <= "7": # octNumber
|
|
3669
|
+
octVal = 0
|
|
3670
|
+
|
|
3671
|
+
octVal_n = 1
|
|
3672
|
+
|
|
3673
|
+
while True:
|
|
3674
|
+
d = int(ord(ch) - ord("0"))
|
|
3675
|
+
assert d >= 0 and d <= 7
|
|
3676
|
+
|
|
3677
|
+
octVal = (octVal * 8) + d
|
|
3678
|
+
|
|
3679
|
+
if octVal_n == 3:
|
|
3680
|
+
break
|
|
3681
|
+
|
|
3682
|
+
ch = lineReader.ReadSymbol()
|
|
3683
|
+
|
|
3684
|
+
if ch is None:
|
|
3685
|
+
break
|
|
3686
|
+
|
|
3687
|
+
if not (ch >= "0" and ch <= "7"):
|
|
3688
|
+
lineReader.StepBack()
|
|
3689
|
+
break
|
|
3690
|
+
|
|
3691
|
+
octVal_n += 1
|
|
3692
|
+
continue
|
|
3693
|
+
|
|
3694
|
+
optionValue += chr(octVal)
|
|
3695
|
+
else:
|
|
3696
|
+
RaiseError.CfgReader__UnknownEscapedSymbolInQuotedOptionValue(
|
|
3697
|
+
optionName, lineReader.GetLineNum(), lineReader.GetColNum(), ch
|
|
3698
|
+
)
|
|
3699
|
+
|
|
3700
|
+
continue
|
|
3701
|
+
|
|
3702
|
+
optionValue += ch
|
|
3703
|
+
continue
|
|
3704
|
+
|
|
3705
|
+
assert type(optionValue) == str
|
|
3706
|
+
|
|
3707
|
+
fileLine.AddOption(optionName, optionValue, optionOffset)
|
|
3708
|
+
|
|
3709
|
+
# --------------------------------------------------------------------
|
|
3710
|
+
def Helper__ProcessLineData__Option__Generic(
|
|
3711
|
+
fileLine: PostgresConfigurationFileLine_Base,
|
|
3712
|
+
lineReader: ReadUtils__LineReader,
|
|
3713
|
+
optionOffset: int,
|
|
3714
|
+
optionName: str,
|
|
3715
|
+
):
|
|
3716
|
+
assert type(fileLine) == PostgresConfigurationFileLine_Base
|
|
3717
|
+
assert type(lineReader) == ReadUtils__LineReader
|
|
3718
|
+
assert type(optionOffset) == int
|
|
3719
|
+
assert type(optionName) == str
|
|
3720
|
+
assert optionName != ""
|
|
3721
|
+
|
|
3722
|
+
optionValue = ""
|
|
3723
|
+
|
|
3724
|
+
while True:
|
|
3725
|
+
ch = lineReader.ReadSymbol()
|
|
3726
|
+
|
|
3727
|
+
if not ch:
|
|
3728
|
+
assert ch is None
|
|
3729
|
+
break
|
|
3730
|
+
|
|
3731
|
+
assert type(ch) == str
|
|
3732
|
+
|
|
3733
|
+
if ch == "#" or ReadUtils.IsEOL(ch):
|
|
3734
|
+
lineReader.StepBack()
|
|
3735
|
+
break
|
|
3736
|
+
|
|
3737
|
+
optionValue += ch
|
|
3738
|
+
continue
|
|
3739
|
+
|
|
3740
|
+
optionValue = optionValue.strip()
|
|
3741
|
+
|
|
3742
|
+
assert type(optionValue) == str
|
|
3743
|
+
assert optionValue != ""
|
|
3744
|
+
|
|
3745
|
+
fileLine.AddOption(optionName, optionValue, optionOffset)
|
|
3746
|
+
|
|
3747
|
+
|
|
3748
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
3749
|
+
# class PostgresConfigurationWriterFileCtx_Base
|
|
3750
|
+
|
|
3751
|
+
|
|
3752
|
+
class PostgresConfigurationWriterFileCtx_Base:
|
|
3753
|
+
FileData: PgCfgModel__FileData
|
|
3754
|
+
Content: typing.Optional[str]
|
|
3755
|
+
File: typing.Optional[ConfigurationOsFile]
|
|
3756
|
+
|
|
3757
|
+
# TODO: We can use filelock (it is a separated lock file)
|
|
3758
|
+
# to provide an exclusive access to our File
|
|
3759
|
+
|
|
3760
|
+
# --------------------------------------------------------------------
|
|
3761
|
+
def __init__(self, fileData: PgCfgModel__FileData):
|
|
3762
|
+
assert fileData is not None
|
|
3763
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
3764
|
+
|
|
3765
|
+
self.FileData = fileData
|
|
3766
|
+
self.Content = None
|
|
3767
|
+
self.File = None
|
|
3768
|
+
|
|
3769
|
+
|
|
3770
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
3771
|
+
# class PostgresConfigurationWriterCtx_Base
|
|
3772
|
+
|
|
3773
|
+
|
|
3774
|
+
class PostgresConfigurationWriterCtx_Base:
|
|
3775
|
+
Cfg: PostgresConfiguration_Base
|
|
3776
|
+
|
|
3777
|
+
AllFiles: list[PostgresConfigurationWriterFileCtx_Base]
|
|
3778
|
+
NewFiles: list[PostgresConfigurationWriterFileCtx_Base]
|
|
3779
|
+
UpdFiles: list[PostgresConfigurationWriterFileCtx_Base]
|
|
3780
|
+
|
|
3781
|
+
# --------------------------------------------------------------------
|
|
3782
|
+
def __init__(self, cfg: PostgresConfiguration_Base):
|
|
3783
|
+
assert cfg is not None
|
|
3784
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
3785
|
+
|
|
3786
|
+
self.Cfg = cfg
|
|
3787
|
+
|
|
3788
|
+
self.AllFiles = list()
|
|
3789
|
+
self.NewFiles = list()
|
|
3790
|
+
self.UpdFiles = list()
|
|
3791
|
+
|
|
3792
|
+
assert type(self.AllFiles) == list
|
|
3793
|
+
assert type(self.NewFiles) == list
|
|
3794
|
+
assert type(self.UpdFiles) == list
|
|
3795
|
+
|
|
3796
|
+
# --------------------------------------------------------------------
|
|
3797
|
+
def Init(self):
|
|
3798
|
+
assert type(self.AllFiles) == list
|
|
3799
|
+
assert type(self.NewFiles) == list
|
|
3800
|
+
assert type(self.UpdFiles) == list
|
|
3801
|
+
|
|
3802
|
+
self.AllFiles.clear()
|
|
3803
|
+
self.NewFiles.clear()
|
|
3804
|
+
self.UpdFiles.clear()
|
|
3805
|
+
|
|
3806
|
+
|
|
3807
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
3808
|
+
# class PostgresConfigurationWriter_Base
|
|
3809
|
+
|
|
3810
|
+
|
|
3811
|
+
class PostgresConfigurationWriter_Base:
|
|
3812
|
+
def MakeFileDataContent(
|
|
3813
|
+
ctx: PostgresConfigurationWriterCtx_Base, fileData: PgCfgModel__FileData
|
|
3814
|
+
) -> str:
|
|
3815
|
+
assert type(ctx) == PostgresConfigurationWriterCtx_Base
|
|
3816
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
3817
|
+
|
|
3818
|
+
return __class__.Helper__MakeFileDataContent(ctx, fileData)
|
|
3819
|
+
|
|
3820
|
+
# --------------------------------------------------------------------
|
|
3821
|
+
def DoWork(ctx: PostgresConfigurationWriterCtx_Base):
|
|
3822
|
+
assert type(ctx) == PostgresConfigurationWriterCtx_Base
|
|
3823
|
+
assert isinstance(ctx.Cfg, PostgresConfiguration_Base)
|
|
3824
|
+
assert type(ctx.Cfg.m_Data) == PgCfgModel__ConfigurationData
|
|
3825
|
+
|
|
3826
|
+
return __class__.Helper__DoWork(ctx)
|
|
3827
|
+
|
|
3828
|
+
# Helper Methods -----------------------------------------------------
|
|
3829
|
+
def Helper__DoWork(ctx: PostgresConfigurationWriterCtx_Base):
|
|
3830
|
+
assert type(ctx) == PostgresConfigurationWriterCtx_Base
|
|
3831
|
+
assert isinstance(ctx.Cfg, PostgresConfiguration_Base)
|
|
3832
|
+
assert type(ctx.Cfg.m_Data) == PgCfgModel__ConfigurationData
|
|
3833
|
+
|
|
3834
|
+
# 0.
|
|
3835
|
+
ctx.Init()
|
|
3836
|
+
|
|
3837
|
+
# 1.
|
|
3838
|
+
__class__.Helper__DoWork__Stage01__CreateFileContexts(ctx)
|
|
3839
|
+
|
|
3840
|
+
# 2.
|
|
3841
|
+
__class__.Helper__DoWork__Stage02__MakeFileDataContents(ctx)
|
|
3842
|
+
|
|
3843
|
+
# 3.
|
|
3844
|
+
__class__.Helper__DoWork__Stage03__OpenUpdFilesToWrite(ctx)
|
|
3845
|
+
|
|
3846
|
+
# 4.
|
|
3847
|
+
__class__.Helper__DoWork__Stage04__OpenNewFilesToWrite(ctx)
|
|
3848
|
+
|
|
3849
|
+
# 4.
|
|
3850
|
+
__class__.Helper__DoWork__Stage05__WriteContents(ctx)
|
|
3851
|
+
|
|
3852
|
+
# OK. Go HOME!
|
|
3853
|
+
return
|
|
3854
|
+
|
|
3855
|
+
# --------------------------------------------------------------------
|
|
3856
|
+
def Helper__DoWork__Stage01__CreateFileContexts(
|
|
3857
|
+
ctx: PostgresConfigurationWriterCtx_Base,
|
|
3858
|
+
):
|
|
3859
|
+
assert type(ctx) == PostgresConfigurationWriterCtx_Base
|
|
3860
|
+
assert isinstance(ctx.Cfg, PostgresConfiguration_Base)
|
|
3861
|
+
assert type(ctx.Cfg.m_Data) == PgCfgModel__ConfigurationData
|
|
3862
|
+
|
|
3863
|
+
for fileData in ctx.Cfg.m_Data.m_AllFilesByName.values():
|
|
3864
|
+
assert fileData is not None
|
|
3865
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
3866
|
+
|
|
3867
|
+
fileCtx = PostgresConfigurationWriterFileCtx_Base(fileData)
|
|
3868
|
+
|
|
3869
|
+
assert fileCtx.FileData is fileData
|
|
3870
|
+
assert fileCtx.Content is None
|
|
3871
|
+
assert fileCtx.File is None
|
|
3872
|
+
|
|
3873
|
+
assert not (fileCtx in ctx.AllFiles)
|
|
3874
|
+
assert not (fileCtx in ctx.NewFiles)
|
|
3875
|
+
assert not (fileCtx in ctx.UpdFiles)
|
|
3876
|
+
|
|
3877
|
+
ctx.AllFiles.append(fileCtx)
|
|
3878
|
+
|
|
3879
|
+
if fileData.m_Status == PgCfgModel__FileStatus.IS_NEW:
|
|
3880
|
+
ctx.NewFiles.append(fileCtx)
|
|
3881
|
+
elif fileData.m_Status == PgCfgModel__FileStatus.EXISTS:
|
|
3882
|
+
ctx.UpdFiles.append(fileCtx)
|
|
3883
|
+
else:
|
|
3884
|
+
BugCheckError.UnkFileDataStatus(fileData.m_Path, fileData.m_Status)
|
|
3885
|
+
|
|
3886
|
+
# --------------------------------------------------------------------
|
|
3887
|
+
def Helper__DoWork__Stage02__MakeFileDataContents(
|
|
3888
|
+
ctx: PostgresConfigurationWriterCtx_Base,
|
|
3889
|
+
):
|
|
3890
|
+
assert type(ctx) == PostgresConfigurationWriterCtx_Base
|
|
3891
|
+
assert isinstance(ctx.Cfg, PostgresConfiguration_Base)
|
|
3892
|
+
assert type(ctx.Cfg.m_Data) == PgCfgModel__ConfigurationData
|
|
3893
|
+
|
|
3894
|
+
for fileCtx in ctx.AllFiles:
|
|
3895
|
+
assert fileCtx is not None
|
|
3896
|
+
assert type(fileCtx) == PostgresConfigurationWriterFileCtx_Base
|
|
3897
|
+
assert type(fileCtx.FileData) == PgCfgModel__FileData
|
|
3898
|
+
assert fileCtx.Content is None
|
|
3899
|
+
|
|
3900
|
+
fileCtx.Content = __class__.Helper__MakeFileDataContent(
|
|
3901
|
+
ctx, fileCtx.FileData
|
|
3902
|
+
)
|
|
3903
|
+
|
|
3904
|
+
# --------------------------------------------------------------------
|
|
3905
|
+
def Helper__DoWork__Stage03__OpenUpdFilesToWrite(
|
|
3906
|
+
ctx: PostgresConfigurationWriterCtx_Base,
|
|
3907
|
+
):
|
|
3908
|
+
assert type(ctx) == PostgresConfigurationWriterCtx_Base
|
|
3909
|
+
assert isinstance(ctx.Cfg, PostgresConfiguration_Base)
|
|
3910
|
+
assert type(ctx.Cfg.m_Data) == PgCfgModel__ConfigurationData
|
|
3911
|
+
|
|
3912
|
+
for fileCtx in ctx.UpdFiles:
|
|
3913
|
+
assert fileCtx is not None
|
|
3914
|
+
assert type(fileCtx) == PostgresConfigurationWriterFileCtx_Base
|
|
3915
|
+
assert type(fileCtx.FileData) == PgCfgModel__FileData
|
|
3916
|
+
|
|
3917
|
+
assert fileCtx.FileData.m_Status == PgCfgModel__FileStatus.EXISTS
|
|
3918
|
+
assert fileCtx.FileData.m_LastModifiedTimestamp is not None
|
|
3919
|
+
assert type(fileCtx.FileData.m_LastModifiedTimestamp) == datetime.datetime
|
|
3920
|
+
assert fileCtx.File is None
|
|
3921
|
+
|
|
3922
|
+
# Let's open an exist file to read and write without truncation
|
|
3923
|
+
fileCtx.File = ctx.Cfg.m_Data.OsOps.OpenFileToWrite(fileCtx.FileData.m_Path) # raise
|
|
3924
|
+
|
|
3925
|
+
assert fileCtx.File is not None
|
|
3926
|
+
assert isinstance(fileCtx.File, ConfigurationOsFile)
|
|
3927
|
+
|
|
3928
|
+
lastMDate = fileCtx.File.GetModificationTS()
|
|
3929
|
+
assert type(lastMDate) == datetime.datetime
|
|
3930
|
+
|
|
3931
|
+
if fileCtx.FileData.m_LastModifiedTimestamp != lastMDate:
|
|
3932
|
+
RaiseError.FileWasModifiedExternally(
|
|
3933
|
+
fileCtx.FileData.m_Path,
|
|
3934
|
+
fileCtx.FileData.m_LastModifiedTimestamp,
|
|
3935
|
+
lastMDate,
|
|
3936
|
+
)
|
|
3937
|
+
|
|
3938
|
+
# OK!
|
|
3939
|
+
continue
|
|
3940
|
+
|
|
3941
|
+
# OK, Go HOME!
|
|
3942
|
+
return
|
|
3943
|
+
|
|
3944
|
+
# --------------------------------------------------------------------
|
|
3945
|
+
def Helper__DoWork__Stage04__OpenNewFilesToWrite(
|
|
3946
|
+
ctx: PostgresConfigurationWriterCtx_Base,
|
|
3947
|
+
):
|
|
3948
|
+
assert type(ctx) == PostgresConfigurationWriterCtx_Base
|
|
3949
|
+
assert isinstance(ctx.Cfg, PostgresConfiguration_Base)
|
|
3950
|
+
assert type(ctx.Cfg.m_Data) == PgCfgModel__ConfigurationData
|
|
3951
|
+
assert type(ctx.NewFiles) == list
|
|
3952
|
+
|
|
3953
|
+
iFile = 0
|
|
3954
|
+
|
|
3955
|
+
try:
|
|
3956
|
+
for iFile in range(len(ctx.NewFiles)):
|
|
3957
|
+
fileCtx = ctx.NewFiles[iFile]
|
|
3958
|
+
|
|
3959
|
+
assert fileCtx is not None
|
|
3960
|
+
assert type(fileCtx) == PostgresConfigurationWriterFileCtx_Base
|
|
3961
|
+
assert type(fileCtx.FileData) == PgCfgModel__FileData
|
|
3962
|
+
|
|
3963
|
+
assert fileCtx.FileData.m_Status == PgCfgModel__FileStatus.IS_NEW
|
|
3964
|
+
assert fileCtx.File is None
|
|
3965
|
+
|
|
3966
|
+
fileCtx.File = ctx.Cfg.m_Data.OsOps.CreateFile(fileCtx.FileData.m_Path) # raise
|
|
3967
|
+
|
|
3968
|
+
assert fileCtx.File is not None
|
|
3969
|
+
assert isinstance(fileCtx.File, ConfigurationOsFile)
|
|
3970
|
+
|
|
3971
|
+
# OK
|
|
3972
|
+
continue
|
|
3973
|
+
|
|
3974
|
+
except: # Rollback new files
|
|
3975
|
+
assert type(iFile) == int
|
|
3976
|
+
assert iFile >= 0
|
|
3977
|
+
assert iFile <= len(ctx.NewFiles)
|
|
3978
|
+
|
|
3979
|
+
for iFile2 in range(iFile):
|
|
3980
|
+
fileCtx = ctx.NewFiles[iFile2]
|
|
3981
|
+
|
|
3982
|
+
assert fileCtx is not None
|
|
3983
|
+
assert type(fileCtx) == PostgresConfigurationWriterFileCtx_Base
|
|
3984
|
+
assert type(fileCtx.FileData) == PgCfgModel__FileData
|
|
3985
|
+
|
|
3986
|
+
assert fileCtx.FileData.m_Status == PgCfgModel__FileStatus.IS_NEW
|
|
3987
|
+
assert fileCtx.File is not None
|
|
3988
|
+
assert isinstance(fileCtx.File, ConfigurationOsFile)
|
|
3989
|
+
|
|
3990
|
+
assert not fileCtx.File.IsClosed
|
|
3991
|
+
|
|
3992
|
+
filePath = fileCtx.File.Name
|
|
3993
|
+
assert filePath is not None
|
|
3994
|
+
assert type(filePath) == str
|
|
3995
|
+
assert filePath == fileCtx.FileData.m_Path
|
|
3996
|
+
|
|
3997
|
+
fileCtx.File.Close() # raise
|
|
3998
|
+
|
|
3999
|
+
ctx.Cfg.m_Data.OsOps.Remove(filePath) # raise
|
|
4000
|
+
continue
|
|
4001
|
+
|
|
4002
|
+
raise
|
|
4003
|
+
|
|
4004
|
+
# OK, Go HOME!
|
|
4005
|
+
return
|
|
4006
|
+
|
|
4007
|
+
# --------------------------------------------------------------------
|
|
4008
|
+
def Helper__DoWork__Stage05__WriteContents(
|
|
4009
|
+
ctx: PostgresConfigurationWriterCtx_Base,
|
|
4010
|
+
):
|
|
4011
|
+
assert type(ctx) == PostgresConfigurationWriterCtx_Base
|
|
4012
|
+
|
|
4013
|
+
for iFile in range(len(ctx.AllFiles)):
|
|
4014
|
+
fileCtx = ctx.AllFiles[iFile]
|
|
4015
|
+
|
|
4016
|
+
assert fileCtx is not None
|
|
4017
|
+
assert type(fileCtx) == PostgresConfigurationWriterFileCtx_Base
|
|
4018
|
+
assert type(fileCtx.FileData) == PgCfgModel__FileData
|
|
4019
|
+
|
|
4020
|
+
assert fileCtx.File is not None
|
|
4021
|
+
assert isinstance(fileCtx.File, ConfigurationOsFile)
|
|
4022
|
+
|
|
4023
|
+
assert fileCtx.Content is not None
|
|
4024
|
+
assert type(fileCtx.Content) == str
|
|
4025
|
+
|
|
4026
|
+
fileCtx.File.Overwrite(fileCtx.Content)
|
|
4027
|
+
|
|
4028
|
+
lastMDate = fileCtx.File.GetModificationTS()
|
|
4029
|
+
assert type(lastMDate) == datetime.datetime
|
|
4030
|
+
|
|
4031
|
+
fileCtx.File.Close()
|
|
4032
|
+
|
|
4033
|
+
fileCtx.FileData.m_LastModifiedTimestamp = lastMDate
|
|
4034
|
+
fileCtx.FileData.m_Status = PgCfgModel__FileStatus.EXISTS
|
|
4035
|
+
|
|
4036
|
+
# --------------------------------------------------------------------
|
|
4037
|
+
def Helper__MakeFileDataContent(
|
|
4038
|
+
ctx: PostgresConfigurationWriterCtx_Base, fileData: PgCfgModel__FileData
|
|
4039
|
+
) -> str:
|
|
4040
|
+
assert type(ctx) == PostgresConfigurationWriterCtx_Base
|
|
4041
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
4042
|
+
|
|
4043
|
+
fileContent = ""
|
|
4044
|
+
|
|
4045
|
+
for fileLineData in fileData.m_Lines:
|
|
4046
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
4047
|
+
lineContent = __class__.Helper__FileLineToString(ctx, fileLineData)
|
|
4048
|
+
assert type(lineContent) == str
|
|
4049
|
+
fileContent += lineContent
|
|
4050
|
+
fileContent += "\n"
|
|
4051
|
+
|
|
4052
|
+
return fileContent
|
|
4053
|
+
|
|
4054
|
+
# --------------------------------------------------------------------
|
|
4055
|
+
def Helper__FileLineToString(
|
|
4056
|
+
ctx: PostgresConfigurationWriterCtx_Base,
|
|
4057
|
+
fileLineData: PgCfgModel__FileLineData,
|
|
4058
|
+
) -> str:
|
|
4059
|
+
assert type(ctx) == PostgresConfigurationWriterCtx_Base
|
|
4060
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
4061
|
+
|
|
4062
|
+
fileLineItemCount = len(fileLineData.m_Items)
|
|
4063
|
+
|
|
4064
|
+
if fileLineItemCount == 0:
|
|
4065
|
+
return ""
|
|
4066
|
+
|
|
4067
|
+
lineContent = ""
|
|
4068
|
+
|
|
4069
|
+
for lineItem in fileLineData.m_Items:
|
|
4070
|
+
assert type(lineItem) == PgCfgModel__FileLineData.tagItem
|
|
4071
|
+
assert type(lineItem) == PgCfgModel__FileLineData.tagItem
|
|
4072
|
+
assert lineItem.m_Element is not None
|
|
4073
|
+
assert isinstance(lineItem.m_Element, PgCfgModel__FileLineElementData)
|
|
4074
|
+
assert (
|
|
4075
|
+
lineItem.m_Element.m_Offset is None
|
|
4076
|
+
or type(lineItem.m_Element.m_Offset) == int
|
|
4077
|
+
)
|
|
4078
|
+
assert (
|
|
4079
|
+
lineItem.m_Element.m_Offset is None or lineItem.m_Element.m_Offset >= 0
|
|
4080
|
+
)
|
|
4081
|
+
|
|
4082
|
+
itemContent = __class__.Helper__ElementToString(ctx, lineItem.m_Element)
|
|
4083
|
+
assert type(itemContent) == str
|
|
4084
|
+
|
|
4085
|
+
lineContent = __class__.Helper__AppendItemToLine(
|
|
4086
|
+
lineContent, lineItem.m_Element.m_Offset, itemContent
|
|
4087
|
+
)
|
|
4088
|
+
assert type(lineContent) == str
|
|
4089
|
+
|
|
4090
|
+
assert type(lineContent) == str
|
|
4091
|
+
return lineContent
|
|
4092
|
+
|
|
4093
|
+
# --------------------------------------------------------------------
|
|
4094
|
+
def Helper__AppendItemToLine(lineContent: str, offset: int, text: str) -> str:
|
|
4095
|
+
assert type(lineContent) == str
|
|
4096
|
+
assert offset is None or type(offset) == int
|
|
4097
|
+
assert type(text) == str
|
|
4098
|
+
assert offset is None or offset >= 0
|
|
4099
|
+
|
|
4100
|
+
if text == "":
|
|
4101
|
+
return lineContent
|
|
4102
|
+
|
|
4103
|
+
lineContentLen = len(lineContent)
|
|
4104
|
+
|
|
4105
|
+
assert type(lineContentLen) == int
|
|
4106
|
+
assert lineContentLen >= 0
|
|
4107
|
+
|
|
4108
|
+
if offset is not None and lineContentLen < offset:
|
|
4109
|
+
lineContent += " " * (offset - lineContentLen)
|
|
4110
|
+
elif lineContentLen > 0:
|
|
4111
|
+
lineContent += " "
|
|
4112
|
+
|
|
4113
|
+
lineContent += text
|
|
4114
|
+
return lineContent
|
|
4115
|
+
|
|
4116
|
+
# --------------------------------------------------------------------
|
|
4117
|
+
def Helper__ElementToString(
|
|
4118
|
+
ctx: PostgresConfigurationWriterCtx_Base,
|
|
4119
|
+
elementData: PgCfgModel__FileLineElementData,
|
|
4120
|
+
) -> str:
|
|
4121
|
+
assert type(ctx) == PostgresConfigurationWriterCtx_Base
|
|
4122
|
+
assert elementData is not None
|
|
4123
|
+
assert isinstance(elementData, PgCfgModel__FileLineElementData)
|
|
4124
|
+
|
|
4125
|
+
typeOfElementData = type(elementData)
|
|
4126
|
+
|
|
4127
|
+
if typeOfElementData == PgCfgModel__OptionData:
|
|
4128
|
+
return __class__.Helper__OptionToString(ctx, elementData)
|
|
4129
|
+
|
|
4130
|
+
if typeOfElementData == PgCfgModel__CommentData:
|
|
4131
|
+
return __class__.Helper__CommentToString(ctx, elementData)
|
|
4132
|
+
|
|
4133
|
+
if typeOfElementData == PgCfgModel__IncludeData:
|
|
4134
|
+
return __class__.Helper__IncludeToString(ctx, elementData)
|
|
4135
|
+
|
|
4136
|
+
BugCheckError.UnkObjectDataType(typeOfElementData)
|
|
4137
|
+
|
|
4138
|
+
# --------------------------------------------------------------------
|
|
4139
|
+
def Helper__OptionToString(
|
|
4140
|
+
ctx: PostgresConfigurationWriterCtx_Base, optionData: PgCfgModel__OptionData
|
|
4141
|
+
) -> str:
|
|
4142
|
+
assert type(ctx) == PostgresConfigurationWriterCtx_Base
|
|
4143
|
+
assert ctx.Cfg is not None
|
|
4144
|
+
assert isinstance(ctx.Cfg, PostgresConfiguration_Base)
|
|
4145
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
4146
|
+
assert type(optionData.m_Name) == str
|
|
4147
|
+
assert optionData.m_Name != ""
|
|
4148
|
+
assert optionData.m_Value is not None
|
|
4149
|
+
|
|
4150
|
+
writeHandler = ctx.Cfg.Internal__GetOptionHandlerToWrite(optionData.m_Name)
|
|
4151
|
+
|
|
4152
|
+
assert writeHandler is not None
|
|
4153
|
+
assert isinstance(writeHandler, PgCfgModel__OptionHandlerToWrite)
|
|
4154
|
+
|
|
4155
|
+
writeHandlerCtx = PgCfgModel__OptionHandlerCtxToWrite(
|
|
4156
|
+
ctx.Cfg, optionData.m_Name, optionData.m_Value
|
|
4157
|
+
)
|
|
4158
|
+
|
|
4159
|
+
optValueAsText = writeHandler.OptionValueToString(writeHandlerCtx)
|
|
4160
|
+
|
|
4161
|
+
assert type(optValueAsText) == str
|
|
4162
|
+
assert optValueAsText != ""
|
|
4163
|
+
|
|
4164
|
+
result = optionData.m_Name + " = " + optValueAsText
|
|
4165
|
+
return result
|
|
4166
|
+
|
|
4167
|
+
# --------------------------------------------------------------------
|
|
4168
|
+
def Helper__CommentToString(
|
|
4169
|
+
ctx: PostgresConfigurationWriterCtx_Base, commentData: PgCfgModel__CommentData
|
|
4170
|
+
) -> str:
|
|
4171
|
+
assert type(ctx) == PostgresConfigurationWriterCtx_Base
|
|
4172
|
+
assert ctx.Cfg is not None
|
|
4173
|
+
assert isinstance(ctx.Cfg, PostgresConfiguration_Base)
|
|
4174
|
+
assert type(commentData) == PgCfgModel__CommentData
|
|
4175
|
+
assert commentData.m_Text is not None
|
|
4176
|
+
assert type(commentData.m_Text) == str
|
|
4177
|
+
|
|
4178
|
+
assert DataVerificator.IsValidCommentText(commentData.m_Text)
|
|
4179
|
+
|
|
4180
|
+
result = "#" + commentData.m_Text
|
|
4181
|
+
return result
|
|
4182
|
+
|
|
4183
|
+
# --------------------------------------------------------------------
|
|
4184
|
+
def Helper__IncludeToString(
|
|
4185
|
+
ctx: PostgresConfigurationWriterCtx_Base, includeData: PgCfgModel__IncludeData
|
|
4186
|
+
) -> str:
|
|
4187
|
+
assert type(ctx) == PostgresConfigurationWriterCtx_Base
|
|
4188
|
+
assert ctx.Cfg is not None
|
|
4189
|
+
assert isinstance(ctx.Cfg, PostgresConfiguration_Base)
|
|
4190
|
+
assert type(includeData) == PgCfgModel__IncludeData
|
|
4191
|
+
assert includeData.m_Path is not None
|
|
4192
|
+
assert type(includeData.m_Path) == str
|
|
4193
|
+
assert includeData.m_Path != ""
|
|
4194
|
+
|
|
4195
|
+
result = "include " + WriteUtils.Pack_Str(includeData.m_Path)
|
|
4196
|
+
|
|
4197
|
+
assert type(result) == str
|
|
4198
|
+
assert result != ""
|
|
4199
|
+
return result
|
|
4200
|
+
|
|
4201
|
+
|
|
4202
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
4203
|
+
# PostgresConfigurationController__Base
|
|
4204
|
+
|
|
4205
|
+
|
|
4206
|
+
class PostgresConfigurationController__Base:
|
|
4207
|
+
def AddOption(
|
|
4208
|
+
cfg: PostgresConfiguration_Base,
|
|
4209
|
+
target: typing.Union[None, PgCfgModel__FileData, PgCfgModel__FileLineData],
|
|
4210
|
+
optionName: str,
|
|
4211
|
+
optionValue: any,
|
|
4212
|
+
optionOffset: typing.Union[int],
|
|
4213
|
+
) -> PostgresConfigurationOption_Base:
|
|
4214
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
4215
|
+
assert (
|
|
4216
|
+
target is None
|
|
4217
|
+
or type(target) == PgCfgModel__FileData
|
|
4218
|
+
or type(target) == PgCfgModel__FileLineData
|
|
4219
|
+
)
|
|
4220
|
+
assert type(optionName) == str
|
|
4221
|
+
assert optionValue is not None
|
|
4222
|
+
assert optionOffset is None or type(optionOffset) == int
|
|
4223
|
+
|
|
4224
|
+
# ----------------------
|
|
4225
|
+
preparedOptionValue = __class__.Helper__PrepareSetValue(
|
|
4226
|
+
cfg, optionName, optionValue
|
|
4227
|
+
)
|
|
4228
|
+
|
|
4229
|
+
assert preparedOptionValue is not None
|
|
4230
|
+
|
|
4231
|
+
# ----------------------
|
|
4232
|
+
addHandler = cfg.Internal__GetOptionHandlerToAddOption(optionName)
|
|
4233
|
+
|
|
4234
|
+
assert isinstance(addHandler, PgCfgModel__OptionHandlerToAddOption)
|
|
4235
|
+
|
|
4236
|
+
ctx = PgCfgModel__OptionHandlerCtxToAddOption(
|
|
4237
|
+
cfg,
|
|
4238
|
+
target,
|
|
4239
|
+
optionOffset,
|
|
4240
|
+
optionName,
|
|
4241
|
+
preparedOptionValue,
|
|
4242
|
+
)
|
|
4243
|
+
|
|
4244
|
+
option = addHandler.AddOption(ctx)
|
|
4245
|
+
assert option is not None
|
|
4246
|
+
assert type(option) == PostgresConfigurationOption_Base
|
|
4247
|
+
return option
|
|
4248
|
+
|
|
4249
|
+
# --------------------------------------------------------------------
|
|
4250
|
+
def SetOptionValue(
|
|
4251
|
+
cfg: PostgresConfiguration_Base,
|
|
4252
|
+
targetData: typing.Union[None, PgCfgModel__FileData, PgCfgModel__OptionData],
|
|
4253
|
+
optionName: str,
|
|
4254
|
+
optionValue: any,
|
|
4255
|
+
optionOffset: typing.Union[int],
|
|
4256
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
4257
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
4258
|
+
assert (
|
|
4259
|
+
targetData is None
|
|
4260
|
+
or type(targetData) == PgCfgModel__FileData
|
|
4261
|
+
or type(targetData) == PgCfgModel__OptionData
|
|
4262
|
+
)
|
|
4263
|
+
assert type(optionName) == str
|
|
4264
|
+
assert optionOffset is None or type(optionOffset) == int
|
|
4265
|
+
|
|
4266
|
+
# ----------------------
|
|
4267
|
+
if optionValue is None:
|
|
4268
|
+
return cfg.DataHandler__ResetOption(targetData, optionName)
|
|
4269
|
+
|
|
4270
|
+
assert optionValue is not None
|
|
4271
|
+
|
|
4272
|
+
# ----------------------
|
|
4273
|
+
preparedOptionValue = __class__.Helper__PrepareSetValue(
|
|
4274
|
+
cfg, optionName, optionValue
|
|
4275
|
+
)
|
|
4276
|
+
|
|
4277
|
+
assert preparedOptionValue is not None
|
|
4278
|
+
|
|
4279
|
+
# ----------------------
|
|
4280
|
+
setHandler = cfg.Internal__GetOptionHandlerToSetValue(optionName)
|
|
4281
|
+
|
|
4282
|
+
assert isinstance(setHandler, PgCfgModel__OptionHandlerToSetValue)
|
|
4283
|
+
|
|
4284
|
+
ctx = PgCfgModel__OptionHandlerCtxToSetValue(
|
|
4285
|
+
cfg,
|
|
4286
|
+
targetData,
|
|
4287
|
+
optionName,
|
|
4288
|
+
preparedOptionValue,
|
|
4289
|
+
)
|
|
4290
|
+
|
|
4291
|
+
r = setHandler.SetOptionValue(ctx)
|
|
4292
|
+
|
|
4293
|
+
assert type(r) == PostgresConfigurationSetOptionValueResult_Base
|
|
4294
|
+
|
|
4295
|
+
return r
|
|
4296
|
+
|
|
4297
|
+
# --------------------------------------------------------------------
|
|
4298
|
+
def SetOptionValueItem(
|
|
4299
|
+
cfg: PostgresConfiguration_Base,
|
|
4300
|
+
targetData: typing.Union[None, PgCfgModel__FileData, PgCfgModel__OptionData],
|
|
4301
|
+
optionName: str,
|
|
4302
|
+
optionValueItem: any,
|
|
4303
|
+
) -> PostgresConfigurationSetOptionValueResult_Base:
|
|
4304
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
4305
|
+
assert (
|
|
4306
|
+
targetData is None
|
|
4307
|
+
or type(targetData) == PgCfgModel__FileData
|
|
4308
|
+
or type(targetData) == PgCfgModel__OptionData
|
|
4309
|
+
)
|
|
4310
|
+
assert type(optionName) == str
|
|
4311
|
+
|
|
4312
|
+
# ---------------------------------------
|
|
4313
|
+
if optionValueItem is None:
|
|
4314
|
+
RaiseError.NoneValueIsNotSupported()
|
|
4315
|
+
|
|
4316
|
+
assert optionValueItem is not None
|
|
4317
|
+
|
|
4318
|
+
# ---------------------------------------
|
|
4319
|
+
optionValueItem_p = __class__.Helper__PrepareSetValueItem(
|
|
4320
|
+
cfg, optionName, optionValueItem
|
|
4321
|
+
)
|
|
4322
|
+
|
|
4323
|
+
assert optionValueItem_p is not None
|
|
4324
|
+
|
|
4325
|
+
# ---------------------------------------
|
|
4326
|
+
setHandler = cfg.Internal__GetOptionHandlerToSetValueItem(optionName)
|
|
4327
|
+
|
|
4328
|
+
assert isinstance(setHandler, PgCfgModel__OptionHandlerToSetValueItem)
|
|
4329
|
+
|
|
4330
|
+
ctx = PgCfgModel__OptionHandlerCtxToSetValueItem(
|
|
4331
|
+
cfg,
|
|
4332
|
+
targetData, # target
|
|
4333
|
+
optionName,
|
|
4334
|
+
optionValueItem_p,
|
|
4335
|
+
)
|
|
4336
|
+
|
|
4337
|
+
r = setHandler.SetOptionValueItem(ctx)
|
|
4338
|
+
|
|
4339
|
+
assert type(r) == PostgresConfigurationSetOptionValueResult_Base
|
|
4340
|
+
|
|
4341
|
+
return r
|
|
4342
|
+
|
|
4343
|
+
# --------------------------------------------------------------------
|
|
4344
|
+
def GetOptionValue(
|
|
4345
|
+
cfg: PostgresConfiguration_Base,
|
|
4346
|
+
sourceData: typing.Union[None, PgCfgModel__FileData, PgCfgModel__OptionData],
|
|
4347
|
+
optionName: str,
|
|
4348
|
+
) -> any:
|
|
4349
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
4350
|
+
assert (
|
|
4351
|
+
sourceData is None
|
|
4352
|
+
or type(sourceData) == PgCfgModel__FileData
|
|
4353
|
+
or type(sourceData) == PgCfgModel__OptionData
|
|
4354
|
+
)
|
|
4355
|
+
assert type(optionName) == str
|
|
4356
|
+
|
|
4357
|
+
getHandler = cfg.Internal__GetOptionHandlerToGetValue(optionName)
|
|
4358
|
+
|
|
4359
|
+
assert isinstance(getHandler, PgCfgModel__OptionHandlerToGetValue)
|
|
4360
|
+
|
|
4361
|
+
ctx = PgCfgModel__OptionHandlerCtxToGetValue(cfg, sourceData, optionName)
|
|
4362
|
+
|
|
4363
|
+
r = getHandler.GetOptionValue(ctx)
|
|
4364
|
+
return r
|
|
4365
|
+
|
|
4366
|
+
# Helper methods -----------------------------------------------------
|
|
4367
|
+
def Helper__PrepareSetValue(
|
|
4368
|
+
cfg: PostgresConfiguration_Base, optionName: str, optionValue: any
|
|
4369
|
+
) -> any:
|
|
4370
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
4371
|
+
assert type(optionName) == str
|
|
4372
|
+
assert optionValue is not None
|
|
4373
|
+
|
|
4374
|
+
assert type(optionName) == str
|
|
4375
|
+
assert optionValue is not None
|
|
4376
|
+
|
|
4377
|
+
prepareHandler = cfg.Internal__GetOptionHandlerToPrepareSetValue(optionName)
|
|
4378
|
+
assert prepareHandler is not None
|
|
4379
|
+
assert isinstance(prepareHandler, PgCfgModel__OptionHandlerToPrepareSetValue)
|
|
4380
|
+
|
|
4381
|
+
prepareCtx = PgCfgModel__OptionHandlerCtxPrepareToSetValue(
|
|
4382
|
+
cfg, optionName, optionValue
|
|
4383
|
+
)
|
|
4384
|
+
|
|
4385
|
+
return prepareHandler.PrepareSetValue(prepareCtx)
|
|
4386
|
+
|
|
4387
|
+
# --------------------------------------------------------------------
|
|
4388
|
+
def Helper__PrepareSetValueItem(
|
|
4389
|
+
cfg: PostgresConfiguration_Base, optionName: str, optionValueItem: any
|
|
4390
|
+
) -> any:
|
|
4391
|
+
assert isinstance(cfg, PostgresConfiguration_Base)
|
|
4392
|
+
assert type(optionName) == str
|
|
4393
|
+
assert optionValueItem is not None
|
|
4394
|
+
|
|
4395
|
+
prepareHandler = cfg.Internal__GetOptionHandlerToPrepareSetValueItem(optionName)
|
|
4396
|
+
assert prepareHandler is not None
|
|
4397
|
+
assert isinstance(
|
|
4398
|
+
prepareHandler, PgCfgModel__OptionHandlerToPrepareSetValueItem
|
|
4399
|
+
)
|
|
4400
|
+
|
|
4401
|
+
prepareCtx = PgCfgModel__OptionHandlerCtxPrepareToSetValueItem(
|
|
4402
|
+
cfg, optionName, optionValueItem
|
|
4403
|
+
)
|
|
4404
|
+
|
|
4405
|
+
return prepareHandler.PrepareSetValueItem(prepareCtx)
|
|
4406
|
+
|
|
4407
|
+
|
|
4408
|
+
# //////////////////////////////////////////////////////////////////////////////
|