fix: better namespace support

This commit is contained in:
egarette@silique.fr 2025-12-19 13:34:58 +01:00
parent 5f17a1f086
commit 601f842772

View file

@ -20,6 +20,7 @@ from typing import Any, List, Optional
from json import dumps from json import dumps
from tiramisu import groups
from tiramisu.error import PropertiesOptionError, ConfigError from tiramisu.error import PropertiesOptionError, ConfigError
from rougail.error import ExtensionError from rougail.error import ExtensionError
@ -50,6 +51,11 @@ class RougailOutputJson:
) )
self.rougailconfig = rougailconfig self.rougailconfig = rougailconfig
self.config = config self.config = config
try:
groups.namespace
self.support_namespace = True
except AttributeError:
self.support_namespace = False
if user_data_errors: if user_data_errors:
self.errors = user_data_errors self.errors = user_data_errors
else: else:
@ -81,8 +87,6 @@ class RougailOutputJson:
self.config.property.read_write() self.config.property.read_write()
self.mandatory() self.mandatory()
self.config.property.importation(ori_properties) self.config.property.importation(ori_properties)
if self.manage_errors():
return False
self.manage_warnings() self.manage_warnings()
if self.get: if self.get:
config = self.config.option(self.get) config = self.config.option(self.get)
@ -94,8 +98,9 @@ class RougailOutputJson:
self.parse_family( self.parse_family(
config, config,
self.dico, self.dico,
None,
) )
return True return self.manage_errors()
def mandatory(self): def mandatory(self):
title = False title = False
@ -144,6 +149,7 @@ class RougailOutputJson:
self, self,
conf, conf,
child, child,
namespace,
): ):
for option in conf: for option in conf:
if option.isoptiondescription(): if option.isoptiondescription():
@ -154,10 +160,17 @@ class RougailOutputJson:
parent, parent,
) )
else: else:
if namespace is None and self.support_namespace and option.group_type() is groups.namespace:
subnamespace = option.name()
else:
subnamespace = namespace
parent = {} parent = {}
self.parse_family(option, parent) self.parse_family(option, parent, subnamespace)
child[option.name()] = parent child[option.name()] = parent
else: else:
self.parse_variable(option, child)
def parse_variable(self, option, child):
child[option.name()] = option.value.get() child[option.name()] = option.value.get()
def parse_leadership( def parse_leadership(