Moved the fields validation to a seprated methode.

To keep the function complexity lower.
This commit is contained in:
Salvador E. Tropea 2020-08-27 18:03:41 -03:00
parent 58fd473a41
commit c1e63da09a
1 changed files with 10 additions and 7 deletions

View File

@ -668,6 +668,15 @@ class SchematicComponent(object):
if basic < 4:
logger.warning('Component `{}` without the basic fields'.format(self.f_ref))
def _validate(self):
for field in self.fields:
cur_val = field.value
stripped_val = cur_val.strip()
if len(cur_val) != len(stripped_val):
logger.warning("Field {} of component {} contains extra spaces: `{}` removing them.".
format(field.name, self, field.value))
field.value = stripped_val
def __str__(self):
if self.name == self.value:
return '{} ({})'.format(self.ref, self.name)
@ -775,13 +784,7 @@ class SchematicComponent(object):
if GS.debug_level > 1:
logger.debug("- Loaded component {}".format(comp))
# Report abnormal situations
for field in comp.fields:
cur_val = field.value
stripped_val = cur_val.strip()
if len(cur_val) != len(stripped_val):
logger.warning("Field {} of component {} ({}) contains extra spaces: `{}` removing them.".
format(field.name, comp.ref, comp.name, field.value))
field.value = stripped_val
comp._validate()
return comp