forked from postgrespro/testgres.pg_conf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
298 lines (204 loc) · 8.55 KB
/
model.py
File metadata and controls
298 lines (204 loc) · 8.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# //////////////////////////////////////////////////////////////////////////////
# Postgres Pro. PostgreSQL Configuration Python Library.
from __future__ import annotations
from .raise_error import RaiseError
from ..os.abstract.configuration_os_ops import ConfigurationOsOps
import typing
import enum
import datetime
# //////////////////////////////////////////////////////////////////////////////
# ObjectData
class ObjectData:
def __init__(self):
pass
# interface ----------------------------------------------------------
def get_Parent(self) -> ObjectData:
RaiseError.MethodIsNotImplemented(__class__, "get_Parent")
def IsAlive(self) -> bool:
RaiseError.MethodIsNotImplemented(__class__, "IsAlive")
# //////////////////////////////////////////////////////////////////////////////
# FileLineElementData
class FileLineElementData(ObjectData):
m_Parent: FileLineData
m_Offset: typing.Optional[int]
# --------------------------------------------------------------------
def __init__(self, parent: FileLineData, offset: typing.Optional[int]):
assert type(parent) is FileLineData
assert offset is None or type(offset) is int
super().__init__()
self.m_Parent = parent
self.m_Offset = offset
# own interface ------------------------------------------------------
def MarkAsDeletedFrom(self, fileLineData: FileLineData) -> None:
assert fileLineData is not None
assert isinstance(fileLineData, FileLineData)
assert self.m_Parent is fileLineData
self.m_Parent = None
# Object interface ---------------------------------------------------
def get_Parent(self) -> FileLineData:
assert type(self.m_Parent) is FileLineData
return self.m_Parent
# --------------------------------------------------------------------
def IsAlive(self) -> bool:
if self.m_Parent is None:
return False
return self.m_Parent.IsAlive()
# //////////////////////////////////////////////////////////////////////////////
# CommentData
class CommentData(FileLineElementData):
m_Text: str
# --------------------------------------------------------------------
def __init__(self, parent: FileLineData, offset: typing.Optional[int], text: str):
assert type(parent) is FileLineData
assert offset is None or type(offset) is int
assert type(text) is str
super().__init__(parent, offset)
self.m_Text = text
# //////////////////////////////////////////////////////////////////////////////
# OptionData
class OptionData(FileLineElementData):
m_Name: str
m_Value: typing.Any
# --------------------------------------------------------------------
def __init__(
self, parent: FileLineData, offset: typing.Optional[int], name: str, value: typing.Any
):
assert type(parent) is FileLineData
assert offset is None or type(offset) is int
assert type(name) is str
assert value is not None
assert name != ""
super().__init__(parent, offset)
self.m_Name = name
self.m_Value = value
# //////////////////////////////////////////////////////////////////////////////
# IncludeData
class IncludeData(FileLineElementData):
m_Path: str
m_File: FileData
# --------------------------------------------------------------------
def __init__(
self,
parent: FileLineData,
offset: typing.Optional[int],
path: str,
fileData: FileData,
):
assert type(parent) is FileLineData
assert type(path) is str
assert type(fileData) is FileData
assert offset is None or type(offset) is int
assert parent.IsAlive()
assert fileData.IsAlive()
assert fileData.get_Parent() is parent.get_Parent().get_Parent()
super().__init__(parent, offset)
self.m_Path = path
self.m_File = fileData
# //////////////////////////////////////////////////////////////////////////////
# FileLineData
class FileLineData(ObjectData):
class tagItem:
m_Element: FileLineElementData
# ----------------------------------------------------------------
def __init__(self, element: FileLineElementData):
assert isinstance(element, FileLineElementData)
self.m_Element = element
# --------------------------------------------------------------------
m_Parent: FileData
m_Items: typing.List[tagItem]
# --------------------------------------------------------------------
def __init__(self, parent: FileData):
assert type(parent) is FileData
super().__init__()
self.m_Parent = parent
self.m_Items = list()
# own interface ------------------------------------------------------
def MarkAsDeletedFrom(self, fileData: FileData) -> None:
assert fileData is not None
assert isinstance(fileData, FileData)
assert self.m_Parent is fileData
self.m_Parent = None
# Object interface ---------------------------------------------------
def get_Parent(self) -> FileData:
assert type(self.m_Parent) is FileData
return self.m_Parent
# --------------------------------------------------------------------
def IsAlive(self) -> bool:
if self.m_Parent is None:
return False
return self.m_Parent.IsAlive()
# //////////////////////////////////////////////////////////////////////////////
# FileStatus
class FileStatus(enum.Enum):
IS_NEW: int = 0
EXISTS: int = 1
# //////////////////////////////////////////////////////////////////////////////
# FileData
class FileData(ObjectData):
m_Parent: ConfigurationData
m_Status: FileStatus
m_LastModifiedTimestamp: typing.Optional[datetime.datetime]
m_Path: str
m_Lines: typing.List[FileLineData]
m_OptionsByName: typing.Dict[str, OptionData]
# --------------------------------------------------------------------
def __init__(self, parent: ConfigurationData, path: str):
assert type(parent) is ConfigurationData
assert type(path) is str
assert parent.OsOps.Path_IsAbs(path)
assert parent.OsOps.Path_NormPath(path) == path
assert parent.OsOps.Path_NormCase(path) == path
super().__init__()
self.m_Parent = parent
self.m_Status = FileStatus.IS_NEW
self.m_LastModifiedTimestamp = None
self.m_Path = path
self.m_Lines = list()
self.m_OptionsByName = dict()
assert type(self.m_OptionsByName) is dict
assert type(self.m_Path) is str
assert self.m_Path != ""
# Object interface ---------------------------------------------------
def get_Parent(self) -> ConfigurationData:
assert type(self.m_Parent) is ConfigurationData
return self.m_Parent
# --------------------------------------------------------------------
def IsAlive(self) -> bool:
if self.m_Parent is None:
return False
return self.m_Parent.IsAlive()
# //////////////////////////////////////////////////////////////////////////////
# ConfigurationData
class ConfigurationData(ObjectData):
m_DataDir: str
m_OsOps: ConfigurationOsOps
m_Files: typing.List[FileData]
m_AllOptionsByName: typing.Dict[
str, typing.Union[OptionData, typing.List[OptionData]]
]
m_AllFilesByName: typing.Dict[str, typing.Union[FileData, typing.List[FileData]]]
# --------------------------------------------------------------------
def __init__(self, data_dir: str, osOps: ConfigurationOsOps):
assert type(data_dir) is str
assert isinstance(osOps, ConfigurationOsOps)
super().__init__()
self.m_DataDir = data_dir
self.m_OsOps = osOps
self.m_Files = list()
self.m_AllOptionsByName = dict()
self.m_AllFilesByName = dict()
assert type(self.m_Files) is list
assert type(self.m_AllOptionsByName) is dict
assert type(self.m_AllFilesByName) is dict
# Own interface ------------------------------------------------------
@property
def OsOps(self) -> ConfigurationOsOps:
assert isinstance(self.m_OsOps, ConfigurationOsOps)
return self.m_OsOps
# Object interface ---------------------------------------------------
def get_Parent(self) -> FileData:
return None
# --------------------------------------------------------------------
def IsAlive(self) -> bool:
return True
# //////////////////////////////////////////////////////////////////////////////