check symlink type for _type in service
This commit is contained in:
@ -38,16 +38,6 @@ ERASED_ATTRIBUTES = ('redefine', 'exists', 'optional', 'remove_check', 'namespac
|
||||
'reflector_object',)
|
||||
|
||||
|
||||
KEY_TYPE = {'variable': 'symlink',
|
||||
'PortOption': 'port',
|
||||
'UnicodeOption': 'string',
|
||||
'NetworkOption': 'network',
|
||||
'NetmaskOption': 'netmask',
|
||||
'URLOption': 'web_address',
|
||||
'FilenameOption': 'filename',
|
||||
}
|
||||
|
||||
|
||||
class ServiceAnnotator:
|
||||
"""Manage service's object
|
||||
for example::
|
||||
@ -122,9 +112,11 @@ class ServiceAnnotator:
|
||||
)
|
||||
family.variable = []
|
||||
activate_obj = self._generate_element('boolean',
|
||||
None,
|
||||
None,
|
||||
'activate',
|
||||
True,
|
||||
elt.xmlfiles,
|
||||
elt,
|
||||
'.'.join([subpath, 'activate']),
|
||||
)
|
||||
for key in dir(elt):
|
||||
@ -137,13 +129,19 @@ class ServiceAnnotator:
|
||||
value,
|
||||
[]).append(activate_obj)
|
||||
continue
|
||||
family.variable.append(self._generate_element(self._get_type(key,
|
||||
elttype,
|
||||
elt,
|
||||
),
|
||||
if key == 'name':
|
||||
dtd_key_type = elttype + '_type'
|
||||
else:
|
||||
dtd_key_type = key + '_type'
|
||||
elt_type = getattr(elt, dtd_key_type, 'string')
|
||||
if elt_type == 'variable':
|
||||
elt_type = 'symlink'
|
||||
family.variable.append(self._generate_element(elt_type,
|
||||
dtd_key_type,
|
||||
elttype,
|
||||
key,
|
||||
value,
|
||||
elt.xmlfiles,
|
||||
elt,
|
||||
f'{subpath}.{key}'
|
||||
))
|
||||
family.variable.append(activate_obj)
|
||||
@ -190,18 +188,26 @@ class ServiceAnnotator:
|
||||
|
||||
def _generate_element(self,
|
||||
type_,
|
||||
dtd_key_type,
|
||||
elttype,
|
||||
key,
|
||||
value,
|
||||
xmlfiles,
|
||||
elt,
|
||||
path,
|
||||
): # pylint: disable=R0913
|
||||
variable = self.objectspace.variable(xmlfiles)
|
||||
variable = self.objectspace.variable(elt.xmlfiles)
|
||||
variable.name = normalize_family(key)
|
||||
variable.mode = None
|
||||
variable.type = type_
|
||||
if type_ == 'symlink':
|
||||
variable.opt = self.objectspace.paths.get_variable(value)
|
||||
variable.multi = None
|
||||
if self.objectspace.types[dtd_key_type] != 'variable' and \
|
||||
variable.opt.type != self.objectspace.types[dtd_key_type]:
|
||||
msg = _(f'"{key}" in "{elttype}" must be a variable with type '
|
||||
f'"{self.objectspace.types[dtd_key_type]}" not "{variable.opt.type}"')
|
||||
raise DictConsistencyError(msg, 58, elt.xmlfiles)
|
||||
|
||||
else:
|
||||
variable.doc = key
|
||||
variable.default = value
|
||||
@ -214,21 +220,6 @@ class ServiceAnnotator:
|
||||
)
|
||||
return variable
|
||||
|
||||
def _get_type(self,
|
||||
key: str,
|
||||
elt_name: str,
|
||||
elt,
|
||||
) -> str:
|
||||
if key == 'name':
|
||||
dtd_key_type = elt_name + '_type'
|
||||
else:
|
||||
dtd_key_type = key + '_type'
|
||||
if key in self.objectspace.booleans_attributs:
|
||||
return 'boolean'
|
||||
if hasattr(elt, dtd_key_type):
|
||||
return KEY_TYPE[getattr(elt, dtd_key_type)]
|
||||
return 'string'
|
||||
|
||||
def _update_override(self,
|
||||
file_,
|
||||
service_name,
|
||||
@ -247,7 +238,7 @@ class ServiceAnnotator:
|
||||
file_,
|
||||
service_name,
|
||||
):
|
||||
if not hasattr(file_, 'file_type') or file_.file_type == "UnicodeOption":
|
||||
if not hasattr(file_, 'file_type') or file_.file_type == "string":
|
||||
if not hasattr(file_, 'source'):
|
||||
file_.source = basename(file_.name)
|
||||
elif not hasattr(file_, 'source'):
|
||||
|
@ -49,21 +49,21 @@
|
||||
<!ATTLIST service name CDATA #REQUIRED>
|
||||
|
||||
<!ELEMENT port (#PCDATA)>
|
||||
<!ATTLIST port port_type (PortOption|variable) "PortOption">
|
||||
<!ATTLIST port port_type (port|variable) "port">
|
||||
<!ATTLIST port portlist CDATA #IMPLIED>
|
||||
<!ATTLIST port protocol (tcp|udp) "tcp">
|
||||
|
||||
<!ELEMENT ip (#PCDATA)>
|
||||
<!ATTLIST ip iplist CDATA #IMPLIED>
|
||||
<!ATTLIST ip ip_type (NetworkOption|variable) "NetworkOption">
|
||||
<!ATTLIST ip interface_type (UnicodeOption|variable) "UnicodeOption">
|
||||
<!ATTLIST ip ip_type (network|variable) "network">
|
||||
<!ATTLIST ip interface_type (string|variable) "string">
|
||||
<!ATTLIST ip interface CDATA #REQUIRED>
|
||||
<!ATTLIST ip netmask_type (NetmaskOption|variable) "NetmaskOption">
|
||||
<!ATTLIST ip netmask_type (netmask|variable) "netmask">
|
||||
<!ATTLIST ip netmask CDATA "255.255.255.255">
|
||||
|
||||
<!ELEMENT file EMPTY>
|
||||
<!ATTLIST file name CDATA #REQUIRED>
|
||||
<!ATTLIST file file_type (UnicodeOption|variable) "UnicodeOption">
|
||||
<!ATTLIST file file_type (string|variable) "string">
|
||||
<!ATTLIST file variable CDATA #IMPLIED>
|
||||
<!ATTLIST file variable_type (variable) "variable">
|
||||
<!ATTLIST file source CDATA #IMPLIED>
|
||||
|
@ -110,6 +110,7 @@ class RougailObjSpace:
|
||||
self.valid_enums = {}
|
||||
self.booleans_attributs = []
|
||||
self.has_dyn_option = False
|
||||
self.types = {}
|
||||
|
||||
self.make_object_space_classes(xmlreflector)
|
||||
self.rougailconfig = rougailconfig
|
||||
@ -141,6 +142,8 @@ class RougailObjSpace:
|
||||
if dtd_attr.name in self.booleans_attributs:
|
||||
default_value = convert_boolean(default_value)
|
||||
attrs[dtd_attr.name] = default_value
|
||||
if dtd_attr.name.endswith('_type'):
|
||||
self.types[dtd_attr.name] = default_value
|
||||
if dtd_attr.name == 'redefine':
|
||||
# has a redefine attribute, so it's a Redefinable object
|
||||
clstype = Redefinable
|
||||
|
Reference in New Issue
Block a user