Coverage for /Users/buh/.pyenv/versions/3.12.9/envs/es-testbed/lib/python3.12/site-packages/es_testbed/mgrs/entity.py: 93%
41 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-16 12:23 -0600
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-16 12:23 -0600
1"""Entity Class Definition"""
3import typing as t
4from es_testbed.defaults import NAMEMAPPER
6if t.TYPE_CHECKING:
7 from elasticsearch8 import Elasticsearch
8 from dotmap import DotMap
11class EntityMgr:
12 """Entity Manager Parent Class"""
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
25 @property
26 def entity_list(self) -> t.List:
27 """Return the stored list of entities"""
28 return self.plan[self.listname]
30 @entity_list.setter
31 def entity_list(self, value: t.Sequence) -> None:
32 self.plan[self.listname] = value
34 @property
35 def entity_root(self) -> str:
36 """The entity root name builder"""
37 return f'{self.plan.prefix}-{self.ident()}-{self.plan.uniq}'
39 @property
40 def indexlist(self) -> t.Sequence[str]:
41 """Empty attribute/property waiting to be overridden"""
42 return []
44 @property
45 def last(self) -> str:
46 """Return the most recently appended entity"""
47 return self.entity_list[-1]
49 @property
50 def name(self) -> str:
51 """Return the full, incrementing name of a not yet appended entity"""
52 return f'{self.entity_root}{self.suffix}'
54 @property
55 def pattern(self) -> str:
56 """Return the search pattern for the managed entity"""
57 return f'*{self.entity_root}*'
59 @property
60 def suffix(self) -> str:
61 """Return the incrementing index suffix"""
62 return f'-{len(self.entity_list) + 1:06}'
64 def appender(self, name: str) -> None:
65 """Append an item to entity_list"""
66 self.entity_list.append(name)
68 def ident(self, dkey=None) -> str:
69 """Get the formatted name string of the managed entity"""
70 if not dkey:
71 dkey = self.kind
72 return NAMEMAPPER[dkey]
74 def setup(self) -> None:
75 """Setup the entity manager"""
77 def track_index(self, name: str) -> None:
78 """Track an index and append that tracking entity to entity_list"""