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,982 @@
|
|
|
1
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
# Postgres Pro. PostgreSQL Configuration Python Library.
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
# fmt: off
|
|
7
|
+
from .model import ConfigurationData as PgCfgModel__ConfigurationData
|
|
8
|
+
from .model import ObjectData as PgCfgModel__ObjectData
|
|
9
|
+
from .model import FileLineElementData as PgCfgModel__FileLineElementData
|
|
10
|
+
from .model import CommentData as PgCfgModel__CommentData
|
|
11
|
+
from .model import OptionData as PgCfgModel__OptionData
|
|
12
|
+
from .model import IncludeData as PgCfgModel__IncludeData
|
|
13
|
+
from .model import FileLineData as PgCfgModel__FileLineData
|
|
14
|
+
from .model import FileData as PgCfgModel__FileData
|
|
15
|
+
# fmt: on
|
|
16
|
+
|
|
17
|
+
from ..os.abstract.configuration_os_ops import ConfigurationOsOps
|
|
18
|
+
|
|
19
|
+
from .raise_error import RaiseError
|
|
20
|
+
from .bugcheck_error import BugCheckError
|
|
21
|
+
from .helpers import Helpers
|
|
22
|
+
|
|
23
|
+
import typing
|
|
24
|
+
|
|
25
|
+
# //////////////////////////////////////////////////////////////////////////////
|
|
26
|
+
# class DataControllerUtils
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class DataControllerUtils:
|
|
30
|
+
def Option__set_Value(optionData: PgCfgModel__OptionData, value: any):
|
|
31
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
32
|
+
assert value is not None
|
|
33
|
+
|
|
34
|
+
optionData.m_Value = value
|
|
35
|
+
|
|
36
|
+
# --------------------------------------------------------------------
|
|
37
|
+
def Option__add_ValueItem(optionData: PgCfgModel__OptionData, valueItem: any):
|
|
38
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
39
|
+
assert type(optionData.m_Value) == list
|
|
40
|
+
assert valueItem is not None
|
|
41
|
+
|
|
42
|
+
optionData.m_Value.append(valueItem)
|
|
43
|
+
|
|
44
|
+
# --------------------------------------------------------------------
|
|
45
|
+
def Option__delete(
|
|
46
|
+
cfgData: PgCfgModel__ConfigurationData,
|
|
47
|
+
optionData: PgCfgModel__OptionData,
|
|
48
|
+
withLine: bool,
|
|
49
|
+
):
|
|
50
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
51
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
52
|
+
assert type(withLine) == bool
|
|
53
|
+
|
|
54
|
+
fileLineData = optionData.m_Parent
|
|
55
|
+
assert fileLineData is not None
|
|
56
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
57
|
+
|
|
58
|
+
__class__.Helper__DeleteOption(cfgData, optionData)
|
|
59
|
+
|
|
60
|
+
if not withLine:
|
|
61
|
+
return
|
|
62
|
+
|
|
63
|
+
assert not __class__.Helper__FileLineHasWorkData(fileLineData)
|
|
64
|
+
|
|
65
|
+
__class__.Helper__DeleteFileLine(cfgData, fileLineData)
|
|
66
|
+
|
|
67
|
+
# --------------------------------------------------------------------
|
|
68
|
+
def Include__delete(
|
|
69
|
+
cfgData: PgCfgModel__ConfigurationData,
|
|
70
|
+
includeData: PgCfgModel__IncludeData,
|
|
71
|
+
withLine: bool,
|
|
72
|
+
):
|
|
73
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
74
|
+
assert type(includeData) == PgCfgModel__IncludeData
|
|
75
|
+
assert type(withLine) == bool
|
|
76
|
+
|
|
77
|
+
fileLineData = includeData.m_Parent
|
|
78
|
+
assert fileLineData is not None
|
|
79
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
80
|
+
|
|
81
|
+
__class__.Helper__DeleteInclude(includeData)
|
|
82
|
+
|
|
83
|
+
if not withLine:
|
|
84
|
+
return
|
|
85
|
+
|
|
86
|
+
assert not __class__.Helper__FileLineHasWorkData(fileLineData)
|
|
87
|
+
|
|
88
|
+
__class__.Helper__DeleteFileLine(cfgData, fileLineData)
|
|
89
|
+
|
|
90
|
+
# --------------------------------------------------------------------
|
|
91
|
+
def Comment__delete(
|
|
92
|
+
cfgData: PgCfgModel__ConfigurationData,
|
|
93
|
+
commentData: PgCfgModel__CommentData,
|
|
94
|
+
withLineIfLast: bool,
|
|
95
|
+
):
|
|
96
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
97
|
+
assert type(commentData) == PgCfgModel__CommentData
|
|
98
|
+
assert type(withLineIfLast) == bool
|
|
99
|
+
|
|
100
|
+
commentData.IsAlive()
|
|
101
|
+
|
|
102
|
+
assert cfgData is commentData.m_Parent.m_Parent.m_Parent
|
|
103
|
+
|
|
104
|
+
fileLineData = commentData.m_Parent
|
|
105
|
+
assert fileLineData is not None
|
|
106
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
107
|
+
|
|
108
|
+
__class__.Helper__DeleteComment(commentData)
|
|
109
|
+
|
|
110
|
+
if not withLineIfLast:
|
|
111
|
+
return
|
|
112
|
+
|
|
113
|
+
if len(fileLineData.m_Items) != 0:
|
|
114
|
+
return
|
|
115
|
+
|
|
116
|
+
__class__.Helper__DeleteFileLine(cfgData, fileLineData)
|
|
117
|
+
|
|
118
|
+
# --------------------------------------------------------------------
|
|
119
|
+
def FileLine__add_Comment(
|
|
120
|
+
fileLineData: PgCfgModel__FileLineData, offset: typing.Optional[int], text: str
|
|
121
|
+
) -> PgCfgModel__CommentData:
|
|
122
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
123
|
+
assert (offset is None) or (type(offset) == int)
|
|
124
|
+
assert type(text) == str
|
|
125
|
+
assert type(fileLineData.m_Items) == list
|
|
126
|
+
|
|
127
|
+
assert fileLineData.IsAlive()
|
|
128
|
+
|
|
129
|
+
__class__.Helper__CheckThatWeCanAddCommentToFileLine(fileLineData)
|
|
130
|
+
|
|
131
|
+
commentData = PgCfgModel__CommentData(fileLineData, offset, text)
|
|
132
|
+
fileLineDataItem = PgCfgModel__FileLineData.tagItem(commentData)
|
|
133
|
+
fileLineData.m_Items.append(fileLineDataItem)
|
|
134
|
+
return commentData
|
|
135
|
+
|
|
136
|
+
# --------------------------------------------------------------------
|
|
137
|
+
def Helper__CheckThatWeCanAddCommentToFileLine(
|
|
138
|
+
fileLineData: PgCfgModel__FileLineData,
|
|
139
|
+
):
|
|
140
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
141
|
+
assert type(fileLineData.m_Items) == list
|
|
142
|
+
|
|
143
|
+
assert fileLineData.IsAlive()
|
|
144
|
+
|
|
145
|
+
if len(fileLineData.m_Items) == 0:
|
|
146
|
+
return
|
|
147
|
+
|
|
148
|
+
lastItem = fileLineData.m_Items[-1]
|
|
149
|
+
|
|
150
|
+
assert lastItem is not None
|
|
151
|
+
assert type(lastItem) == PgCfgModel__FileLineData.tagItem
|
|
152
|
+
assert lastItem.m_Element is not None
|
|
153
|
+
assert isinstance(lastItem.m_Element, PgCfgModel__FileLineElementData)
|
|
154
|
+
|
|
155
|
+
typeOfLastElement = type(lastItem.m_Element)
|
|
156
|
+
|
|
157
|
+
if typeOfLastElement == PgCfgModel__OptionData:
|
|
158
|
+
return
|
|
159
|
+
|
|
160
|
+
if typeOfLastElement == PgCfgModel__IncludeData:
|
|
161
|
+
return
|
|
162
|
+
|
|
163
|
+
if typeOfLastElement == PgCfgModel__CommentData:
|
|
164
|
+
RaiseError.FileLineAlreadyHasComment()
|
|
165
|
+
|
|
166
|
+
BugCheckError.UnkObjectDataType(typeOfLastElement)
|
|
167
|
+
|
|
168
|
+
# --------------------------------------------------------------------
|
|
169
|
+
def FileLine__add_Include(
|
|
170
|
+
fileLineData: PgCfgModel__FileLineData,
|
|
171
|
+
filePath: str,
|
|
172
|
+
fileData: PgCfgModel__FileData,
|
|
173
|
+
offset: typing.Optional[int],
|
|
174
|
+
) -> PgCfgModel__IncludeData:
|
|
175
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
176
|
+
assert type(filePath) == str
|
|
177
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
178
|
+
assert filePath != ""
|
|
179
|
+
assert offset is None or type(offset) == int
|
|
180
|
+
|
|
181
|
+
assert fileLineData.IsAlive()
|
|
182
|
+
assert fileData.IsAlive()
|
|
183
|
+
|
|
184
|
+
__class__.Helper__CheckThatWeCanAddWorkDataToFileLine(fileLineData)
|
|
185
|
+
|
|
186
|
+
includeData = PgCfgModel__IncludeData(fileLineData, offset, filePath, fileData)
|
|
187
|
+
fileLineDataItem = PgCfgModel__FileLineData.tagItem(includeData)
|
|
188
|
+
fileLineData.m_Items.append(fileLineDataItem)
|
|
189
|
+
|
|
190
|
+
# TODO: Reg include data in a global index?
|
|
191
|
+
|
|
192
|
+
return includeData
|
|
193
|
+
|
|
194
|
+
# --------------------------------------------------------------------
|
|
195
|
+
def FileLine__add_Option(
|
|
196
|
+
cfgData: PgCfgModel__ConfigurationData,
|
|
197
|
+
fileLineData: PgCfgModel__FileLineData,
|
|
198
|
+
optName: str,
|
|
199
|
+
optValue: any,
|
|
200
|
+
optOffset: typing.Optional[int],
|
|
201
|
+
) -> PgCfgModel__OptionData:
|
|
202
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
203
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
204
|
+
assert type(optName) == str
|
|
205
|
+
assert optValue is not None
|
|
206
|
+
assert optName != ""
|
|
207
|
+
assert type(fileLineData.m_Items) == list
|
|
208
|
+
assert optOffset is None or type(optOffset) == int
|
|
209
|
+
|
|
210
|
+
__class__.Helper__CheckThatWeCanAddWorkDataToFileLine(fileLineData)
|
|
211
|
+
|
|
212
|
+
fileData = fileLineData.m_Parent
|
|
213
|
+
assert fileData is not None
|
|
214
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
215
|
+
assert fileData.m_OptionsByName is not None
|
|
216
|
+
assert type(fileData.m_OptionsByName) == dict
|
|
217
|
+
|
|
218
|
+
optionData = PgCfgModel__OptionData(fileLineData, optOffset, optName, optValue)
|
|
219
|
+
fileLineDataItem = PgCfgModel__FileLineData.tagItem(optionData)
|
|
220
|
+
fileLineData.m_Items.append(fileLineDataItem)
|
|
221
|
+
|
|
222
|
+
try:
|
|
223
|
+
__class__.Helper__InsertOptionIntoIndex(
|
|
224
|
+
fileData.m_OptionsByName, optionData
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
try:
|
|
228
|
+
__class__.Helper__InsertOptionIntoIndex(
|
|
229
|
+
cfgData.m_AllOptionsByName, optionData
|
|
230
|
+
)
|
|
231
|
+
except: # rollback
|
|
232
|
+
__class__.Helper__DeleteOptionFromIndex(
|
|
233
|
+
fileData.m_OptionsByName, optionData
|
|
234
|
+
)
|
|
235
|
+
raise
|
|
236
|
+
except: # rollback
|
|
237
|
+
assert type(fileLineData.m_Items) == list
|
|
238
|
+
assert len(fileLineData.m_Items) > 0
|
|
239
|
+
assert fileLineData.m_Items[-1] is fileLineDataItem
|
|
240
|
+
assert fileLineData.m_Items[-1].m_Element is optionData
|
|
241
|
+
fileLineData.m_Items.pop()
|
|
242
|
+
raise
|
|
243
|
+
|
|
244
|
+
return optionData
|
|
245
|
+
|
|
246
|
+
# --------------------------------------------------------------------
|
|
247
|
+
def Helper__CheckThatWeCanAddWorkDataToFileLine(
|
|
248
|
+
fileLineData: PgCfgModel__FileLineData,
|
|
249
|
+
):
|
|
250
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
251
|
+
assert type(fileLineData.m_Items) == list
|
|
252
|
+
|
|
253
|
+
assert fileLineData.IsAlive()
|
|
254
|
+
|
|
255
|
+
if len(fileLineData.m_Items) == 0:
|
|
256
|
+
return
|
|
257
|
+
|
|
258
|
+
lastItem = fileLineData.m_Items[-1]
|
|
259
|
+
|
|
260
|
+
assert lastItem is not None
|
|
261
|
+
assert type(lastItem) == PgCfgModel__FileLineData.tagItem
|
|
262
|
+
assert lastItem.m_Element is not None
|
|
263
|
+
assert isinstance(lastItem.m_Element, PgCfgModel__FileLineElementData)
|
|
264
|
+
|
|
265
|
+
typeOfLastElement = type(lastItem.m_Element)
|
|
266
|
+
|
|
267
|
+
if typeOfLastElement == PgCfgModel__OptionData:
|
|
268
|
+
RaiseError.FileLineAlreadyHasOption(lastItem.m_Element.m_Name)
|
|
269
|
+
|
|
270
|
+
if typeOfLastElement == PgCfgModel__IncludeData:
|
|
271
|
+
RaiseError.FileLineAlreadyHasIncludeDirective()
|
|
272
|
+
|
|
273
|
+
if typeOfLastElement == PgCfgModel__CommentData:
|
|
274
|
+
RaiseError.FileLineAlreadyHasComment()
|
|
275
|
+
|
|
276
|
+
BugCheckError.UnkObjectDataType(typeOfLastElement)
|
|
277
|
+
|
|
278
|
+
# --------------------------------------------------------------------
|
|
279
|
+
def FileLine__delete(
|
|
280
|
+
cfgData: PgCfgModel__ConfigurationData, fileLineData: PgCfgModel__FileLineData
|
|
281
|
+
):
|
|
282
|
+
assert cfgData is not None
|
|
283
|
+
assert fileLineData is not None
|
|
284
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
285
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
286
|
+
assert fileLineData.IsAlive()
|
|
287
|
+
|
|
288
|
+
__class__.Helper__DeleteFileLine(cfgData, fileLineData)
|
|
289
|
+
|
|
290
|
+
assert not fileLineData.IsAlive()
|
|
291
|
+
|
|
292
|
+
# --------------------------------------------------------------------
|
|
293
|
+
def FileLine__clear(
|
|
294
|
+
cfgData: PgCfgModel__ConfigurationData, fileLineData: PgCfgModel__FileLineData
|
|
295
|
+
):
|
|
296
|
+
assert cfgData is not None
|
|
297
|
+
assert fileLineData is not None
|
|
298
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
299
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
300
|
+
assert fileLineData.IsAlive()
|
|
301
|
+
assert fileLineData.m_Items is not None
|
|
302
|
+
assert type(fileLineData.m_Items) == list
|
|
303
|
+
|
|
304
|
+
return __class__.Helper__ClearFileLine(cfgData, fileLineData)
|
|
305
|
+
|
|
306
|
+
# --------------------------------------------------------------------
|
|
307
|
+
def File__add_Option(
|
|
308
|
+
cfgData: PgCfgModel__ConfigurationData,
|
|
309
|
+
fileData: PgCfgModel__FileData,
|
|
310
|
+
optName: str,
|
|
311
|
+
optValue: any,
|
|
312
|
+
) -> PgCfgModel__OptionData:
|
|
313
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
314
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
315
|
+
assert type(optName) == str
|
|
316
|
+
assert optValue is not None
|
|
317
|
+
|
|
318
|
+
newLineData = DataControllerUtils.File__add_Line(fileData) # raise
|
|
319
|
+
|
|
320
|
+
assert type(newLineData) == PgCfgModel__FileLineData
|
|
321
|
+
|
|
322
|
+
try:
|
|
323
|
+
optionData = __class__.FileLine__add_Option(
|
|
324
|
+
cfgData, newLineData, optName, optValue, None
|
|
325
|
+
) # raise
|
|
326
|
+
|
|
327
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
328
|
+
assert optionData.m_Name == optName
|
|
329
|
+
except:
|
|
330
|
+
DataControllerUtils.FileLine__delete(cfgData, newLineData)
|
|
331
|
+
raise
|
|
332
|
+
|
|
333
|
+
assert optionData is not None
|
|
334
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
335
|
+
assert optionData.IsAlive()
|
|
336
|
+
return optionData
|
|
337
|
+
|
|
338
|
+
# --------------------------------------------------------------------
|
|
339
|
+
def File__add_Line(fileData: PgCfgModel__FileData) -> PgCfgModel__FileLineData:
|
|
340
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
341
|
+
assert type(fileData.m_Lines) == list
|
|
342
|
+
|
|
343
|
+
lineData = PgCfgModel__FileLineData(fileData)
|
|
344
|
+
fileData.m_Lines.append(lineData)
|
|
345
|
+
return lineData
|
|
346
|
+
|
|
347
|
+
# --------------------------------------------------------------------
|
|
348
|
+
def Cfg__CreateAndAddTopLevelFile__AUTO(
|
|
349
|
+
cfgData: PgCfgModel__ConfigurationData, file_name: str
|
|
350
|
+
) -> PgCfgModel__FileData:
|
|
351
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
352
|
+
assert type(cfgData.m_Files) == list
|
|
353
|
+
assert type(cfgData.m_AllFilesByName) == dict
|
|
354
|
+
assert isinstance(cfgData.OsOps, ConfigurationOsOps)
|
|
355
|
+
assert type(file_name) == str
|
|
356
|
+
assert file_name != ""
|
|
357
|
+
assert cfgData.OsOps.Path_BaseName(file_name) == file_name
|
|
358
|
+
|
|
359
|
+
newFilePath = cfgData.OsOps.Path_Join(cfgData.m_DataDir, file_name)
|
|
360
|
+
newFilePath = cfgData.OsOps.Path_NormPath(newFilePath)
|
|
361
|
+
|
|
362
|
+
assert type(newFilePath) == str
|
|
363
|
+
assert newFilePath != ""
|
|
364
|
+
|
|
365
|
+
return __class__.Helper__FinishCreateTopLevelFile(cfgData, newFilePath)
|
|
366
|
+
|
|
367
|
+
# --------------------------------------------------------------------
|
|
368
|
+
def Cfg__CreateAndAddTopLevelFile__USER(
|
|
369
|
+
cfgData: PgCfgModel__ConfigurationData, path: str
|
|
370
|
+
) -> PgCfgModel__FileData:
|
|
371
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
372
|
+
assert type(cfgData.m_Files) == list
|
|
373
|
+
assert type(cfgData.m_AllFilesByName) == dict
|
|
374
|
+
assert type(path) == str
|
|
375
|
+
assert isinstance(cfgData.OsOps, ConfigurationOsOps)
|
|
376
|
+
assert path != ""
|
|
377
|
+
|
|
378
|
+
newFilePath = Helpers.NormalizeFilePath(cfgData.OsOps, cfgData.m_DataDir, path)
|
|
379
|
+
|
|
380
|
+
assert type(newFilePath) == str
|
|
381
|
+
assert newFilePath != ""
|
|
382
|
+
|
|
383
|
+
# TODO: use index
|
|
384
|
+
for fileData in cfgData.m_AllFilesByName.values():
|
|
385
|
+
assert fileData is not None
|
|
386
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
387
|
+
assert fileData.IsAlive()
|
|
388
|
+
|
|
389
|
+
if fileData.m_Path == newFilePath:
|
|
390
|
+
RaiseError.FileIsAlreadyRegistered(newFilePath)
|
|
391
|
+
|
|
392
|
+
return __class__.Helper__FinishCreateTopLevelFile(cfgData, newFilePath)
|
|
393
|
+
|
|
394
|
+
# --------------------------------------------------------------------
|
|
395
|
+
def Cfg__GetOrCreateFile__USER(
|
|
396
|
+
cfgData: PgCfgModel__ConfigurationData, baseFolder: str, path: str
|
|
397
|
+
) -> PgCfgModel__FileData:
|
|
398
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
399
|
+
assert type(cfgData.m_Files) == list
|
|
400
|
+
assert type(cfgData.m_AllFilesByName) == dict
|
|
401
|
+
assert isinstance(cfgData.OsOps, ConfigurationOsOps)
|
|
402
|
+
assert type(baseFolder) == str
|
|
403
|
+
assert type(path) == str
|
|
404
|
+
assert path != ""
|
|
405
|
+
|
|
406
|
+
newFilePath = Helpers.NormalizeFilePath(cfgData.OsOps, baseFolder, path)
|
|
407
|
+
|
|
408
|
+
assert type(newFilePath) == str
|
|
409
|
+
assert newFilePath != ""
|
|
410
|
+
|
|
411
|
+
# TODO: use index
|
|
412
|
+
for fileData in cfgData.m_AllFilesByName.values():
|
|
413
|
+
assert fileData is not None
|
|
414
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
415
|
+
assert fileData.IsAlive()
|
|
416
|
+
|
|
417
|
+
if fileData.m_Path == newFilePath:
|
|
418
|
+
return fileData
|
|
419
|
+
|
|
420
|
+
newFileData = PgCfgModel__FileData(cfgData, newFilePath)
|
|
421
|
+
|
|
422
|
+
__class__.Helper__RegFileInCfgData(cfgData, newFileData) # raise
|
|
423
|
+
|
|
424
|
+
return newFileData
|
|
425
|
+
|
|
426
|
+
# Helper methods -----------------------------------------------------
|
|
427
|
+
def Helper__FinishCreateTopLevelFile(
|
|
428
|
+
cfgData: PgCfgModel__ConfigurationData, newFilePath: str
|
|
429
|
+
) -> PgCfgModel__FileData:
|
|
430
|
+
|
|
431
|
+
newFileData = PgCfgModel__FileData(cfgData, newFilePath)
|
|
432
|
+
|
|
433
|
+
__class__.Helper__RegFileInCfgData(cfgData, newFileData) # raise
|
|
434
|
+
|
|
435
|
+
try:
|
|
436
|
+
cfgData.m_Files.append(newFileData) # raise
|
|
437
|
+
except:
|
|
438
|
+
__class__.Helper__UnRegFileFromCfgData(cfgData, newFileData)
|
|
439
|
+
raise
|
|
440
|
+
|
|
441
|
+
return newFileData
|
|
442
|
+
|
|
443
|
+
# --------------------------------------------------------------------
|
|
444
|
+
def Helper__FindIndexOfFileLine(
|
|
445
|
+
fileData: PgCfgModel__FileData, fileLineData: PgCfgModel__FileLineData
|
|
446
|
+
) -> int:
|
|
447
|
+
assert fileData is not None
|
|
448
|
+
assert fileLineData is not None
|
|
449
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
450
|
+
assert type(fileData.m_Lines) == list
|
|
451
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
452
|
+
|
|
453
|
+
cFileLines = len(fileData.m_Lines)
|
|
454
|
+
|
|
455
|
+
for iFileLine in range(cFileLines):
|
|
456
|
+
ptr = fileData.m_Lines[iFileLine]
|
|
457
|
+
assert ptr is not None
|
|
458
|
+
assert type(ptr) == PgCfgModel__FileLineData
|
|
459
|
+
assert ptr.m_Parent is fileData
|
|
460
|
+
|
|
461
|
+
if ptr is fileLineData:
|
|
462
|
+
return iFileLine
|
|
463
|
+
|
|
464
|
+
assert iFileLine == cFileLines
|
|
465
|
+
return iFileLine
|
|
466
|
+
|
|
467
|
+
# --------------------------------------------------------------------
|
|
468
|
+
def Helper__FindIndexOfFileLineElement(
|
|
469
|
+
fileLineData: PgCfgModel__FileLineData,
|
|
470
|
+
elementData: PgCfgModel__FileLineElementData,
|
|
471
|
+
) -> int:
|
|
472
|
+
assert fileLineData is not None
|
|
473
|
+
assert elementData is not None
|
|
474
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
475
|
+
assert type(fileLineData.m_Items) == list
|
|
476
|
+
assert isinstance(elementData, PgCfgModel__FileLineElementData)
|
|
477
|
+
|
|
478
|
+
cItems = len(fileLineData.m_Items)
|
|
479
|
+
|
|
480
|
+
for iItem in range(cItems):
|
|
481
|
+
ptr = fileLineData.m_Items[iItem]
|
|
482
|
+
assert ptr is not None
|
|
483
|
+
assert type(ptr) == PgCfgModel__FileLineData.tagItem
|
|
484
|
+
assert ptr.m_Element is not None
|
|
485
|
+
|
|
486
|
+
if ptr.m_Element is elementData:
|
|
487
|
+
return iItem
|
|
488
|
+
|
|
489
|
+
assert iItem == cItems
|
|
490
|
+
return iItem
|
|
491
|
+
|
|
492
|
+
# --------------------------------------------------------------------
|
|
493
|
+
def Helper__RegFileInCfgData(
|
|
494
|
+
cfgData: PgCfgModel__ConfigurationData, fileData: PgCfgModel__FileData
|
|
495
|
+
):
|
|
496
|
+
assert cfgData is not None
|
|
497
|
+
assert fileData is not None
|
|
498
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
499
|
+
assert isinstance(cfgData.OsOps, ConfigurationOsOps)
|
|
500
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
501
|
+
assert type(fileData.m_Path) == str
|
|
502
|
+
assert fileData.m_Path != ""
|
|
503
|
+
|
|
504
|
+
assert fileData.IsAlive()
|
|
505
|
+
|
|
506
|
+
fileName = cfgData.OsOps.Path_BaseName(fileData.m_Path)
|
|
507
|
+
assert type(fileName) == str
|
|
508
|
+
assert fileName != ""
|
|
509
|
+
|
|
510
|
+
__class__.Helper__InsertFileIntoIndex(
|
|
511
|
+
cfgData.m_AllFilesByName, fileName, fileData
|
|
512
|
+
)
|
|
513
|
+
|
|
514
|
+
# --------------------------------------------------------------------
|
|
515
|
+
def Helper__UnRegFileFromCfgData(
|
|
516
|
+
cfgData: PgCfgModel__ConfigurationData, fileData: PgCfgModel__FileData
|
|
517
|
+
):
|
|
518
|
+
assert cfgData is not None
|
|
519
|
+
assert fileData is not None
|
|
520
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
521
|
+
assert isinstance(cfgData.OsOps, ConfigurationOsOps)
|
|
522
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
523
|
+
assert fileData.m_Path != ""
|
|
524
|
+
|
|
525
|
+
assert fileData.IsAlive()
|
|
526
|
+
|
|
527
|
+
fileName = cfgData.OsOps.Path_BaseName(fileData.m_Path)
|
|
528
|
+
assert type(fileName) == str
|
|
529
|
+
assert fileName != ""
|
|
530
|
+
|
|
531
|
+
__class__.Helper__DeleteFileIntoIndex(
|
|
532
|
+
cfgData.m_AllFilesByName, fileName, fileData
|
|
533
|
+
)
|
|
534
|
+
|
|
535
|
+
# --------------------------------------------------------------------
|
|
536
|
+
def Helper__InsertFileIntoIndex(
|
|
537
|
+
filesByStrKeyDictionary: dict[str, PgCfgModel__FileData],
|
|
538
|
+
fileKey: str,
|
|
539
|
+
fileData: PgCfgModel__FileData,
|
|
540
|
+
):
|
|
541
|
+
assert type(filesByStrKeyDictionary) == dict
|
|
542
|
+
assert type(fileKey) == str
|
|
543
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
544
|
+
|
|
545
|
+
assert fileKey != ""
|
|
546
|
+
assert fileData.IsAlive()
|
|
547
|
+
|
|
548
|
+
if not (fileKey in filesByStrKeyDictionary.keys()):
|
|
549
|
+
filesByStrKeyDictionary[fileKey] = fileData
|
|
550
|
+
else:
|
|
551
|
+
indexItemData = filesByStrKeyDictionary[fileKey]
|
|
552
|
+
|
|
553
|
+
if indexItemData is PgCfgModel__FileData:
|
|
554
|
+
filesByStrKeyDictionary[fileKey] = [indexItemData, fileData] # throw
|
|
555
|
+
else:
|
|
556
|
+
assert type(indexItemData) == list
|
|
557
|
+
assert len(indexItemData) > 0
|
|
558
|
+
indexItemData.append(fileData) # throw
|
|
559
|
+
|
|
560
|
+
assert type(filesByStrKeyDictionary[fileKey]) == list
|
|
561
|
+
assert len(filesByStrKeyDictionary[fileKey]) > 1
|
|
562
|
+
assert filesByStrKeyDictionary[fileKey][-1] is fileData
|
|
563
|
+
|
|
564
|
+
# --------------------------------------------------------------------
|
|
565
|
+
def Helper__DeleteFileIntoIndex(
|
|
566
|
+
filesByStrKeyDictionary: dict[str, PgCfgModel__FileData],
|
|
567
|
+
fileKey: str,
|
|
568
|
+
fileData: PgCfgModel__FileData,
|
|
569
|
+
):
|
|
570
|
+
assert type(filesByStrKeyDictionary) == dict
|
|
571
|
+
assert type(fileKey) == str
|
|
572
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
573
|
+
|
|
574
|
+
assert fileKey != ""
|
|
575
|
+
assert fileData.IsAlive()
|
|
576
|
+
|
|
577
|
+
if not (fileKey in filesByStrKeyDictionary.keys()):
|
|
578
|
+
BugCheckError.FileIsNotFoundInIndex(fileKey, fileData.m_Path)
|
|
579
|
+
|
|
580
|
+
indexItemData = filesByStrKeyDictionary[fileKey]
|
|
581
|
+
|
|
582
|
+
assert indexItemData is not None
|
|
583
|
+
|
|
584
|
+
typeOfIndexItemData = type(indexItemData)
|
|
585
|
+
|
|
586
|
+
if typeOfIndexItemData == fileData:
|
|
587
|
+
assert indexItemData is fileData
|
|
588
|
+
|
|
589
|
+
if not (indexItemData is fileData):
|
|
590
|
+
BugCheckError.FileIsNotFoundInIndex(fileKey, fileData.m_Path)
|
|
591
|
+
|
|
592
|
+
filesByStrKeyDictionary.pop(fileKey)
|
|
593
|
+
assert not (fileKey in filesByStrKeyDictionary.keys())
|
|
594
|
+
return
|
|
595
|
+
|
|
596
|
+
if typeOfIndexItemData == list:
|
|
597
|
+
assert type(indexItemData) == list
|
|
598
|
+
assert len(indexItemData) > 1
|
|
599
|
+
|
|
600
|
+
for i in range(len(indexItemData)):
|
|
601
|
+
ptr = indexItemData[i]
|
|
602
|
+
assert ptr is not None
|
|
603
|
+
assert type(ptr) == PgCfgModel__FileData
|
|
604
|
+
|
|
605
|
+
if ptr is fileData:
|
|
606
|
+
break
|
|
607
|
+
|
|
608
|
+
assert i >= 0
|
|
609
|
+
assert i <= len(indexItemData)
|
|
610
|
+
|
|
611
|
+
if i == len(indexItemData):
|
|
612
|
+
BugCheckError.FileIsNotFoundInIndex(fileKey, fileData.m_Path)
|
|
613
|
+
|
|
614
|
+
assert type(indexItemData) == list
|
|
615
|
+
assert i < len(indexItemData)
|
|
616
|
+
indexItemData.pop(i)
|
|
617
|
+
assert len(indexItemData) > 0
|
|
618
|
+
|
|
619
|
+
if len(indexItemData) == 0: # it is an abnormal situation
|
|
620
|
+
filesByStrKeyDictionary.pop(fileKey)
|
|
621
|
+
elif len(indexItemData) == 1:
|
|
622
|
+
filesByStrKeyDictionary[fileKey] == indexItemData[0]
|
|
623
|
+
|
|
624
|
+
return
|
|
625
|
+
|
|
626
|
+
BugCheckError.UnkFileObjectDataType(fileKey, typeOfIndexItemData)
|
|
627
|
+
|
|
628
|
+
# --------------------------------------------------------------------
|
|
629
|
+
def Helper__InsertOptionIntoIndex(
|
|
630
|
+
optionsByNameDictionary: dict[str, PgCfgModel__OptionData],
|
|
631
|
+
optionData: PgCfgModel__OptionData,
|
|
632
|
+
):
|
|
633
|
+
assert optionsByNameDictionary is not None
|
|
634
|
+
assert optionData is not None
|
|
635
|
+
assert type(optionsByNameDictionary) == dict
|
|
636
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
637
|
+
|
|
638
|
+
if not (optionData.m_Name in optionsByNameDictionary.keys()):
|
|
639
|
+
optionsByNameDictionary[optionData.m_Name] = optionData
|
|
640
|
+
return
|
|
641
|
+
|
|
642
|
+
data = optionsByNameDictionary[optionData.m_Name]
|
|
643
|
+
|
|
644
|
+
typeOfData = type(data)
|
|
645
|
+
|
|
646
|
+
if typeOfData == PgCfgModel__OptionData:
|
|
647
|
+
assert data is not optionData
|
|
648
|
+
optionsByNameDictionary[optionData.m_Name] = [data, optionData]
|
|
649
|
+
return
|
|
650
|
+
|
|
651
|
+
if typeOfData == list:
|
|
652
|
+
assert type(data) == list
|
|
653
|
+
assert len(data) > 1
|
|
654
|
+
data.append(optionData)
|
|
655
|
+
return
|
|
656
|
+
|
|
657
|
+
BugCheckError.UnkOptObjectDataType(optionData.m_Name, typeOfData)
|
|
658
|
+
|
|
659
|
+
# --------------------------------------------------------------------
|
|
660
|
+
def Helper__DeleteOptionFromIndex(
|
|
661
|
+
optionsByNameDictionary: dict[str, PgCfgModel__OptionData],
|
|
662
|
+
optionData: PgCfgModel__OptionData,
|
|
663
|
+
):
|
|
664
|
+
assert optionsByNameDictionary is not None
|
|
665
|
+
assert optionData is not None
|
|
666
|
+
assert type(optionsByNameDictionary) == dict
|
|
667
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
668
|
+
|
|
669
|
+
if not (optionData.m_Name in optionsByNameDictionary.keys()):
|
|
670
|
+
BugCheckError.OptionIsNotFoundInIndex(optionData.m_Name)
|
|
671
|
+
|
|
672
|
+
data = optionsByNameDictionary[optionData.m_Name]
|
|
673
|
+
|
|
674
|
+
assert data is not None
|
|
675
|
+
|
|
676
|
+
typeOfData = type(data)
|
|
677
|
+
|
|
678
|
+
if typeOfData == PgCfgModel__OptionData:
|
|
679
|
+
assert data is optionData
|
|
680
|
+
|
|
681
|
+
if not (data is optionData):
|
|
682
|
+
BugCheckError.OptionIsNotFoundInIndex(optionData.m_Name)
|
|
683
|
+
|
|
684
|
+
optionsByNameDictionary.pop(optionData.m_Name)
|
|
685
|
+
assert not (optionData.m_Name in optionsByNameDictionary.keys())
|
|
686
|
+
return
|
|
687
|
+
|
|
688
|
+
if typeOfData == list:
|
|
689
|
+
assert type(data) == list
|
|
690
|
+
assert len(data) > 1
|
|
691
|
+
|
|
692
|
+
for i in range(len(data)):
|
|
693
|
+
ptr = data[i]
|
|
694
|
+
assert ptr is not None
|
|
695
|
+
assert type(ptr) == PgCfgModel__OptionData
|
|
696
|
+
assert type(ptr.m_Name) == str
|
|
697
|
+
assert ptr.m_Name == optionData.m_Name
|
|
698
|
+
|
|
699
|
+
if ptr is optionData:
|
|
700
|
+
break
|
|
701
|
+
|
|
702
|
+
assert i >= 0
|
|
703
|
+
assert i <= len(data)
|
|
704
|
+
|
|
705
|
+
if i == len(data):
|
|
706
|
+
BugCheckError.OptionIsNotFoundInIndex(optionData.m_Name)
|
|
707
|
+
|
|
708
|
+
assert type(data) == list
|
|
709
|
+
data.pop(i)
|
|
710
|
+
assert len(data) > 0
|
|
711
|
+
|
|
712
|
+
if len(data) == 0: # an abnormal situation
|
|
713
|
+
optionsByNameDictionary.pop(optionData.m_Name)
|
|
714
|
+
elif len(data) == 1:
|
|
715
|
+
optionsByNameDictionary[optionData.m_Name] = data[0]
|
|
716
|
+
|
|
717
|
+
return
|
|
718
|
+
|
|
719
|
+
BugCheckError.UnkOptObjectDataType(optionData.m_Name, typeOfData)
|
|
720
|
+
|
|
721
|
+
# --------------------------------------------------------------------
|
|
722
|
+
def Helper__ClearFileLine(
|
|
723
|
+
cfgData: PgCfgModel__ConfigurationData, fileLineData: PgCfgModel__FileLineData
|
|
724
|
+
):
|
|
725
|
+
assert cfgData is not None
|
|
726
|
+
assert fileLineData is not None
|
|
727
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
728
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
729
|
+
assert fileLineData.IsAlive()
|
|
730
|
+
assert fileLineData.m_Items is not None
|
|
731
|
+
assert type(fileLineData.m_Items) == list
|
|
732
|
+
|
|
733
|
+
cItems = len(fileLineData.m_Items)
|
|
734
|
+
|
|
735
|
+
while True:
|
|
736
|
+
if cItems == 0:
|
|
737
|
+
return
|
|
738
|
+
|
|
739
|
+
assert cItems > 0
|
|
740
|
+
lastItem = fileLineData.m_Items[-1]
|
|
741
|
+
assert lastItem is not None
|
|
742
|
+
assert isinstance(lastItem.m_Element, PgCfgModel__FileLineElementData)
|
|
743
|
+
|
|
744
|
+
__class__.Helper__DeleteElement(cfgData, lastItem.m_Element)
|
|
745
|
+
|
|
746
|
+
assert fileLineData.m_Items is not None
|
|
747
|
+
assert type(fileLineData.m_Items) == list
|
|
748
|
+
|
|
749
|
+
cItems__new = len(fileLineData.m_Items)
|
|
750
|
+
|
|
751
|
+
assert cItems__new == cItems - 1
|
|
752
|
+
cItems = cItems__new
|
|
753
|
+
|
|
754
|
+
# --------------------------------------------------------------------
|
|
755
|
+
def Helper__FileLineHasWorkData(fileLineData: PgCfgModel__FileLineData):
|
|
756
|
+
assert fileLineData is not None
|
|
757
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
758
|
+
assert fileLineData.IsAlive()
|
|
759
|
+
assert fileLineData.m_Items is not None
|
|
760
|
+
assert type(fileLineData.m_Items) == list
|
|
761
|
+
|
|
762
|
+
for item in fileLineData.m_Items:
|
|
763
|
+
assert item is not None
|
|
764
|
+
assert type(item) == PgCfgModel__FileLineData.tagItem
|
|
765
|
+
assert item.m_Element is not None
|
|
766
|
+
assert isinstance(item.m_Element, PgCfgModel__FileLineElementData)
|
|
767
|
+
|
|
768
|
+
typeOfElementData = type(item.m_Element)
|
|
769
|
+
|
|
770
|
+
if typeOfElementData == PgCfgModel__OptionData:
|
|
771
|
+
return True
|
|
772
|
+
|
|
773
|
+
if typeOfElementData == PgCfgModel__CommentData:
|
|
774
|
+
continue
|
|
775
|
+
|
|
776
|
+
if typeOfElementData == PgCfgModel__IncludeData:
|
|
777
|
+
return True
|
|
778
|
+
|
|
779
|
+
BugCheckError.UnkObjectDataType(typeOfElementData)
|
|
780
|
+
|
|
781
|
+
return False
|
|
782
|
+
|
|
783
|
+
# --------------------------------------------------------------------
|
|
784
|
+
def Helper__DeleteElement(
|
|
785
|
+
cfgData: PgCfgModel__ConfigurationData, objectData: PgCfgModel__ObjectData
|
|
786
|
+
):
|
|
787
|
+
assert cfgData is not None
|
|
788
|
+
assert objectData is not None
|
|
789
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
790
|
+
assert isinstance(objectData, PgCfgModel__ObjectData)
|
|
791
|
+
|
|
792
|
+
typeOfObjectData = type(objectData)
|
|
793
|
+
|
|
794
|
+
if typeOfObjectData == PgCfgModel__CommentData:
|
|
795
|
+
return __class__.Helper__DeleteComment(objectData)
|
|
796
|
+
|
|
797
|
+
if typeOfObjectData == PgCfgModel__OptionData:
|
|
798
|
+
return __class__.Helper__DeleteOption(cfgData, objectData)
|
|
799
|
+
|
|
800
|
+
if typeOfObjectData == PgCfgModel__IncludeData:
|
|
801
|
+
return __class__.Helper__DeleteInclude(objectData)
|
|
802
|
+
|
|
803
|
+
BugCheckError.UnkObjectDataType(typeOfObjectData)
|
|
804
|
+
|
|
805
|
+
# --------------------------------------------------------------------
|
|
806
|
+
def Helper__DeleteComment(commentData: PgCfgModel__CommentData):
|
|
807
|
+
assert type(commentData) == PgCfgModel__CommentData
|
|
808
|
+
assert commentData.IsAlive()
|
|
809
|
+
|
|
810
|
+
# 0.
|
|
811
|
+
fileLineData = None
|
|
812
|
+
iFileLineItem = None
|
|
813
|
+
|
|
814
|
+
# 1.1 Set fileLineData
|
|
815
|
+
fileLineData = commentData.m_Parent
|
|
816
|
+
assert fileLineData is not None
|
|
817
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
818
|
+
assert fileLineData.IsAlive()
|
|
819
|
+
|
|
820
|
+
# 1.2 Set iFileLineItem
|
|
821
|
+
iFileLineItem = __class__.Helper__FindIndexOfFileLineElement(
|
|
822
|
+
fileLineData, commentData
|
|
823
|
+
)
|
|
824
|
+
|
|
825
|
+
assert iFileLineItem >= 0
|
|
826
|
+
assert iFileLineItem <= len(fileLineData.m_Items)
|
|
827
|
+
|
|
828
|
+
if iFileLineItem == len(fileLineData.m_Items):
|
|
829
|
+
BugCheckError.CommentIsNotFoundInFileLine()
|
|
830
|
+
|
|
831
|
+
assert iFileLineItem >= 0
|
|
832
|
+
assert iFileLineItem < len(fileLineData.m_Items)
|
|
833
|
+
|
|
834
|
+
# 2. Perform delete operations
|
|
835
|
+
|
|
836
|
+
# delete from fileLine
|
|
837
|
+
commentData.MarkAsDeletedFrom(fileLineData)
|
|
838
|
+
assert not commentData.IsAlive()
|
|
839
|
+
fileLineData.m_Items.pop(iFileLineItem)
|
|
840
|
+
|
|
841
|
+
# --------------------------------------------------------------------
|
|
842
|
+
def Helper__DeleteOption(
|
|
843
|
+
cfgData: PgCfgModel__ConfigurationData, optionData: PgCfgModel__OptionData
|
|
844
|
+
):
|
|
845
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
846
|
+
assert type(optionData) == PgCfgModel__OptionData
|
|
847
|
+
assert type(optionData.m_Name) == str
|
|
848
|
+
assert optionData.IsAlive()
|
|
849
|
+
|
|
850
|
+
# 0.
|
|
851
|
+
fileLineData = None
|
|
852
|
+
iFileLineItem = None
|
|
853
|
+
fileData = None
|
|
854
|
+
|
|
855
|
+
# 1.1 Set fileLineData
|
|
856
|
+
fileLineData = optionData.m_Parent
|
|
857
|
+
assert fileLineData is not None
|
|
858
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
859
|
+
assert fileLineData.IsAlive()
|
|
860
|
+
|
|
861
|
+
# 1.2 Set iFileLineItem
|
|
862
|
+
iFileLineItem = __class__.Helper__FindIndexOfFileLineElement(
|
|
863
|
+
fileLineData, optionData
|
|
864
|
+
)
|
|
865
|
+
|
|
866
|
+
assert iFileLineItem >= 0
|
|
867
|
+
assert iFileLineItem <= len(fileLineData.m_Items)
|
|
868
|
+
|
|
869
|
+
if iFileLineItem == len(fileLineData.m_Items):
|
|
870
|
+
BugCheckError.OptionIsNotFoundInFileLine(optionData.m_Name)
|
|
871
|
+
|
|
872
|
+
assert iFileLineItem >= 0
|
|
873
|
+
assert iFileLineItem < len(fileLineData.m_Items)
|
|
874
|
+
|
|
875
|
+
# 1.3 Set fileData
|
|
876
|
+
fileData = fileLineData.m_Parent
|
|
877
|
+
assert fileData is not None
|
|
878
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
879
|
+
assert fileData.IsAlive()
|
|
880
|
+
|
|
881
|
+
# 1.3
|
|
882
|
+
assert type(fileData.m_OptionsByName) == dict
|
|
883
|
+
assert optionData.m_Name in fileData.m_OptionsByName.keys()
|
|
884
|
+
|
|
885
|
+
# 1.4
|
|
886
|
+
assert type(cfgData.m_AllOptionsByName) == dict
|
|
887
|
+
assert optionData.m_Name in cfgData.m_AllOptionsByName.keys()
|
|
888
|
+
|
|
889
|
+
# 2. Perform delete operations
|
|
890
|
+
|
|
891
|
+
# delete option from global index
|
|
892
|
+
__class__.Helper__DeleteOptionFromIndex(cfgData.m_AllOptionsByName, optionData)
|
|
893
|
+
|
|
894
|
+
# delete option from file index
|
|
895
|
+
__class__.Helper__DeleteOptionFromIndex(fileData.m_OptionsByName, optionData)
|
|
896
|
+
|
|
897
|
+
# delete from fileLine
|
|
898
|
+
optionData.MarkAsDeletedFrom(fileLineData)
|
|
899
|
+
assert not optionData.IsAlive()
|
|
900
|
+
fileLineData.m_Items.pop(iFileLineItem)
|
|
901
|
+
|
|
902
|
+
# --------------------------------------------------------------------
|
|
903
|
+
def Helper__DeleteInclude(includeData: PgCfgModel__IncludeData):
|
|
904
|
+
assert type(includeData) == PgCfgModel__IncludeData
|
|
905
|
+
assert includeData.IsAlive()
|
|
906
|
+
|
|
907
|
+
# 0.
|
|
908
|
+
fileLineData = None
|
|
909
|
+
iFileLineItem = None
|
|
910
|
+
|
|
911
|
+
# 1.1 Set fileLineData
|
|
912
|
+
fileLineData = includeData.m_Parent
|
|
913
|
+
assert fileLineData is not None
|
|
914
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
915
|
+
assert fileLineData.IsAlive()
|
|
916
|
+
|
|
917
|
+
# 1.2 Set iFileLineItem
|
|
918
|
+
iFileLineItem = __class__.Helper__FindIndexOfFileLineElement(
|
|
919
|
+
fileLineData, includeData
|
|
920
|
+
)
|
|
921
|
+
|
|
922
|
+
assert iFileLineItem >= 0
|
|
923
|
+
assert iFileLineItem <= len(fileLineData.m_Items)
|
|
924
|
+
|
|
925
|
+
if iFileLineItem == len(fileLineData.m_Items):
|
|
926
|
+
BugCheckError.IncludeIsNotFoundInFileLine()
|
|
927
|
+
|
|
928
|
+
assert iFileLineItem >= 0
|
|
929
|
+
assert iFileLineItem < len(fileLineData.m_Items)
|
|
930
|
+
|
|
931
|
+
# 2. Perform delete operations
|
|
932
|
+
|
|
933
|
+
# delete from fileLine
|
|
934
|
+
includeData.MarkAsDeletedFrom(fileLineData)
|
|
935
|
+
assert not includeData.IsAlive()
|
|
936
|
+
fileLineData.m_Items.pop(iFileLineItem)
|
|
937
|
+
|
|
938
|
+
# --------------------------------------------------------------------
|
|
939
|
+
def Helper__DeleteFileLine(
|
|
940
|
+
cfgData: PgCfgModel__ConfigurationData, fileLineData: PgCfgModel__FileLineData
|
|
941
|
+
):
|
|
942
|
+
assert type(cfgData) == PgCfgModel__ConfigurationData
|
|
943
|
+
assert type(fileLineData) == PgCfgModel__FileLineData
|
|
944
|
+
assert fileLineData.IsAlive()
|
|
945
|
+
|
|
946
|
+
# 0.
|
|
947
|
+
fileData = None
|
|
948
|
+
iFileLine = None
|
|
949
|
+
|
|
950
|
+
# 1.1 Set fileData
|
|
951
|
+
fileData = fileLineData.m_Parent
|
|
952
|
+
assert fileData is not None
|
|
953
|
+
assert type(fileData) == PgCfgModel__FileData
|
|
954
|
+
assert fileData.IsAlive()
|
|
955
|
+
|
|
956
|
+
# 1.2 Set iFileLine
|
|
957
|
+
iFileLine = __class__.Helper__FindIndexOfFileLine(fileData, fileLineData)
|
|
958
|
+
|
|
959
|
+
assert iFileLine >= 0
|
|
960
|
+
assert iFileLine <= len(fileData.m_Lines)
|
|
961
|
+
|
|
962
|
+
if iFileLine == len(fileData.m_Lines):
|
|
963
|
+
BugCheckError.FileLineIsNotFoundInFile()
|
|
964
|
+
|
|
965
|
+
assert iFileLine >= 0
|
|
966
|
+
assert iFileLine < len(fileData.m_Lines)
|
|
967
|
+
|
|
968
|
+
# 2. Perform cleanup operations
|
|
969
|
+
__class__.Helper__ClearFileLine(cfgData, fileLineData)
|
|
970
|
+
|
|
971
|
+
assert fileLineData.IsAlive()
|
|
972
|
+
assert fileLineData.m_Items is not None
|
|
973
|
+
assert type(fileLineData.m_Items) == list
|
|
974
|
+
assert len(fileLineData.m_Items) == 0
|
|
975
|
+
|
|
976
|
+
# delete from file
|
|
977
|
+
fileLineData.MarkAsDeletedFrom(fileData)
|
|
978
|
+
assert not fileLineData.IsAlive()
|
|
979
|
+
fileData.m_Lines.pop(iFileLine)
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
# //////////////////////////////////////////////////////////////////////////////
|