ansys-fluent-core 0.33.dev0__py3-none-any.whl → 0.34.dev0__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.
Potentially problematic release.
This version of ansys-fluent-core might be problematic. Click here for more details.
- ansys/fluent/core/__init__.py +11 -4
- ansys/fluent/core/codegen/builtin_settingsgen.py +17 -9
- ansys/fluent/core/codegen/datamodelgen.py +2 -2
- ansys/fluent/core/codegen/print_fluent_version.py +4 -4
- ansys/fluent/core/codegen/settingsgen.py +1 -2
- ansys/fluent/core/exceptions.py +0 -1
- ansys/fluent/core/file_session.py +9 -9
- ansys/fluent/core/filereader/case_file.py +2 -2
- ansys/fluent/core/fluent_connection.py +5 -5
- ansys/fluent/core/generated/api_tree/api_objects.json +1 -1
- ansys/fluent/core/generated/datamodel_231/flicing.py +40 -40
- ansys/fluent/core/generated/datamodel_231/meshing.py +202 -202
- ansys/fluent/core/generated/datamodel_232/flicing.py +55 -55
- ansys/fluent/core/generated/datamodel_232/meshing.py +159 -159
- ansys/fluent/core/generated/datamodel_241/flicing.py +35 -35
- ansys/fluent/core/generated/datamodel_241/meshing.py +294 -294
- ansys/fluent/core/generated/datamodel_242/flicing.py +35 -35
- ansys/fluent/core/generated/datamodel_242/meshing.py +305 -305
- ansys/fluent/core/generated/datamodel_242/part_management.py +9 -9
- ansys/fluent/core/generated/datamodel_251/flicing.py +50 -50
- ansys/fluent/core/generated/datamodel_251/meshing.py +337 -337
- ansys/fluent/core/generated/datamodel_251/part_management.py +6 -6
- ansys/fluent/core/generated/datamodel_252/flicing.py +35 -35
- ansys/fluent/core/generated/datamodel_252/meshing.py +399 -399
- ansys/fluent/core/generated/datamodel_252/part_management.py +5 -5
- ansys/fluent/core/generated/datamodel_261/flicing.py +45 -45
- ansys/fluent/core/generated/datamodel_261/meshing.py +412 -406
- ansys/fluent/core/generated/datamodel_261/part_management.py +5 -5
- ansys/fluent/core/generated/datamodel_261/solver_workflow.py +7 -0
- ansys/fluent/core/generated/fluent_version_261.py +3 -3
- ansys/fluent/core/generated/solver/settings_252.py +55 -55
- ansys/fluent/core/generated/solver/settings_261.py +2483 -3943
- ansys/fluent/core/generated/solver/settings_261.pyi +3530 -6130
- ansys/fluent/core/generated/solver/settings_builtin.py +57 -1
- ansys/fluent/core/generated/solver/settings_builtin.pyi +79 -0
- ansys/fluent/core/generated/solver/tui_261.py +185 -345
- ansys/fluent/core/launcher/container_launcher.py +7 -9
- ansys/fluent/core/launcher/fluent_container.py +106 -75
- ansys/fluent/core/launcher/launch_options.py +22 -1
- ansys/fluent/core/launcher/launcher.py +5 -4
- ansys/fluent/core/pyfluent_warnings.py +13 -0
- ansys/fluent/core/search.py +170 -83
- ansys/fluent/core/services/app_utilities.py +52 -32
- ansys/fluent/core/services/datamodel_se.py +6 -3
- ansys/fluent/core/services/scheme_eval.py +2 -0
- ansys/fluent/core/services/solution_variables.py +64 -49
- ansys/fluent/core/session.py +36 -30
- ansys/fluent/core/session_base_meshing.py +2 -24
- ansys/fluent/core/session_shared.py +5 -2
- ansys/fluent/core/session_solver.py +15 -9
- ansys/fluent/core/solver/__init__.py +1 -1
- ansys/fluent/core/solver/flobject.py +62 -64
- ansys/fluent/core/solver/settings_builtin_bases.py +14 -7
- ansys/fluent/core/solver/settings_builtin_data.py +121 -540
- ansys/fluent/core/utils/context_managers.py +0 -17
- ansys/fluent/core/utils/fluent_version.py +173 -0
- {ansys_fluent_core-0.33.dev0.dist-info → ansys_fluent_core-0.34.dev0.dist-info}/METADATA +8 -8
- {ansys_fluent_core-0.33.dev0.dist-info → ansys_fluent_core-0.34.dev0.dist-info}/RECORD +60 -78
- {ansys_fluent_core-0.33.dev0.dist-info → ansys_fluent_core-0.34.dev0.dist-info}/WHEEL +1 -1
- ansys/fluent/core/generated/datamodel_222/meshing.py +0 -6332
- ansys/fluent/core/generated/datamodel_222/part_management.py +0 -2072
- ansys/fluent/core/generated/datamodel_222/pm_file_management.py +0 -290
- ansys/fluent/core/generated/datamodel_222/preferences.py +0 -2449
- ansys/fluent/core/generated/datamodel_222/workflow.py +0 -651
- ansys/fluent/core/generated/fluent_version_222.py +0 -5
- ansys/fluent/core/generated/meshing/tui_222.py +0 -9649
- ansys/fluent/core/generated/solver/settings_222.py +0 -29473
- ansys/fluent/core/generated/solver/settings_222.pyi +0 -19590
- ansys/fluent/core/generated/solver/tui_222.py +0 -43451
- ansys/fluent/core/post_objects/__init__.py +0 -21
- ansys/fluent/core/post_objects/check_in_notebook.py +0 -35
- ansys/fluent/core/post_objects/meta.py +0 -926
- ansys/fluent/core/post_objects/post_helper.py +0 -178
- ansys/fluent/core/post_objects/post_object_definitions.py +0 -693
- ansys/fluent/core/post_objects/post_objects_container.py +0 -248
- ansys/fluent/core/post_objects/singleton_meta.py +0 -42
- ansys/fluent/core/post_objects/timing_decorator.py +0 -38
- {ansys_fluent_core-0.33.dev0.dist-info → ansys_fluent_core-0.34.dev0.dist-info/licenses}/LICENSE +0 -0
|
@@ -1,926 +0,0 @@
|
|
|
1
|
-
# Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates.
|
|
2
|
-
# SPDX-License-Identifier: MIT
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
"""Metaclasses used in various explicit classes in PyFluent."""
|
|
24
|
-
|
|
25
|
-
from abc import ABCMeta
|
|
26
|
-
from collections.abc import MutableMapping
|
|
27
|
-
import inspect
|
|
28
|
-
from pprint import pformat
|
|
29
|
-
from typing import List
|
|
30
|
-
|
|
31
|
-
from ansys.fluent.core.exceptions import DisallowedValuesError, InvalidArgument
|
|
32
|
-
|
|
33
|
-
# pylint: disable=unused-private-member
|
|
34
|
-
# pylint: disable=bad-mcs-classmethod-argument
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
class Attribute:
|
|
38
|
-
"""Attributes."""
|
|
39
|
-
|
|
40
|
-
VALID_NAMES = [
|
|
41
|
-
"range",
|
|
42
|
-
"allowed_values",
|
|
43
|
-
"display_name_allowed_values",
|
|
44
|
-
"help_str",
|
|
45
|
-
"is_read_only",
|
|
46
|
-
"is_active",
|
|
47
|
-
"on_create",
|
|
48
|
-
"on_change",
|
|
49
|
-
"show_as_separate_object",
|
|
50
|
-
"display_text",
|
|
51
|
-
"layout",
|
|
52
|
-
"previous",
|
|
53
|
-
"next",
|
|
54
|
-
"include",
|
|
55
|
-
"exclude",
|
|
56
|
-
"sort_by",
|
|
57
|
-
"style",
|
|
58
|
-
"icon",
|
|
59
|
-
"show_text",
|
|
60
|
-
"widget",
|
|
61
|
-
"dir_info",
|
|
62
|
-
"extensions",
|
|
63
|
-
]
|
|
64
|
-
|
|
65
|
-
def __init__(self, function):
|
|
66
|
-
self.function = function
|
|
67
|
-
|
|
68
|
-
def __set_name__(self, obj, name):
|
|
69
|
-
if name not in self.VALID_NAMES:
|
|
70
|
-
raise DisallowedValuesError("attribute", name, self.VALID_NAMES)
|
|
71
|
-
self.name = name
|
|
72
|
-
if not hasattr(obj, "attributes"):
|
|
73
|
-
obj.attributes = set()
|
|
74
|
-
obj.attributes.add(name)
|
|
75
|
-
|
|
76
|
-
def __set__(self, obj, value):
|
|
77
|
-
raise AttributeError("Attributes are read only.")
|
|
78
|
-
|
|
79
|
-
def __get__(self, obj, objtype=None):
|
|
80
|
-
return self.function(obj)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
class Command:
|
|
84
|
-
"""Executes command."""
|
|
85
|
-
|
|
86
|
-
def __init__(self, method):
|
|
87
|
-
self.arguments_attrs = {}
|
|
88
|
-
cmd_args = inspect.signature(method).parameters
|
|
89
|
-
for arg_name in cmd_args:
|
|
90
|
-
if arg_name != "self":
|
|
91
|
-
self.arguments_attrs[arg_name] = {}
|
|
92
|
-
|
|
93
|
-
def _init(_self, obj):
|
|
94
|
-
_self.obj = obj
|
|
95
|
-
|
|
96
|
-
def _execute(_self, *args, **kwargs):
|
|
97
|
-
for arg, attr_data in self.arguments_attrs.items():
|
|
98
|
-
arg_value = None
|
|
99
|
-
if arg in kwargs:
|
|
100
|
-
arg_value = kwargs[arg]
|
|
101
|
-
else:
|
|
102
|
-
index = list(self.arguments_attrs.keys()).index(arg)
|
|
103
|
-
if len(args) > index:
|
|
104
|
-
arg_value = args[index]
|
|
105
|
-
if arg_value is not None:
|
|
106
|
-
for attr, attr_value in attr_data.items():
|
|
107
|
-
if attr == "allowed_values":
|
|
108
|
-
allowed_values = attr_value(_self.obj)
|
|
109
|
-
if isinstance(arg_value, list):
|
|
110
|
-
if not all(
|
|
111
|
-
elem in allowed_values for elem in arg_value
|
|
112
|
-
):
|
|
113
|
-
raise DisallowedValuesError(
|
|
114
|
-
arg, arg_value, allowed_values
|
|
115
|
-
)
|
|
116
|
-
else:
|
|
117
|
-
if arg_value not in allowed_values:
|
|
118
|
-
raise DisallowedValuesError(
|
|
119
|
-
arg, arg_value, allowed_values
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
elif attr == "range":
|
|
123
|
-
if not isinstance(arg_value, (int, float)):
|
|
124
|
-
raise RuntimeError(
|
|
125
|
-
f"{arg} value {arg_value} is not number."
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
minimum, maximum = attr_value(_self.obj)
|
|
129
|
-
if arg_value < minimum or arg_value > maximum:
|
|
130
|
-
raise DisallowedValuesError(
|
|
131
|
-
arg, arg_value, allowed_values
|
|
132
|
-
)
|
|
133
|
-
return method(_self.obj, *args, **kwargs)
|
|
134
|
-
|
|
135
|
-
self.command_cls = type(
|
|
136
|
-
"command",
|
|
137
|
-
(),
|
|
138
|
-
{
|
|
139
|
-
"__init__": _init,
|
|
140
|
-
"__call__": _execute,
|
|
141
|
-
"argument_attribute": lambda _self, argument_name, attr_name: self.arguments_attrs[
|
|
142
|
-
argument_name
|
|
143
|
-
][
|
|
144
|
-
attr_name
|
|
145
|
-
](
|
|
146
|
-
_self.obj
|
|
147
|
-
),
|
|
148
|
-
"arguments": lambda _self: list(self.arguments_attrs.keys()),
|
|
149
|
-
},
|
|
150
|
-
)
|
|
151
|
-
|
|
152
|
-
def __set_name__(self, obj, name):
|
|
153
|
-
self.obj = obj
|
|
154
|
-
if not hasattr(obj, "commands"):
|
|
155
|
-
obj.commands = {}
|
|
156
|
-
obj.commands[name] = {}
|
|
157
|
-
|
|
158
|
-
def __get__(self, obj, obj_type=None):
|
|
159
|
-
if hasattr(self, "command"):
|
|
160
|
-
return self.command
|
|
161
|
-
else:
|
|
162
|
-
return self.command_cls(obj)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
def CommandArgs(command_object, argument_name):
|
|
166
|
-
"""Command arguments."""
|
|
167
|
-
|
|
168
|
-
def wrapper(attribute):
|
|
169
|
-
if argument_name in command_object.arguments_attrs:
|
|
170
|
-
command_object.arguments_attrs[argument_name].update(
|
|
171
|
-
{attribute.__name__: attribute}
|
|
172
|
-
)
|
|
173
|
-
else:
|
|
174
|
-
raise InvalidArgument(f"{argument_name} not a valid argument.")
|
|
175
|
-
return attribute
|
|
176
|
-
|
|
177
|
-
return wrapper
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
class PyLocalBaseMeta(type):
|
|
181
|
-
"""Local base metaclass."""
|
|
182
|
-
|
|
183
|
-
@classmethod
|
|
184
|
-
def __create_get_ancestors_by_type(cls):
|
|
185
|
-
def wrapper(self, obj_type, obj=None):
|
|
186
|
-
obj = self if obj is None else obj
|
|
187
|
-
parent = None
|
|
188
|
-
if getattr(obj, "_parent", None):
|
|
189
|
-
if isinstance(obj._parent, obj_type):
|
|
190
|
-
return obj._parent
|
|
191
|
-
parent = self.get_ancestors_by_type(obj_type, obj._parent)
|
|
192
|
-
return parent
|
|
193
|
-
|
|
194
|
-
return wrapper
|
|
195
|
-
|
|
196
|
-
@classmethod
|
|
197
|
-
def __create_get_ancestors_by_name(cls):
|
|
198
|
-
def wrapper(self, obj_type, obj=None):
|
|
199
|
-
obj = self if obj is None else obj
|
|
200
|
-
parent = None
|
|
201
|
-
if getattr(obj, "_parent", None):
|
|
202
|
-
if obj._parent.__class__.__name__ == obj_type:
|
|
203
|
-
return obj._parent
|
|
204
|
-
if getattr(obj._parent, "PLURAL", None) == obj_type:
|
|
205
|
-
return obj._parent._parent
|
|
206
|
-
parent = self.get_ancestors_by_name(obj_type, obj._parent)
|
|
207
|
-
return parent
|
|
208
|
-
|
|
209
|
-
return wrapper
|
|
210
|
-
|
|
211
|
-
@classmethod
|
|
212
|
-
def __create_get_root(cls):
|
|
213
|
-
def wrapper(self, obj=None):
|
|
214
|
-
obj = self if obj is None else obj
|
|
215
|
-
parent = obj
|
|
216
|
-
if getattr(obj, "_parent", None):
|
|
217
|
-
parent = self.get_root(obj._parent)
|
|
218
|
-
return parent
|
|
219
|
-
|
|
220
|
-
return wrapper
|
|
221
|
-
|
|
222
|
-
@classmethod
|
|
223
|
-
def __create_get_session(cls):
|
|
224
|
-
def wrapper(self, obj=None):
|
|
225
|
-
root = self.get_root(obj)
|
|
226
|
-
return root.session
|
|
227
|
-
|
|
228
|
-
return wrapper
|
|
229
|
-
|
|
230
|
-
@classmethod
|
|
231
|
-
def __create_get_session_handle(cls):
|
|
232
|
-
def wrapper(self, obj=None):
|
|
233
|
-
root = self.get_root(obj)
|
|
234
|
-
return getattr(root, "session_handle", None)
|
|
235
|
-
|
|
236
|
-
return wrapper
|
|
237
|
-
|
|
238
|
-
@classmethod
|
|
239
|
-
def __create_get_path(cls):
|
|
240
|
-
def wrapper(self):
|
|
241
|
-
if getattr(self, "_parent", None):
|
|
242
|
-
return self._parent.get_path() + "/" + self._name
|
|
243
|
-
return self._name
|
|
244
|
-
|
|
245
|
-
return wrapper
|
|
246
|
-
|
|
247
|
-
def __new__(cls, name, bases, attrs):
|
|
248
|
-
attrs["get_ancestors_by_type"] = cls.__create_get_ancestors_by_type()
|
|
249
|
-
attrs["get_ancestors_by_name"] = cls.__create_get_ancestors_by_name()
|
|
250
|
-
attrs["get_root"] = cls.__create_get_root()
|
|
251
|
-
attrs["get_session"] = cls.__create_get_session()
|
|
252
|
-
attrs["get_session_handle"] = cls.__create_get_session_handle()
|
|
253
|
-
if "get_path" not in attrs:
|
|
254
|
-
attrs["get_path"] = cls.__create_get_path()
|
|
255
|
-
attrs["root"] = property(lambda self: self.get_root())
|
|
256
|
-
attrs["path"] = property(lambda self: self.get_path())
|
|
257
|
-
attrs["session"] = property(lambda self: self.get_session())
|
|
258
|
-
attrs["session_handle"] = property(lambda self: self.get_session_handle())
|
|
259
|
-
return super(PyLocalBaseMeta, cls).__new__(cls, name, bases, attrs)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
class PyLocalPropertyMeta(PyLocalBaseMeta):
|
|
263
|
-
"""Metaclass for local property classes."""
|
|
264
|
-
|
|
265
|
-
@classmethod
|
|
266
|
-
def __create_validate(cls):
|
|
267
|
-
def wrapper(self, value):
|
|
268
|
-
attrs = getattr(self, "attributes", None)
|
|
269
|
-
if attrs:
|
|
270
|
-
for attr in attrs:
|
|
271
|
-
if attr == "range":
|
|
272
|
-
if self.range and (
|
|
273
|
-
value < self.range[0] or value > self.range[1]
|
|
274
|
-
):
|
|
275
|
-
raise DisallowedValuesError("value", value, self.range)
|
|
276
|
-
elif attr == "allowed_values":
|
|
277
|
-
if isinstance(value, list):
|
|
278
|
-
if not all(
|
|
279
|
-
v is None or v in self.allowed_values for v in value
|
|
280
|
-
):
|
|
281
|
-
raise DisallowedValuesError(
|
|
282
|
-
"value", value, self.allowed_values
|
|
283
|
-
)
|
|
284
|
-
elif value is not None and value not in self.allowed_values:
|
|
285
|
-
raise DisallowedValuesError(
|
|
286
|
-
"value", value, self.allowed_values
|
|
287
|
-
)
|
|
288
|
-
return value
|
|
289
|
-
|
|
290
|
-
return wrapper
|
|
291
|
-
|
|
292
|
-
@classmethod
|
|
293
|
-
def __create_init(cls):
|
|
294
|
-
def wrapper(self, parent, api_helper, name=""):
|
|
295
|
-
"""Create the initialization method for 'PyLocalPropertyMeta'."""
|
|
296
|
-
self._name = name
|
|
297
|
-
self._api_helper = api_helper(self)
|
|
298
|
-
self._parent = parent
|
|
299
|
-
self._on_change_cbs = []
|
|
300
|
-
annotations = self.__class__.__dict__.get("__annotations__")
|
|
301
|
-
if isinstance(getattr(self.__class__, "value", None), property):
|
|
302
|
-
value_annotation = annotations.get("_value")
|
|
303
|
-
else:
|
|
304
|
-
value_annotation = annotations.get("value")
|
|
305
|
-
self.type = value_annotation
|
|
306
|
-
reset_on_change = (
|
|
307
|
-
hasattr(self, "_reset_on_change")
|
|
308
|
-
and getattr(self, "_reset_on_change")()
|
|
309
|
-
)
|
|
310
|
-
|
|
311
|
-
on_change = getattr(self, "on_change", None)
|
|
312
|
-
if on_change is not None:
|
|
313
|
-
self._register_on_change_cb(on_change)
|
|
314
|
-
if reset_on_change:
|
|
315
|
-
for obj in reset_on_change:
|
|
316
|
-
|
|
317
|
-
def reset():
|
|
318
|
-
setattr(self, "_value", None)
|
|
319
|
-
for on_change_cb in self._on_change_cbs:
|
|
320
|
-
on_change_cb()
|
|
321
|
-
|
|
322
|
-
obj._register_on_change_cb(reset)
|
|
323
|
-
|
|
324
|
-
return wrapper
|
|
325
|
-
|
|
326
|
-
@classmethod
|
|
327
|
-
def __create_get_state(cls, show_attributes=False):
|
|
328
|
-
def wrapper(self):
|
|
329
|
-
rv = self.value
|
|
330
|
-
|
|
331
|
-
if hasattr(self, "allowed_values"):
|
|
332
|
-
allowed_values = self.allowed_values
|
|
333
|
-
if len(allowed_values) > 0 and (
|
|
334
|
-
rv is None
|
|
335
|
-
or (not isinstance(rv, list) and rv not in allowed_values)
|
|
336
|
-
):
|
|
337
|
-
self.set_state(allowed_values[0])
|
|
338
|
-
rv = self.value
|
|
339
|
-
|
|
340
|
-
return rv
|
|
341
|
-
|
|
342
|
-
return wrapper
|
|
343
|
-
|
|
344
|
-
@classmethod
|
|
345
|
-
def __create_set_state(cls):
|
|
346
|
-
def wrapper(self, value, validate=True):
|
|
347
|
-
self.value = self._validate(value) if validate else value
|
|
348
|
-
for on_change_cb in self._on_change_cbs:
|
|
349
|
-
on_change_cb()
|
|
350
|
-
|
|
351
|
-
return wrapper
|
|
352
|
-
|
|
353
|
-
@classmethod
|
|
354
|
-
def __create_register_on_change(cls):
|
|
355
|
-
def wrapper(self, on_change_cb):
|
|
356
|
-
self._on_change_cbs.append(on_change_cb)
|
|
357
|
-
|
|
358
|
-
return wrapper
|
|
359
|
-
|
|
360
|
-
@classmethod
|
|
361
|
-
def __create_repr(cls):
|
|
362
|
-
def wrapper(self):
|
|
363
|
-
data = self()
|
|
364
|
-
return f"{data}"
|
|
365
|
-
|
|
366
|
-
return wrapper
|
|
367
|
-
|
|
368
|
-
def __new__(cls, name, bases, attrs):
|
|
369
|
-
attrs["__init__"] = cls.__create_init()
|
|
370
|
-
attrs["__call__"] = cls.__create_get_state()
|
|
371
|
-
attrs["__repr__"] = cls.__create_repr()
|
|
372
|
-
attrs["_validate"] = cls.__create_validate()
|
|
373
|
-
attrs["_register_on_change_cb"] = cls.__create_register_on_change()
|
|
374
|
-
attrs["set_state"] = cls.__create_set_state()
|
|
375
|
-
return super(PyLocalPropertyMeta, cls).__new__(cls, name, bases, attrs)
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
class PyReferenceObjectMeta(PyLocalBaseMeta):
|
|
379
|
-
"""Metaclass for local object classes."""
|
|
380
|
-
|
|
381
|
-
@classmethod
|
|
382
|
-
def __create_init(cls):
|
|
383
|
-
def wrapper(self, parent, path, location, session_id, name=""):
|
|
384
|
-
"""Create the initialization method for 'PyReferenceObjectMeta'."""
|
|
385
|
-
self._parent = parent
|
|
386
|
-
self.type = "object"
|
|
387
|
-
self.parent = parent
|
|
388
|
-
self._path = path
|
|
389
|
-
self.location = location
|
|
390
|
-
self.session_id = session_id
|
|
391
|
-
|
|
392
|
-
def update(clss):
|
|
393
|
-
for name, cls in clss.__dict__.items():
|
|
394
|
-
if cls.__class__.__name__ in (
|
|
395
|
-
"PyLocalPropertyMeta",
|
|
396
|
-
"PyLocalObjectMeta",
|
|
397
|
-
):
|
|
398
|
-
setattr(
|
|
399
|
-
self,
|
|
400
|
-
name,
|
|
401
|
-
cls(self, lambda arg: None, name),
|
|
402
|
-
)
|
|
403
|
-
if (
|
|
404
|
-
cls.__class__.__name__ == "PyLocalNamedObjectMeta"
|
|
405
|
-
or cls.__class__.__name__ == "PyLocalNamedObjectMetaAbstract"
|
|
406
|
-
):
|
|
407
|
-
setattr(
|
|
408
|
-
self,
|
|
409
|
-
cls.PLURAL,
|
|
410
|
-
PyLocalContainer(self, cls, lambda arg: None, cls.PLURAL),
|
|
411
|
-
)
|
|
412
|
-
for base_class in clss.__bases__:
|
|
413
|
-
update(base_class)
|
|
414
|
-
|
|
415
|
-
update(self.__class__)
|
|
416
|
-
|
|
417
|
-
return wrapper
|
|
418
|
-
|
|
419
|
-
@classmethod
|
|
420
|
-
def __create_get_path(cls):
|
|
421
|
-
def wrapper(self):
|
|
422
|
-
return self._path
|
|
423
|
-
|
|
424
|
-
return wrapper
|
|
425
|
-
|
|
426
|
-
@classmethod
|
|
427
|
-
def __create_reset(cls):
|
|
428
|
-
def wrapper(self, path, location, session_id):
|
|
429
|
-
self._path = path
|
|
430
|
-
self.location = location
|
|
431
|
-
self.session_id = session_id
|
|
432
|
-
if hasattr(self, "_object"):
|
|
433
|
-
delattr(self, "_object")
|
|
434
|
-
|
|
435
|
-
return wrapper
|
|
436
|
-
|
|
437
|
-
@classmethod
|
|
438
|
-
def __create_getattr(cls):
|
|
439
|
-
def wrapper(self, item):
|
|
440
|
-
if item == "_object":
|
|
441
|
-
top_most_parent = self.get_root(self)
|
|
442
|
-
|
|
443
|
-
if self.session_id is None:
|
|
444
|
-
self.session_id = top_most_parent.session.id
|
|
445
|
-
property_editor_data = top_most_parent.accessor(
|
|
446
|
-
"AnsysUser", self.session_id
|
|
447
|
-
)
|
|
448
|
-
(
|
|
449
|
-
obj,
|
|
450
|
-
cmd_data,
|
|
451
|
-
) = property_editor_data.get_object_and_command_data_from_properties_info(
|
|
452
|
-
{"path": self.path, "properties": {}, "type": self.location}
|
|
453
|
-
)
|
|
454
|
-
if obj is not None:
|
|
455
|
-
self._object = obj
|
|
456
|
-
return obj
|
|
457
|
-
if item == "ref":
|
|
458
|
-
return self._object._object
|
|
459
|
-
|
|
460
|
-
return wrapper
|
|
461
|
-
|
|
462
|
-
def __new__(cls, name, bases, attrs):
|
|
463
|
-
attrs["__init__"] = attrs.get("__init__", cls.__create_init())
|
|
464
|
-
attrs["__getattr__"] = attrs.get("__getattr__", cls.__create_getattr())
|
|
465
|
-
attrs["reset"] = cls.__create_reset()
|
|
466
|
-
attrs["get_path"] = cls.__create_get_path()
|
|
467
|
-
return super(PyReferenceObjectMeta, cls).__new__(cls, name, bases, attrs)
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
class PyLocalObjectMeta(PyLocalBaseMeta):
|
|
471
|
-
"""Metaclass for local object classes."""
|
|
472
|
-
|
|
473
|
-
@classmethod
|
|
474
|
-
def __create_init(cls):
|
|
475
|
-
def wrapper(self, parent, api_helper, name=""):
|
|
476
|
-
"""Create the initialization method for 'PyLocalObjectMeta'."""
|
|
477
|
-
self._parent = parent
|
|
478
|
-
self._name = name
|
|
479
|
-
self._api_helper = api_helper(self)
|
|
480
|
-
self._command_names = []
|
|
481
|
-
self.type = "object"
|
|
482
|
-
|
|
483
|
-
def update(clss):
|
|
484
|
-
for name, cls in clss.__dict__.items():
|
|
485
|
-
if cls.__class__.__name__ in ("PyLocalCommandMeta"):
|
|
486
|
-
self._command_names.append(name)
|
|
487
|
-
|
|
488
|
-
if cls.__class__.__name__ in (
|
|
489
|
-
"PyLocalPropertyMeta",
|
|
490
|
-
"PyLocalObjectMeta",
|
|
491
|
-
"PyLocalCommandMeta",
|
|
492
|
-
):
|
|
493
|
-
setattr(
|
|
494
|
-
self,
|
|
495
|
-
name,
|
|
496
|
-
cls(self, api_helper, name),
|
|
497
|
-
)
|
|
498
|
-
if (
|
|
499
|
-
cls.__class__.__name__ == "PyLocalNamedObjectMeta"
|
|
500
|
-
or cls.__class__.__name__ == "PyLocalNamedObjectMetaAbstract"
|
|
501
|
-
):
|
|
502
|
-
setattr(
|
|
503
|
-
self,
|
|
504
|
-
cls.PLURAL,
|
|
505
|
-
PyLocalContainer(self, cls, api_helper, cls.PLURAL),
|
|
506
|
-
)
|
|
507
|
-
if cls.__class__.__name__ == "PyReferenceObjectMeta":
|
|
508
|
-
setattr(
|
|
509
|
-
self,
|
|
510
|
-
name,
|
|
511
|
-
cls(self, cls.PATH, cls.LOCATION, cls.SESSION, name),
|
|
512
|
-
)
|
|
513
|
-
for base_class in clss.__bases__:
|
|
514
|
-
update(base_class)
|
|
515
|
-
|
|
516
|
-
update(self.__class__)
|
|
517
|
-
|
|
518
|
-
return wrapper
|
|
519
|
-
|
|
520
|
-
@classmethod
|
|
521
|
-
def __create_getattribute(cls):
|
|
522
|
-
def wrapper(self, name):
|
|
523
|
-
obj = object.__getattribute__(self, name)
|
|
524
|
-
return obj
|
|
525
|
-
|
|
526
|
-
return wrapper
|
|
527
|
-
|
|
528
|
-
@classmethod
|
|
529
|
-
def __create_updateitem(cls):
|
|
530
|
-
def wrapper(self, value):
|
|
531
|
-
properties = value
|
|
532
|
-
sort_by = None
|
|
533
|
-
if hasattr(self, "sort_by"):
|
|
534
|
-
sort_by = self.sort_by
|
|
535
|
-
elif hasattr(self, "include"):
|
|
536
|
-
sort_by = self.include
|
|
537
|
-
if sort_by:
|
|
538
|
-
sorted_properties = {
|
|
539
|
-
prop: properties[prop] for prop in sort_by if prop in properties
|
|
540
|
-
}
|
|
541
|
-
sorted_properties.update(
|
|
542
|
-
{k: v for k, v in properties.items() if k not in sort_by}
|
|
543
|
-
)
|
|
544
|
-
properties.clear()
|
|
545
|
-
properties.update(sorted_properties)
|
|
546
|
-
for name, val in properties.items():
|
|
547
|
-
obj = getattr(self, name)
|
|
548
|
-
if obj.__class__.__class__.__name__ == "PyLocalPropertyMeta":
|
|
549
|
-
obj.set_state(val)
|
|
550
|
-
else:
|
|
551
|
-
if obj.__class__.__class__.__name__ == "PyReferenceObjectMeta":
|
|
552
|
-
obj = obj.ref
|
|
553
|
-
obj.update(val)
|
|
554
|
-
|
|
555
|
-
wrapper.__doc__ = "Update object."
|
|
556
|
-
return wrapper
|
|
557
|
-
|
|
558
|
-
@classmethod
|
|
559
|
-
def __create_get_state(cls):
|
|
560
|
-
def wrapper(self, show_attributes=False):
|
|
561
|
-
state = {}
|
|
562
|
-
|
|
563
|
-
if not getattr(self, "is_active", True):
|
|
564
|
-
return
|
|
565
|
-
|
|
566
|
-
def update_state(clss):
|
|
567
|
-
for name, cls in clss.__dict__.items():
|
|
568
|
-
o = getattr(self, name)
|
|
569
|
-
if o is None or name.startswith("_") or name.startswith("__"):
|
|
570
|
-
continue
|
|
571
|
-
|
|
572
|
-
if cls.__class__.__name__ == "PyReferenceObjectMeta":
|
|
573
|
-
if o.LOCATION == "local":
|
|
574
|
-
o = o.ref
|
|
575
|
-
else:
|
|
576
|
-
continue
|
|
577
|
-
elif cls.__class__.__name__ == "PyLocalCommandMeta":
|
|
578
|
-
args = {}
|
|
579
|
-
for arg in o._args:
|
|
580
|
-
args[arg] = getattr(o, arg)()
|
|
581
|
-
state[name] = args
|
|
582
|
-
if (
|
|
583
|
-
cls.__class__.__name__ == "PyLocalObjectMeta"
|
|
584
|
-
or cls.__class__.__name__ == "PyReferenceObjectMeta"
|
|
585
|
-
):
|
|
586
|
-
if getattr(o, "is_active", True):
|
|
587
|
-
state[name] = o(show_attributes)
|
|
588
|
-
elif (
|
|
589
|
-
cls.__class__.__name__ == "PyLocalNamedObjectMeta"
|
|
590
|
-
or cls.__class__.__name__ == "PyLocalNamedObjectMetaAbstract"
|
|
591
|
-
):
|
|
592
|
-
container = getattr(self, cls.PLURAL)
|
|
593
|
-
if getattr(container, "is_active", True):
|
|
594
|
-
state[cls.PLURAL] = {}
|
|
595
|
-
for child_name in container:
|
|
596
|
-
o = container[child_name]
|
|
597
|
-
if getattr(o, "is_active", True):
|
|
598
|
-
state[cls.PLURAL][child_name] = o()
|
|
599
|
-
|
|
600
|
-
elif cls.__class__.__name__ == "PyLocalPropertyMeta":
|
|
601
|
-
if getattr(o, "is_active", True):
|
|
602
|
-
state[name] = o()
|
|
603
|
-
attrs = show_attributes and getattr(o, "attributes", None)
|
|
604
|
-
if attrs:
|
|
605
|
-
for attr in attrs:
|
|
606
|
-
state[name + "." + attr] = getattr(o, attr)
|
|
607
|
-
|
|
608
|
-
for base_class in clss.__bases__:
|
|
609
|
-
update_state(base_class)
|
|
610
|
-
|
|
611
|
-
update_state(self.__class__)
|
|
612
|
-
return state
|
|
613
|
-
|
|
614
|
-
return wrapper
|
|
615
|
-
|
|
616
|
-
@classmethod
|
|
617
|
-
def __create_setattr(cls):
|
|
618
|
-
def wrapper(self, name, value):
|
|
619
|
-
attr = getattr(self, name, None)
|
|
620
|
-
if attr and attr.__class__.__class__.__name__ == "PyLocalPropertyMeta":
|
|
621
|
-
attr.set_state(value)
|
|
622
|
-
else:
|
|
623
|
-
object.__setattr__(self, name, value)
|
|
624
|
-
|
|
625
|
-
return wrapper
|
|
626
|
-
|
|
627
|
-
@classmethod
|
|
628
|
-
def __create_repr(cls):
|
|
629
|
-
def wrapper(self):
|
|
630
|
-
return pformat(self(True), depth=1, indent=2)
|
|
631
|
-
|
|
632
|
-
return wrapper
|
|
633
|
-
|
|
634
|
-
def __new__(cls, name, bases, attrs):
|
|
635
|
-
attrs["__getattribute__"] = cls.__create_getattribute()
|
|
636
|
-
attrs["__init__"] = attrs.get("__init__", cls.__create_init())
|
|
637
|
-
if "__call__" not in attrs:
|
|
638
|
-
attrs["__call__"] = cls.__create_get_state()
|
|
639
|
-
attrs["__setattr__"] = cls.__create_setattr()
|
|
640
|
-
# attrs["__repr__"] = cls.__create_repr()
|
|
641
|
-
attrs["update"] = cls.__create_updateitem()
|
|
642
|
-
return super(PyLocalObjectMeta, cls).__new__(cls, name, bases, attrs)
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
class PyLocalCommandMeta(PyLocalObjectMeta):
|
|
646
|
-
"""Local object metaclass."""
|
|
647
|
-
|
|
648
|
-
@classmethod
|
|
649
|
-
def __create_init(cls):
|
|
650
|
-
def wrapper(self, parent, api_helper, name=""):
|
|
651
|
-
"""Create the initialization method for 'PyLocalObjectMeta'."""
|
|
652
|
-
self._parent = parent
|
|
653
|
-
self._name = name
|
|
654
|
-
self._api_helper = api_helper(self)
|
|
655
|
-
self.type = "object"
|
|
656
|
-
self._args = []
|
|
657
|
-
self._command_names = []
|
|
658
|
-
self._exe_cmd = getattr(self, "_exe_cmd")
|
|
659
|
-
|
|
660
|
-
def update(clss):
|
|
661
|
-
for name, cls in clss.__dict__.items():
|
|
662
|
-
if cls.__class__.__name__ in (
|
|
663
|
-
"PyLocalCommandArgMeta",
|
|
664
|
-
"PyLocalPropertyMeta",
|
|
665
|
-
):
|
|
666
|
-
self._args.append(name)
|
|
667
|
-
setattr(
|
|
668
|
-
self,
|
|
669
|
-
name,
|
|
670
|
-
cls(self, api_helper, name),
|
|
671
|
-
)
|
|
672
|
-
for base_class in clss.__bases__:
|
|
673
|
-
update(base_class)
|
|
674
|
-
|
|
675
|
-
update(self.__class__)
|
|
676
|
-
|
|
677
|
-
return wrapper
|
|
678
|
-
|
|
679
|
-
@classmethod
|
|
680
|
-
def __execute_command(cls):
|
|
681
|
-
def wrapper(self, **kwargs):
|
|
682
|
-
for arg_name, arg_value in kwargs.items():
|
|
683
|
-
getattr(self, arg_name).set_state(arg_value)
|
|
684
|
-
cmd_args = {}
|
|
685
|
-
for arg_name in self._args:
|
|
686
|
-
cmd_args[arg_name] = getattr(self, arg_name)()
|
|
687
|
-
rv = self._exe_cmd(**cmd_args)
|
|
688
|
-
return rv
|
|
689
|
-
|
|
690
|
-
return wrapper
|
|
691
|
-
|
|
692
|
-
def __new__(cls, name, bases, attrs):
|
|
693
|
-
attrs["__init__"] = cls.__create_init()
|
|
694
|
-
attrs["__call__"] = cls.__execute_command()
|
|
695
|
-
return super(PyLocalCommandMeta, cls).__new__(cls, name, bases, attrs)
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
class PyLocalNamedObjectMeta(PyLocalObjectMeta):
|
|
699
|
-
"""Metaclass for local named object classes."""
|
|
700
|
-
|
|
701
|
-
@classmethod
|
|
702
|
-
def __create_init(cls):
|
|
703
|
-
def wrapper(self, name, parent, api_helper):
|
|
704
|
-
"""Create the initialization method for 'PyLocalNamedObjectMeta'."""
|
|
705
|
-
self._name = name
|
|
706
|
-
self._api_helper = api_helper(self)
|
|
707
|
-
self._parent = parent
|
|
708
|
-
self._command_names = []
|
|
709
|
-
self.type = "object"
|
|
710
|
-
|
|
711
|
-
def update(clss):
|
|
712
|
-
for name, cls in clss.__dict__.items():
|
|
713
|
-
if cls.__class__.__name__ in ("PyLocalCommandMeta"):
|
|
714
|
-
self._command_names.append(name)
|
|
715
|
-
|
|
716
|
-
if cls.__class__.__name__ in (
|
|
717
|
-
"PyLocalPropertyMeta",
|
|
718
|
-
"PyLocalObjectMeta",
|
|
719
|
-
"PyLocalCommandMeta",
|
|
720
|
-
):
|
|
721
|
-
# delete old property if overridden
|
|
722
|
-
if getattr(self, name).__class__.__name__ == name:
|
|
723
|
-
delattr(self, name)
|
|
724
|
-
setattr(
|
|
725
|
-
self,
|
|
726
|
-
name,
|
|
727
|
-
cls(self, api_helper, name),
|
|
728
|
-
)
|
|
729
|
-
elif (
|
|
730
|
-
cls.__class__.__name__ == "PyLocalNamedObjectMeta"
|
|
731
|
-
or cls.__class__.__name__ == "PyLocalNamedObjectMetaAbstract"
|
|
732
|
-
):
|
|
733
|
-
setattr(
|
|
734
|
-
self,
|
|
735
|
-
cls.PLURAL,
|
|
736
|
-
PyLocalContainer(self, cls, api_helper, cls.PLURAL),
|
|
737
|
-
)
|
|
738
|
-
elif cls.__class__.__name__ == "PyReferenceObjectMeta":
|
|
739
|
-
setattr(
|
|
740
|
-
self, name, cls(self, cls.PATH, cls.LOCATION, cls.SESSION)
|
|
741
|
-
)
|
|
742
|
-
for base_class in clss.__bases__:
|
|
743
|
-
update(base_class)
|
|
744
|
-
|
|
745
|
-
update(self.__class__)
|
|
746
|
-
|
|
747
|
-
return wrapper
|
|
748
|
-
|
|
749
|
-
def __new__(cls, name, bases, attrs):
|
|
750
|
-
attrs["__init__"] = cls.__create_init()
|
|
751
|
-
return super(PyLocalNamedObjectMeta, cls).__new__(cls, name, bases, attrs)
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
class PyLocalNamedObjectMetaAbstract(ABCMeta, PyLocalNamedObjectMeta):
|
|
755
|
-
"""Local named object abstract metaclass."""
|
|
756
|
-
|
|
757
|
-
pass
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
class PyLocalContainer(MutableMapping):
|
|
761
|
-
"""Local container for named objects."""
|
|
762
|
-
|
|
763
|
-
def __init__(self, parent, object_class, api_helper, name=""):
|
|
764
|
-
"""Initialize the 'PyLocalContainer' object."""
|
|
765
|
-
self._parent = parent
|
|
766
|
-
self._name = name
|
|
767
|
-
self.__object_class = object_class
|
|
768
|
-
self._local_collection = {}
|
|
769
|
-
self.__api_helper = api_helper
|
|
770
|
-
self.type = "named-object"
|
|
771
|
-
self._command_names = []
|
|
772
|
-
|
|
773
|
-
if hasattr(object_class, "SHOW_AS_SEPARATE_OBJECT"):
|
|
774
|
-
PyLocalContainer.show_as_separate_object = property(
|
|
775
|
-
lambda self: self.__object_class.SHOW_AS_SEPARATE_OBJECT(self)
|
|
776
|
-
)
|
|
777
|
-
if hasattr(object_class, "EXCLUDE"):
|
|
778
|
-
PyLocalContainer.exclude = property(
|
|
779
|
-
lambda self: self.__object_class.EXCLUDE(self)
|
|
780
|
-
)
|
|
781
|
-
if hasattr(object_class, "INCLUDE"):
|
|
782
|
-
PyLocalContainer.include = property(
|
|
783
|
-
lambda self: self.__object_class.INCLUDE(self)
|
|
784
|
-
)
|
|
785
|
-
if hasattr(object_class, "LAYOUT"):
|
|
786
|
-
PyLocalContainer.layout = property(
|
|
787
|
-
lambda self: self.__object_class.LAYOUT(self)
|
|
788
|
-
)
|
|
789
|
-
if hasattr(object_class, "STYLE"):
|
|
790
|
-
PyLocalContainer.style = property(
|
|
791
|
-
lambda self: self.__object_class.STYLE(self)
|
|
792
|
-
)
|
|
793
|
-
if hasattr(object_class, "ICON"):
|
|
794
|
-
PyLocalContainer.icon = property(
|
|
795
|
-
lambda self: self.__object_class.ICON(self)
|
|
796
|
-
)
|
|
797
|
-
if hasattr(object_class, "IS_ACTIVE"):
|
|
798
|
-
PyLocalContainer.is_active = property(
|
|
799
|
-
lambda self: self.__object_class.IS_ACTIVE(self)
|
|
800
|
-
)
|
|
801
|
-
|
|
802
|
-
for name, cls in self.__class__.__dict__.items():
|
|
803
|
-
if cls.__class__.__name__ in ("PyLocalCommandMeta"):
|
|
804
|
-
self._command_names.append(name)
|
|
805
|
-
|
|
806
|
-
if cls.__class__.__name__ in ("PyLocalCommandMeta"):
|
|
807
|
-
setattr(
|
|
808
|
-
self,
|
|
809
|
-
name,
|
|
810
|
-
cls(self, api_helper, name),
|
|
811
|
-
)
|
|
812
|
-
|
|
813
|
-
def update(self, value):
|
|
814
|
-
"""Updates this object with the provided dictionary."""
|
|
815
|
-
for name, val in value.items():
|
|
816
|
-
o = self[name]
|
|
817
|
-
o.update(val)
|
|
818
|
-
|
|
819
|
-
def get_root(self, obj=None):
|
|
820
|
-
"""Returns the top-most parent object."""
|
|
821
|
-
obj = self if obj is None else obj
|
|
822
|
-
parent = obj
|
|
823
|
-
if getattr(obj, "_parent", None):
|
|
824
|
-
parent = self.get_root(obj._parent)
|
|
825
|
-
return parent
|
|
826
|
-
|
|
827
|
-
def get_session(self, obj=None):
|
|
828
|
-
"""Returns the session object."""
|
|
829
|
-
root = self.get_root(obj)
|
|
830
|
-
return root.session
|
|
831
|
-
|
|
832
|
-
def get_path(self):
|
|
833
|
-
"""Path to the current object."""
|
|
834
|
-
if getattr(self, "_parent", None):
|
|
835
|
-
return self._parent.get_path() + "/" + self._name
|
|
836
|
-
return self._name
|
|
837
|
-
|
|
838
|
-
@property
|
|
839
|
-
def path(self):
|
|
840
|
-
"""Path to the current object."""
|
|
841
|
-
return self.get_path()
|
|
842
|
-
|
|
843
|
-
@property
|
|
844
|
-
def session(self):
|
|
845
|
-
"""Returns the session object."""
|
|
846
|
-
return self.get_session()
|
|
847
|
-
|
|
848
|
-
def get_session_handle(self, obj=None):
|
|
849
|
-
"""Returns the session-handle object."""
|
|
850
|
-
root = self.get_root(obj)
|
|
851
|
-
return getattr(root, "session_handle", None)
|
|
852
|
-
|
|
853
|
-
@property
|
|
854
|
-
def session_handle(self):
|
|
855
|
-
"""Returns the session-handle object."""
|
|
856
|
-
return self.get_session_handle()
|
|
857
|
-
|
|
858
|
-
def __iter__(self):
|
|
859
|
-
return iter(self._local_collection)
|
|
860
|
-
|
|
861
|
-
def __len__(self):
|
|
862
|
-
return len(self._local_collection)
|
|
863
|
-
|
|
864
|
-
def __getitem__(self, name):
|
|
865
|
-
o = self._local_collection.get(name, None)
|
|
866
|
-
if not o:
|
|
867
|
-
o = self._local_collection[name] = self.__object_class(
|
|
868
|
-
name, self, self.__api_helper
|
|
869
|
-
)
|
|
870
|
-
on_create = getattr(self._PyLocalContainer__object_class, "on_create", None)
|
|
871
|
-
if on_create:
|
|
872
|
-
on_create(self, name)
|
|
873
|
-
return o
|
|
874
|
-
|
|
875
|
-
def __setitem__(self, name, value):
|
|
876
|
-
o = self[name]
|
|
877
|
-
o.update(value)
|
|
878
|
-
|
|
879
|
-
def __delitem__(self, name):
|
|
880
|
-
del self._local_collection[name]
|
|
881
|
-
on_delete = getattr(self._PyLocalContainer__object_class, "on_delete", None)
|
|
882
|
-
if on_delete:
|
|
883
|
-
on_delete(self, name)
|
|
884
|
-
|
|
885
|
-
def _get_unique_chid_name(self):
|
|
886
|
-
children = list(self)
|
|
887
|
-
index = 0
|
|
888
|
-
while True:
|
|
889
|
-
unique_name = (
|
|
890
|
-
f"{self._PyLocalContainer__object_class.__name__.lower()}-{index}"
|
|
891
|
-
)
|
|
892
|
-
if unique_name not in children:
|
|
893
|
-
break
|
|
894
|
-
index += 1
|
|
895
|
-
return unique_name
|
|
896
|
-
|
|
897
|
-
class Delete(metaclass=PyLocalCommandMeta):
|
|
898
|
-
"""Local delete command."""
|
|
899
|
-
|
|
900
|
-
def _exe_cmd(self, names):
|
|
901
|
-
for item in names:
|
|
902
|
-
self._parent.__delitem__(item)
|
|
903
|
-
|
|
904
|
-
class names(metaclass=PyLocalPropertyMeta):
|
|
905
|
-
"""Local names property."""
|
|
906
|
-
|
|
907
|
-
value: List[str] = []
|
|
908
|
-
|
|
909
|
-
@Attribute
|
|
910
|
-
def allowed_values(self):
|
|
911
|
-
"""Get allowed values."""
|
|
912
|
-
return list(self._parent._parent)
|
|
913
|
-
|
|
914
|
-
class Create(metaclass=PyLocalCommandMeta):
|
|
915
|
-
"""Local create command."""
|
|
916
|
-
|
|
917
|
-
def _exe_cmd(self, name=None):
|
|
918
|
-
if name is None:
|
|
919
|
-
name = self._parent._get_unique_chid_name()
|
|
920
|
-
new_object = self._parent.__getitem__(name)
|
|
921
|
-
return new_object._name
|
|
922
|
-
|
|
923
|
-
class name(metaclass=PyLocalPropertyMeta):
|
|
924
|
-
"""Local name property."""
|
|
925
|
-
|
|
926
|
-
value: str = None
|