Added support for \n and \t to text* options of join

Related to #108
This commit is contained in:
Diego Capusotto 2021-12-14 17:45:10 -03:00
parent 9be560e78d
commit 71c7150baa
6 changed files with 39 additions and 10 deletions

View File

@ -763,10 +763,13 @@ Next time you need this list just use an alias, like this:
- `field`: [string=''] Name of the field.
- `text`: [string=''] Text to use instead of a field. This option is incompatible with the `field` option.
Any space to separate it should be added in the text.
Use \n for newline and \t for tab.
- `text_after`: [string=''] Text to add after the field content. Will be added only if the field isn't empty.
Any space to separate it should be added in the text.
Use \n for newline and \t for tab.
- `text_before`: [string=''] Text to add before the field content. Will be added only if the field isn't empty.
Any space to separate it should be added in the text.
Use \n for newline and \t for tab.
- `level`: [number=0] Used to group columns. The XLSX output uses it to collapse columns.
- `name`: [string=''] Name to display in the header. The field is used when empty.
- `component_aliases`: [list(list(string))] A series of values which are considered to be equivalent for the part name.
@ -789,10 +792,13 @@ Next time you need this list just use an alias, like this:
- `field`: [string=''] Name of the field.
- `text`: [string=''] Text to use instead of a field. This option is incompatible with the `field` option.
Any space to separate it should be added in the text.
Use \n for newline and \t for tab.
- `text_after`: [string=''] Text to add after the field content. Will be added only if the field isn't empty.
Any space to separate it should be added in the text.
Use \n for newline and \t for tab.
- `text_before`: [string=''] Text to add before the field content. Will be added only if the field isn't empty.
Any space to separate it should be added in the text.
Use \n for newline and \t for tab.
- `level`: [number=0] Used to group columns. The XLSX output uses it to collapse columns.
- `name`: [string=''] Name to display in the header. The field is used when empty.
- `count_smd_tht`: [boolean=false] Show the stats about how many of the components are SMD/THT. You must provide the PCB.

View File

@ -94,13 +94,16 @@ outputs:
# [string=''] Name of the field
- field: 'Voltage'
# [string=''] Text to use instead of a field. This option is incompatible with the `field` option.
# Any space to separate it should be added in the text
# Any space to separate it should be added in the text.
# Use \n for newline and \t for tab
text: ''
# [string=''] Text to add after the field content. Will be added only if the field isn't empty.
# Any space to separate it should be added in the text
# Any space to separate it should be added in the text.
# Use \n for newline and \t for tab
text_after: ''
# [string=''] Text to add before the field content. Will be added only if the field isn't empty.
# Any space to separate it should be added in the text
# Any space to separate it should be added in the text.
# Use \n for newline and \t for tab
text_before: ''
# [number=0] Used to group columns. The XLSX output uses it to collapse columns
level: 0
@ -129,13 +132,16 @@ outputs:
# [string=''] Name of the field
- field: 'Voltage'
# [string=''] Text to use instead of a field. This option is incompatible with the `field` option.
# Any space to separate it should be added in the text
# Any space to separate it should be added in the text.
# Use \n for newline and \t for tab
text: ''
# [string=''] Text to add after the field content. Will be added only if the field isn't empty.
# Any space to separate it should be added in the text
# Any space to separate it should be added in the text.
# Use \n for newline and \t for tab
text_after: ''
# [string=''] Text to add before the field content. Will be added only if the field isn't empty.
# Any space to separate it should be added in the text
# Any space to separate it should be added in the text.
# Use \n for newline and \t for tab
text_before: ''
# [number=0] Used to group columns. The XLSX output uses it to collapse columns
level: 0

View File

@ -8,6 +8,7 @@ Internal BoM (Bill of Materials) output for KiBot.
This is somehow compatible with KiBoM.
"""
import os
import re
from .gs import GS
from .misc import W_BADFIELD, W_NEEDSPCB
from .optionable import Optionable, BaseOptions
@ -52,14 +53,24 @@ class BoMJoinField(Optionable):
""" Name of the field """
self.text = ''
""" Text to use instead of a field. This option is incompatible with the `field` option.
Any space to separate it should be added in the text """
Any space to separate it should be added in the text.
Use \\n for newline and \\t for tab """
self.text_before = ''
""" Text to add before the field content. Will be added only if the field isn't empty.
Any space to separate it should be added in the text """
Any space to separate it should be added in the text.
Use \\n for newline and \\t for tab """
self.text_after = ''
""" Text to add after the field content. Will be added only if the field isn't empty.
Any space to separate it should be added in the text """
Any space to separate it should be added in the text.
Use \\n for newline and \\t for tab """
self._field_example = 'Voltage'
self._nl = re.compile(r'([^\\]|^)\\n')
self._tab = re.compile(r'([^\\]|^)\\t')
def unescape(self, text):
text = self._nl.sub(r'\1\n', text)
text = self._tab.sub(r'\1\t', text)
return text
def config(self, parent):
super().config(parent)
@ -73,6 +84,9 @@ class BoMJoinField(Optionable):
self.text_before = ''
if self.text_after is None:
self.text_after = ''
self.text = self.unescape(self.text)
self.text_before = self.unescape(self.text_before)
self.text_after = self.unescape(self.text_after)
def get_text(self, field_getter):
if self.text:

View File

@ -71,6 +71,7 @@ F 5 "C0805C102K5RACTU" H 3750 2500 50 0001 C CNN "manf#"
F 6 "10%" H 3750 2500 50 0001 C CNN "Tolerance"
F 7 "KEMET" H 3750 2500 50 0001 C CNN "manf"
F 8 "50V" H 3750 2500 50 0001 C CNN "Voltage"
F 9 "Alternative" H 3750 2500 50 0001 C CNN "SMN1"
1 3750 2500
1 0 0 -1
$EndComp

View File

@ -651,7 +651,7 @@ def test_int_bom_join_2(test_dir):
value_column = header.index('Value')
check_kibom_test_netlist(rows, ref_column, LINKS_GROUPS+1, [], LINKS_EXCLUDE+LINKS_COMPONENTS)
assert rows[0][ref_column] == 'C1'
assert rows[0][value_column] == '1nF 10% - (50V)'
assert rows[0][value_column] == '1nF 10% - (50V)\nAlternative'
assert rows[0][manf_column] == 'KEMET C0805C102K5RACTU'
assert rows[1][ref_column] == 'J1 J2'
assert rows[1][value_column] == 'Molex KK -'

View File

@ -19,6 +19,8 @@ outputs:
- field: 'Voltage'
text_before: ' ('
text_after: ')'
- field: 'SMN1'
text_before: '\n'
- field: manf
join: manf#
- field: digikey#