fix: adapt api for rougail-web-ui

This commit is contained in:
egarette@silique.fr 2025-10-18 06:40:23 +02:00
parent c1ab106ba5
commit a0843e08ca
3 changed files with 35 additions and 19 deletions

View file

@ -119,27 +119,38 @@ class RougailOutputDoc(Examples, Changelog):
print(data) print(data)
return ret return ret
def load(self, reload=False): def load(self):
self.dynamic_paths = {} self.dynamic_paths = {}
config = self.conf.unrestraint config = self.conf.unrestraint
self._populate_dynamics(config, reload) self.populate_dynamics(config=config)
informations = self.parse_families(config) informations = self.parse_families(config)
if informations is None: if informations is None:
informations = {} informations = {}
self.informations = informations self.informations = informations
def _populate_dynamics(self, family, reload) -> None: def populate_dynamics(self, *, config=None, reload=False):
for child in family.list(): if config is None:
config = self.conf.unrestraint
self._populate_dynamics(config, reload)
def _populate_dynamics(self, family, reload, uncalculated=False) -> None:
def populate(child, uncalculated):
if child.isoptiondescription(): if child.isoptiondescription():
type_ = "family" type_ = "family"
else: else:
type_ = "variable" type_ = "variable"
if child.isdynamic(): if child.isdynamic():
self.populate_dynamic(child, type_, reload) self.populate_dynamic(child, type_, reload, uncalculated)
if child.isoptiondescription(): if not uncalculated and child.isoptiondescription():
self._populate_dynamics(child, reload) self._populate_dynamics(child, reload, uncalculated)
for child in family.list(uncalculated=uncalculated):
populate(child, uncalculated)
if not uncalculated:
for child in family.list(uncalculated=True):
if child.isdynamic() and child.path(uncalculated=True) not in self.dynamic_paths:
populate(family, uncalculated=True)
def populate_dynamic(self, obj, type_, reload) -> None: def populate_dynamic(self, obj, type_, reload, uncalculated) -> None:
path = obj.path(uncalculated=True) path = obj.path(uncalculated=True)
if path not in self.dynamic_paths: if path not in self.dynamic_paths:
new_name = True new_name = True
@ -158,6 +169,8 @@ class RougailOutputDoc(Examples, Changelog):
self.dynamic_paths[path]["description"] = self._convert_description( self.dynamic_paths[path]["description"] = self._convert_description(
description, obj, type_, its_a_path=True description, obj, type_, its_a_path=True
) )
if uncalculated:
return
dynamic_obj = self.dynamic_paths[path] dynamic_obj = self.dynamic_paths[path]
if reload and obj.identifiers() in dynamic_obj["identifiers"]: if reload and obj.identifiers() in dynamic_obj["identifiers"]:
return return
@ -168,7 +181,7 @@ class RougailOutputDoc(Examples, Changelog):
informations = {} informations = {}
leader = None leader = None
for child in family.list(): for child in family.list():
if self._is_inaccessible_user_data(child): if self.is_inaccessible_user_data(child):
continue continue
if child.type(only_self=True) == "symlink": if child.type(only_self=True) == "symlink":
continue continue
@ -178,7 +191,7 @@ class RougailOutputDoc(Examples, Changelog):
self.parse_family(child, informations) self.parse_family(child, informations)
return informations return informations
def _is_inaccessible_user_data(self, child): def is_inaccessible_user_data(self, child):
"""If family is not accessible in read_write mode (to load user_data), """If family is not accessible in read_write mode (to load user_data),
do not comment this family do not comment this family
""" """
@ -199,7 +212,7 @@ class RougailOutputDoc(Examples, Changelog):
uncalculated = variable.value.get(uncalculated=True) uncalculated = variable.value.get(uncalculated=True)
if ( if (
not isinstance(uncalculated, Calculation) not isinstance(uncalculated, Calculation)
and self._is_inaccessible_user_data(variable) and self.is_inaccessible_user_data(variable)
and ( and (
condition == "when" condition == "when"
and value == variable_value and value == variable_value
@ -214,11 +227,11 @@ class RougailOutputDoc(Examples, Changelog):
return True return True
return False return False
def parse_family(self, family, informations: dict) -> None: def parse_family(self, family, informations: dict, *, force_injection=False) -> None:
path = family.path(uncalculated=True) path = family.path(uncalculated=True)
name = family.name(uncalculated=True) name = family.name(uncalculated=True)
sub_informations = self.parse_families(family) sub_informations = self.parse_families(family)
if not sub_informations: if not force_injection and not sub_informations:
return return
# if self.with_family: # if self.with_family:
family_informations = self._populate_family( family_informations = self._populate_family(
@ -709,7 +722,7 @@ class RougailOutputDoc(Examples, Changelog):
if prop in HIDDEN_PROPERTIES: if prop in HIDDEN_PROPERTIES:
return False return False
variable = None variable = None
if variable and self._is_inaccessible_user_data(variable): if variable and self.is_inaccessible_user_data(variable):
try: try:
variable_value = self._get_unmodified_default_value(variable) variable_value = self._get_unmodified_default_value(variable)
except VariableCalculationDependencyError: except VariableCalculationDependencyError:
@ -779,7 +792,7 @@ class RougailOutputDoc(Examples, Changelog):
cpath = calc_path(path, identifiers=identifiers) cpath = calc_path(path, identifiers=identifiers)
if regexp and not regexp.search(cpath): if regexp and not regexp.search(cpath):
continue continue
if self._is_inaccessible_user_data(self.conf.option(cpath)): if self.is_inaccessible_user_data(self.conf.option(cpath)):
if all_is_undocumented is None: if all_is_undocumented is None:
all_is_undocumented = True all_is_undocumented = True
msg = hidden_msg msg = hidden_msg
@ -806,7 +819,7 @@ class RougailOutputDoc(Examples, Changelog):
except AttributeError as err: except AttributeError as err:
pass pass
else: else:
if not isfollower and self._is_inaccessible_user_data(variable): if not isfollower and self.is_inaccessible_user_data(variable):
try: try:
uncalculated = variable.value.get(uncalculated=True) uncalculated = variable.value.get(uncalculated=True)
except PropertiesOptionError: except PropertiesOptionError:
@ -845,6 +858,6 @@ class RougailOutputDoc(Examples, Changelog):
return child.value.get() return child.value.get()
if calculation["type"] == "variable": if calculation["type"] == "variable":
variable = self.conf.forcepermissive.option(calculation["value"]) variable = self.conf.forcepermissive.option(calculation["value"])
if variable and self._is_inaccessible_user_data(variable): if variable and self.is_inaccessible_user_data(variable):
return self._get_unmodified_default_value(variable) return self._get_unmodified_default_value(variable)
raise VariableCalculationDependencyError() raise VariableCalculationDependencyError()

View file

@ -809,7 +809,10 @@ class CommonFormater:
if isinstance(msg, list): if isinstance(msg, list):
if len(msg) == 1: if len(msg) == 1:
submessage, elt = self.message_to_string(msg[0], submessage) submessage, elt = self.message_to_string(msg[0], submessage)
submessage += self.list(elt) if isinstance(elt, list):
submessage += self.list(elt)
else:
submessage += elt
else: else:
lst = [] lst = []
for p in msg: for p in msg:

View file

@ -20,7 +20,7 @@ excludes = [
] ]
test_ok = get_structures_list(excludes) test_ok = get_structures_list(excludes)
test_ok = [HERE.parent.parent / "rougail-tests" / "structures" / "60_0family_dynamic_source_hidden"] #test_ok = [HERE.parent.parent / "rougail-tests" / "structures" / "60_0family_dynamic_source_hidden"]
os.environ['COLUMNS'] = '80' os.environ['COLUMNS'] = '80'