Changed %v/%V to also icnlude the global variant

Closes #104
This commit is contained in:
Salvador E. Tropea 2021-11-22 16:22:52 -03:00
parent 49ea1bb62a
commit f9a2aac01b
6 changed files with 25 additions and 4 deletions

View File

@ -35,6 +35,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- JLCPCB example, to match current recommendations
(g200kg/kicad-gerberzipper#11)
- Internal BoM: the field used for variants doesn't produce conflicts. (#100)
- The `%v/%V` expansion patterns now expand to the global variant when used in
a context not related to variants. I.e. when a `compress` target expands
`%v`.
### Fixed
- Position files now defaults to use the auxiliar origin as KiCad.

View File

@ -209,8 +209,8 @@ The pattern uses the following expansions:
- **%r** revision from pcb/sch metadata.
- **%T** time the script was started.
- **%x** a suitable extension for the output type.
- **%v** the `file_id` of the current variant.
- **%V** the `name` of the current variant.
- **%v** the `file_id` of the current variant, or the global variant if outside a variant scope.
- **%V** the `name` of the current variant, or the global variant if outside a variant scope.
They are compatible with the ones used by IBoM.
The default value for `global.output` is `%f-%i.%x`.

View File

@ -188,8 +188,8 @@ The pattern uses the following expansions:
- **%r** revision from pcb/sch metadata.
- **%T** time the script was started.
- **%x** a suitable extension for the output type.
- **%v** the `file_id` of the current variant.
- **%V** the `name` of the current variant.
- **%v** the `file_id` of the current variant, or the global variant if outside a variant scope.
- **%V** the `name` of the current variant, or the global variant if outside a variant scope.
They are compatible with the ones used by IBoM.
The default value for `global.output` is `%f-%i.%x`.

View File

@ -355,6 +355,9 @@ class CfgYamlReader(object):
config_error('Unknown section `{}` in config.'.format(k))
if version is None:
config_error("YAML config needs `kibot.version`.")
# Solve the global variant
if GS.global_variant:
GS.solved_global_variant = RegOutput.check_variant(GS.global_variant)
return outputs

View File

@ -72,6 +72,7 @@ class GS(object):
global_output = None
global_dir = None
global_variant = None
solved_global_variant = None
global_kiauto_wait_start = None
global_kiauto_time_out_scale = None
global_opts_class = None

View File

@ -190,21 +190,29 @@ class Optionable(object):
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
if GS.solved_global_variant:
return GS.solved_global_variant.file_id
return ''
def _find_variant_name(self):
""" Returns the name 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, 'name'):
return self.variant.name
if GS.solved_global_variant:
return GS.solved_global_variant.name
return ''
def expand_filename_pcb(self, name):
""" Expands %* values in filenames.
Uses data from the PCB. """
if GS.debug_level > 3:
logger.debug('Expanding `{}` in PCB context for {} parent: {}'.format(name, self, self._parent))
if GS.board:
GS.load_pcb_title_block()
# Do the replacements
@ -223,11 +231,15 @@ class Optionable(object):
# sanitize the name to avoid characters illegal in file systems
name = name.replace('\\', '/')
name = re.sub(r'[?%*:|"<>]', '_', name)
if GS.debug_level > 3:
logger.debug('Expanded `{}`'.format(name))
return name
def expand_filename_sch(self, name):
""" Expands %* values in filenames.
Uses data from the SCH. """
if GS.debug_level > 3:
logger.debug('Expanding `{}` in sch context for {}'.format(name, self))
if GS.sch_file:
GS.load_sch_title_block()
# Do the replacements
@ -246,6 +258,8 @@ class Optionable(object):
# sanitize the name to avoid characters illegal in file systems
name = name.replace('\\', '/')
name = re.sub(r'[?%*:|"<>]', '_', name)
if GS.debug_level > 3:
logger.debug('Expanded `{}`'.format(name))
return name
@staticmethod