Fixed problems with KiCost using internal variants

- The XML didn't remove `variant` field properly (lack of lower)
- THe XML didn't support UTF-8
This commit is contained in:
Salvador E. Tropea 2022-05-18 15:55:28 -03:00
parent 054a090258
commit 23e632303d
10 changed files with 85 additions and 9 deletions

View File

@ -5,9 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- New outputs:
- KiCad netlist generation
- IPC-D-356 netlist generation
- IPC-D-356 netlist generation (#197)
### Fixed
- KiCost+Internal variants: UTF-8 problems
- KiCost+Internal variants: problem with `variant` field capitalization
## [1.0.0] - 2022-05-10
### Added

View File

@ -1907,7 +1907,7 @@ class Schematic(object):
if user_fields:
fields = SubElement(comp, 'fields')
for fname, fvalue in user_fields:
if fname in no_field:
if fname.lower() in no_field:
continue
fld = SubElement(fields, 'field')
fld.set('name', fname)
@ -2026,5 +2026,5 @@ class Schematic(object):
SubElement(root, 'nets')
# Make it look nice
rough_string = tostring(root, encoding='utf8')
reparsed = minidom.parseString(rough_string)
reparsed = minidom.parseString(rough_string.decode('utf8'))
fhandle.write(reparsed.toprettyxml(indent=" ", encoding='UTF-8'))

View File

@ -152,6 +152,7 @@ class KiCostOptions(VariantOptions):
# Write a custom netlist to a temporal dir
net_dir = mkdtemp(prefix='tmp-kibot-kicost-')
netlist = os.path.join(net_dir, GS.sch_basename+'.xml')
logger.debug('Creating variant netlist `{}`'.format(netlist))
with open(netlist, 'wb') as f:
GS.sch.save_netlist(f, self._comps, no_field=var_fields)
else:

View File

@ -79,7 +79,7 @@ class KiCost(BaseVariant): # noqa: F821
return comps
# Apply to all the components
for c in comps:
logger.debug("{} {} {}".format(c.ref, c.fitted, c.included))
logger.debug("{} fitted: {} included: {}".format(c.ref, c.fitted, c.included))
if not (c.fitted and c.included):
# Don't check if we already discarded it
continue

View File

@ -1,6 +1,6 @@
Prj:,KiBom Test Schematic,,,,Board Qty:,100
Co.:,https://github.com/SchrodingersGat/KiBom,,,,Unit Cost:,0
Prj date:,mar 30 mar 2021 09:46:24,,,,Total Cost:,0
Prj date:,,,,,Total Cost:,0
$ date:,,,,,,
Global Part Info,,,,,,
Refs,Value,Footprint,Manf#,Qty,Unit$,Ext$

1 Prj: KiBom Test Schematic Board Qty: 100
2 Co.: https://github.com/SchrodingersGat/KiBom Unit Cost: 0
3 Prj date: mar 30 mar 2021 09:46:24 Total Cost: 0
4 $ date:
5 Global Part Info
6 Refs Value Footprint Manf# Qty Unit$ Ext$

View File

@ -1,6 +1,6 @@
Prj:,KiBom Test Schematic,,,,Board Qty:,100
Co.:,https://github.com/SchrodingersGat/KiBom,,,,Unit Cost:,0
Prj date:,mar 30 mar 2021 09:46:24,,,,Total Cost:,0
Prj date:,,,,,Total Cost:,0
$ date:,,,,,,
Global Part Info,,,,,,
Refs,Value,Footprint,Manf#,Qty,Unit$,Ext$

1 Prj: KiBom Test Schematic Board Qty: 100
2 Co.: https://github.com/SchrodingersGat/KiBom Unit Cost: 0
3 Prj date: mar 30 mar 2021 09:46:24 Total Cost: 0
4 $ date:
5 Global Part Info
6 Refs Value Footprint Manf# Qty Unit$ Ext$

View File

@ -1,6 +1,6 @@
Prj:,KiBom Test Schematic,,,,Board Qty:,100
Co.:,https://github.com/SchrodingersGat/KiBom,,,,Unit Cost:,0
Prj date:,mar 30 mar 2021 09:46:24,,,,Total Cost:,0
Prj date:,,,,,Total Cost:,0
$ date:,,,,,,
Global Part Info,,,,,,
Refs,Value,Footprint,Manf#,Qty,Unit$,Ext$

1 Prj: KiBom Test Schematic Board Qty: 100
2 Co.: https://github.com/SchrodingersGat/KiBom Unit Cost: 0
3 Prj date: mar 30 mar 2021 09:46:24 Total Cost: 0
4 $ date:
5 Global Part Info
6 Refs Value Footprint Manf# Qty Unit$ Ext$

View File

@ -1,6 +1,6 @@
Prj:,KiBom Test Schematic,,,,Board Qty:,100
Co.:,https://github.com/SchrodingersGat/KiBom,,,,Unit Cost:,0
Prj date:,mar 30 mar 2021 09:46:24,,,,Total Cost:,0
Prj date:,,,,,Total Cost:,0
$ date:,,,,,,
Global Part Info,,,,,,
Refs,Value,Footprint,Manf#,Qty,Unit$,Ext$

1 Prj: KiBom Test Schematic Board Qty: 100
2 Co.: https://github.com/SchrodingersGat/KiBom Unit Cost: 0
3 Prj date: mar 30 mar 2021 09:46:24 Total Cost: 0
4 $ date:
5 Global Part Info
6 Refs Value Footprint Manf# Qty Unit$ Ext$

View File

@ -34,7 +34,7 @@ def convert2csv(xlsx, skip_empty=False, sheet=None):
subprocess.check_output(cmd)
with open(csv, 'rt') as f:
content = f.read()
content = re.sub(r'\$ date:,[^,]+', '$ date:,', content, 1)
content = re.sub(r'(\$|Prj) date:,[^,]+', r'\1 date:,', content, 2)
content = re.sub(r'KiCost[^,]+', 'KiCost', content, 1)
content = re.sub(r'KiCad Version:,[^,]+', 'KiCad Version:,', content)
content = re.sub(r'Created:,[^,]+', 'Created:,', content, 1)
@ -64,6 +64,18 @@ def test_kicost_simple(test_dir):
ctx.clean_up()
def test_kicost_int_variant(test_dir):
""" External KiCost using internal variants """
prj = 'kibom-variant_kicost'
ctx = context.TestContextSCH(test_dir, 'test_kicost_int_variant', prj, 'kicost_int_variant', OUT_DIR)
ctx.run(extra_debug=True)
check_simple(ctx, '')
check_simple(ctx, 'default')
check_simple(ctx, 'production')
check_simple(ctx, 'test')
ctx.clean_up()
def test_kicost_bom_simple(test_dir):
""" Internal BoM + KiCost, very simple case. With DNF sheet. """
prj = 'kibom-variant_2c'

View File

@ -0,0 +1,58 @@
# KiCost basic test
kibot:
version: 1
variants:
- name: 'production'
comment: 'Production variant'
type: kicost
file_id: '_(production)'
variant: production
- name: 'test'
comment: 'Test variant'
type: kicost
file_id: '_(test)'
variant: 't.*'
- name: 'default'
comment: 'Default variant'
type: kicost
variant: default
outputs:
- name: 'Costs'
comment: "Components costs spreadsheet"
type: kicost
dir: KiCost
options:
output: 'simple'
no_price: true
no_collapse: true
- name: 'Costs (default)'
comment: "Components costs spreadsheet default variant"
type: kicost
dir: KiCost
options:
output: 'simple_default'
no_price: true
variant: default
- name: 'Costs (production)'
comment: "Components costs spreadsheet production variant"
type: kicost
dir: KiCost
options:
output: 'simple_production'
no_price: true
variant: production
- name: 'Costs (test)'
comment: "Components costs spreadsheet test variant"
type: kicost
dir: KiCost
options:
output: 'simple_test'
no_price: true
variant: test