remove servcice_elt_attr_list

This commit is contained in:
Emmanuel Garette 2020-02-14 21:34:47 +01:00
parent 25d5307415
commit d8e99fef54
2 changed files with 15 additions and 21 deletions

View File

@ -114,21 +114,21 @@ class ServiceAnnotator:
def convert_service_to_family(self, service_name, service_family, service): def convert_service_to_family(self, service_name, service_family, service):
# tranform service object to family object # tranform service object to family object
# add services, service_accesses, ... # add services, service_accesses, ...
for elttype in self.objectspace.service_elt_attr_list: for elttype, values in vars(service).items():
if hasattr(service, elttype): if elttype in ['name', 'index']:
family = self.objectspace.family() continue
if elttype.endswith('s'): family = self.objectspace.family()
family.name = elttype + 'es' if elttype.endswith('s'):
else: family.name = elttype + 'es'
family.name = elttype + 's' else:
values = getattr(service, elttype) family.name = elttype + 's'
if isinstance(values, dict): if isinstance(values, dict):
values = list(values.values()) values = list(values.values())
family.family = self.convert_subelement_service(elttype, family.family = self.convert_subelement_service(elttype,
values, values,
'services.{}.{}'.format(service_name, family.name)) 'services.{}.{}'.format(service_name, family.name))
family.mode = None family.mode = None
service_family[family.name] = family service_family[family.name] = family
def convert_subelement_service(self, name, elts, path): def convert_subelement_service(self, name, elts, path):
families = [] families = []

View File

@ -86,8 +86,6 @@ class CreoleObjSpace(object):
self.redefine_variables = None self.redefine_variables = None
self.probe_variables = [] self.probe_variables = []
# elt service's attrs list
self.service_elt_attr_list = [] #
# ['variable', 'separator', 'family'] # ['variable', 'separator', 'family']
self.forced_text_elts = set() self.forced_text_elts = set()
# ['disknod', 'follower', 'target', 'service', 'package', 'ip', 'value', 'tcpwrapper', # ['disknod', 'follower', 'target', 'service', 'package', 'ip', 'value', 'tcpwrapper',
@ -107,7 +105,6 @@ class CreoleObjSpace(object):
if elt.type == 'mixed': if elt.type == 'mixed':
forced_text_elt = True forced_text_elt = True
if elt.name == 'service': if elt.name == 'service':
self.service_elt_attr_list = [elt.content.left.name]
self.parse_dtd_right_left_elt(elt.content) self.parse_dtd_right_left_elt(elt.content)
for attr in elt.iterattributes(): for attr in elt.iterattributes():
atomic = False atomic = False
@ -152,10 +149,7 @@ class CreoleObjSpace(object):
def parse_dtd_right_left_elt(self, elt): def parse_dtd_right_left_elt(self, elt):
if elt.right.type == 'or': if elt.right.type == 'or':
self.service_elt_attr_list.append(elt.right.left.name)
self.parse_dtd_right_left_elt(elt.right) self.parse_dtd_right_left_elt(elt.right)
else:
self.service_elt_attr_list.append(elt.right.name)
def _convert_boolean(self, value): # pylint: disable=R0201 def _convert_boolean(self, value): # pylint: disable=R0201
"""Boolean coercion. The Creole XML may contain srings like `True` or `False` """Boolean coercion. The Creole XML may contain srings like `True` or `False`