From b9bd5368c95bbfaffc460576d2de5aa3c07c9921 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 21 Jul 2022 13:03:36 -0300 Subject: [PATCH] Now %V/%v can be expanded in preflights Related to #234 --- kibot/optionable.py | 20 ++++++++++++++++---- kibot/pre_base.py | 6 ++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/kibot/optionable.py b/kibot/optionable.py index d8f7ec01..655f4e42 100644 --- a/kibot/optionable.py +++ b/kibot/optionable.py @@ -212,14 +212,24 @@ class Optionable(object): attrs = self.get_attrs_for() return ((k, v) for k, v in attrs.items() if k[0] != '_') + @staticmethod + def _find_global_variant(): + if GS.solved_global_variant: + return GS.solved_global_variant.file_id + return '' + def _find_variant(self): """ Returns the text to add for the current variant. Also try with the globally defined variant. If no variant is defined an empty string is returned. """ if hasattr(self, 'variant') and self.variant and hasattr(self.variant, 'file_id'): return self.variant.file_id + return Optionable._find_global_variant() + + @staticmethod + def _find_global_variant_name(): if GS.solved_global_variant: - return GS.solved_global_variant.file_id + return GS.solved_global_variant.name return '' def _find_variant_name(self): @@ -228,9 +238,8 @@ class Optionable(object): If no variant is defined an empty string is returned. """ if hasattr(self, 'variant') and self.variant and hasattr(self.variant, 'name'): return self.variant.name - if GS.solved_global_variant: - return GS.solved_global_variant.name - return '' + logger.error('S') + return Optionable._find_global_variant_name() def expand_filename_common(self, name, parent): """ Expansions common to the PCB and Schematic """ @@ -268,6 +277,9 @@ class Optionable(object): if parent and hasattr(parent, 'output_id'): replace_id = _cl(parent.output_id) name = name.replace('%I', replace_id) + else: + name = name.replace('%v', _cl(Optionable._find_global_variant())) + name = name.replace('%V', _cl(Optionable._find_global_variant_name())) return name def expand_filename_both(self, name, is_sch=True, make_safe=True): diff --git a/kibot/pre_base.py b/kibot/pre_base.py index c354411a..4d2c9c8a 100644 --- a/kibot/pre_base.py +++ b/kibot/pre_base.py @@ -138,10 +138,12 @@ class BasePreFlight(Registrable): return Optionable.expand_filename_both(self, out_dir, is_sch=self._sch_related) def _find_variant(self): - return '' + # Preflights doesn't have a variant, but we could have one global default + return Optionable._find_global_variant() def _find_variant_name(self): - return '' + # Preflights doesn't have a variant, but we could have one global default + return Optionable._find_global_variant_name() def ensure_tool(self, name): """ Looks for a mandatory dependency """