In creole template support of %%lead.follower2 and %%lead['follower2'] notation
%if 'follower1' in %%lead now search if a follower exists has follower
This commit is contained in:
parent
1249276b9d
commit
3999969aa0
3 changed files with 35 additions and 11 deletions
|
@ -74,12 +74,21 @@ class RougailLeaderIndex:
|
|||
|
||||
def __getattr__(self, name):
|
||||
if name not in self._follower:
|
||||
raise AttributeError()
|
||||
raise AttributeError(f'unable to find follower "{name}"')
|
||||
value = self._follower[name]
|
||||
if isinstance(value, PropertiesOptionError):
|
||||
raise AttributeError()
|
||||
raise AttributeError(f'unable to access to follower "{name}": {value}')
|
||||
return value
|
||||
|
||||
def __getitem__(self, name):
|
||||
return self.__getattr__(name)
|
||||
|
||||
def __contains__(self, name):
|
||||
if self._follower.__contains__(name):
|
||||
value = self._follower[name]
|
||||
return not isinstance(value, PropertiesOptionError)
|
||||
return False
|
||||
|
||||
def __str__(self):
|
||||
return str(self._value)
|
||||
|
||||
|
@ -141,11 +150,11 @@ class RougailLeader:
|
|||
def __contains__(self, value):
|
||||
return self._value.__contains__(value)
|
||||
|
||||
async def add_follower(self,
|
||||
config,
|
||||
name: str,
|
||||
path: str,
|
||||
):
|
||||
async def _add_follower(self,
|
||||
config,
|
||||
name: str,
|
||||
path: str,
|
||||
):
|
||||
"""Add a new follower
|
||||
"""
|
||||
self._follower[name] = []
|
||||
|
@ -389,10 +398,10 @@ class RougailBaseTemplate:
|
|||
if is_variable_namespace:
|
||||
self.rougail_variables_dict[await suboption.option.name()] = leader
|
||||
else:
|
||||
await leader.add_follower(self.config,
|
||||
await suboption.option.name(),
|
||||
await suboption.option.path(),
|
||||
)
|
||||
await leader._add_follower(self.config,
|
||||
await suboption.option.name(),
|
||||
await suboption.option.path(),
|
||||
)
|
||||
variables[leader_name] = leader
|
||||
else:
|
||||
if is_service_namespace == 'root':
|
||||
|
|
|
@ -1,2 +1,6 @@
|
|||
#attr
|
||||
leader: a
|
||||
follower2:
|
||||
#key
|
||||
leader: a
|
||||
follower2:
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#attr
|
||||
%for %%lead in %%leader
|
||||
leader: %%lead
|
||||
%if %%hasattr(%%lead, 'follower1')
|
||||
|
@ -7,3 +8,13 @@ follower1: %%lead.follower1
|
|||
follower2: %%lead.follower2
|
||||
%end if
|
||||
%end for
|
||||
#key
|
||||
%for %%lead in %%leader
|
||||
leader: %%lead
|
||||
%if 'follower1' in %%lead
|
||||
follower1: %%lead['follower1']
|
||||
%end if
|
||||
%if 'follower2' in %%lead
|
||||
follower2: %%lead['follower2']
|
||||
%end if
|
||||
%end for
|
||||
|
|
Loading…
Reference in a new issue