From c1e63da09a389db19f199456be1c432811ab3f9f Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 27 Aug 2020 18:03:41 -0300 Subject: [PATCH] Moved the fields validation to a seprated methode. To keep the function complexity lower. --- kibot/kicad/v5_sch.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/kibot/kicad/v5_sch.py b/kibot/kicad/v5_sch.py index da8f9f6d..bb21781b 100644 --- a/kibot/kicad/v5_sch.py +++ b/kibot/kicad/v5_sch.py @@ -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