Coverage for /Users/buh/.pyenv/versions/3.12.2/envs/es-testbed/lib/python3.12/site-packages/es_testbed/mgrs/entitymgr.py: 93%
42 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-05-02 11:57 -0600
« prev ^ index » next coverage.py v7.4.4, created at 2024-05-02 11:57 -0600
1"""Entity Class Definition"""
3import typing as t
4from ..defaults import NAMEMAPPER
6if t.TYPE_CHECKING:
7 from elasticsearch8 import Elasticsearch
8 from dotmap import DotMap
10# pylint: disable=missing-docstring,broad-exception-caught,too-many-instance-attributes
13class EntityMgr:
14 kind = 'entity_type'
15 listname = 'entity_mgrs'
17 def __init__(
18 self,
19 client: t.Union['Elasticsearch', None] = None,
20 plan: t.Union['DotMap', None] = None,
21 ):
22 self.client = client
23 self.plan = plan
24 self.success = False
26 @property
27 def entity_list(self) -> t.List:
28 """Return the stored list of entities"""
29 return self.plan[self.listname]
31 @entity_list.setter
32 def entity_list(self, value: t.Sequence) -> None:
33 self.plan[self.listname] = value
35 @property
36 def entity_root(self) -> str:
37 """The entity root name builder"""
38 return f'{self.plan.prefix}-{self.ident()}-{self.plan.uniq}'
40 @property
41 def indexlist(self) -> t.Sequence[str]:
42 """Empty attribute/property waiting to be overridden"""
43 return []
45 @property
46 def last(self) -> str:
47 """Return the most recently appended entity"""
48 return self.entity_list[-1]
50 @property
51 def name(self) -> str:
52 """Return the full, incrementing name of a not yet appended entity"""
53 return f'{self.entity_root}{self.suffix}'
55 @property
56 def pattern(self) -> str:
57 """Return the search pattern for the managed entity"""
58 return f'*{self.entity_root}*'
60 @property
61 def suffix(self) -> str:
62 """Return the incrementing index suffix"""
63 return f'-{len(self.entity_list) + 1:06}'
65 def appender(self, name: str) -> None:
66 """Append an item to entity_list"""
67 self.entity_list.append(name)
69 def ident(self, dkey=None) -> str:
70 """Get the formatted name string of the managed entity"""
71 if not dkey:
72 dkey = self.kind
73 return NAMEMAPPER[dkey]
75 def setup(self) -> None:
76 """Setup the entity manager"""
78 def track_index(self, name: str) -> None:
79 """Track an index and append that tracking entity to entity_list"""