Newer
Older
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
from typing import Dict
from ...engines._DatabaseEngine import _DatabaseEngine
from ..entity._Entity import _Entity
from ..entity.EntityAttributes import EntityAttributes
from ..entity.EntityCollection import EntityCollection
from .Keys import KEY_CONTEXT, KEY_TOPOLOGIES
from .Topology import Topology
VALIDATORS = {}
class Context(_Entity):
def __init__(self, context_uuid : str, database_engine : _DatabaseEngine):
self._database_engine = database_engine
super().__init__(parent=self)
self._context_uuid = context_uuid
self._attributes = EntityAttributes(self, KEY_CONTEXT, validators=VALIDATORS)
self._topologies = EntityCollection(self, KEY_TOPOLOGIES)
@property
def database_engine(self) -> _DatabaseEngine: return self._database_engine
@property
def parent(self) -> 'Context': return self
@property
def context(self) -> 'Context': return self
@property
def context_uuid(self) -> str: return self._context_uuid
@property
def attributes(self) -> EntityAttributes: return self._attributes
@property
def topologies(self) -> EntityCollection: return self._topologies
def topology(self, topology_uuid : str) -> Topology: return Topology(topology_uuid, self)
def create(self) -> 'Context': return self
def delete(self):
for topology_uuid in self.topologies.get(): self.topology(topology_uuid).delete()
def dump(self) -> Dict:
return {topology_uuid : self.topology(topology_uuid).dump() for topology_uuid in self.topologies.get()}