From 85acaadf26d4a77ae7ff6d173d684da2b35c2ca8 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 19 Mar 2020 09:57:11 -0300 Subject: [PATCH] Added generation of the BoM in XML format --- kiplot/config_reader.py | 3 +++ kiplot/kiplot.py | 42 ++++++++++++++++++++++++++++++++--------- kiplot/misc.py | 1 + kiplot/plot_config.py | 1 + 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/kiplot/config_reader.py b/kiplot/config_reader.py index 6b5e14db..5e21e8b4 100644 --- a/kiplot/config_reader.py +++ b/kiplot/config_reader.py @@ -484,6 +484,9 @@ class CfgYamlReader(CfgReader): if 'run_erc' in pf: cfg.run_erc = pf['run_erc'] + if 'update_xml' in pf: + cfg.update_xml = pf['update_xml'] + if 'ignore_unconnected' in pf: cfg.ignore_unconnected = pf['ignore_unconnected'] diff --git a/kiplot/kiplot.py b/kiplot/kiplot.py index 0f1d2bbd..5c26fd1c 100644 --- a/kiplot/kiplot.py +++ b/kiplot/kiplot.py @@ -44,6 +44,19 @@ def check_version(command, version): logger.error('Wrong version for `'+command+'` ('+res[0]+'), must be '+version+' or newer.') exit(misc.MISSING_TOOL) +def check_eeschema_do(file): + if which('eeschema_do') is None: + logger.error('No `eeschema_do` command found.\n' + 'Please install it, visit: https://github.com/INTI-CMNB/kicad-automation-scripts') + exit(misc.MISSING_TOOL) + check_version('eeschema_do','1.1.1') + sch_file = os.path.splitext(file)[0] + '.sch' + if not os.path.isfile(sch_file): + logger.error('Missing schematic file: ' + sch_file) + exit(misc.NO_SCH_FILE) + return sch_file + + class PlotError(error.KiPlotError): pass @@ -112,6 +125,9 @@ class Plotter(object): elif skip == 'run_drc': self.cfg.run_drc = False logger.debug('Skipping run_drc') + elif skip == 'update_xml': + self.cfg.update_xml = False + logger.debug('Skipping run_drc') elif skip == 'run_erc': self.cfg.run_erc = False logger.debug('Skipping run_erc') @@ -120,19 +136,13 @@ class Plotter(object): exit(misc.EXIT_BAD_ARGS) if self.cfg.run_erc: self._run_erc(brd_file) + if self.cfg.update_xml: + self._update_xml(brd_file) if self.cfg.run_drc: self._run_drc(brd_file, self.cfg.ignore_unconnected, self.cfg.check_zone_fills) def _run_erc(self, brd_file): - if which('eeschema_do') is None: - logger.error('No `eeschema_do` command found.\n' - 'Please install it, visit: https://github.com/INTI-CMNB/kicad-automation-scripts') - exit(misc.MISSING_TOOL) - check_version('eeschema_do','1.1.1') - sch_file = os.path.splitext(brd_file)[0] + '.sch' - if not os.path.isfile(sch_file): - logger.error('Missing schematic file: ' + sch_file) - exit(misc.NO_SCH_FILE) + sch_file = check_eeschema_do(brd_file) cmd = ['eeschema_do', 'run_erc', sch_file, '.'] # If we are in verbose mode enable debug in the child if logger.getEffectiveLevel() <= logging.DEBUG: @@ -148,6 +158,20 @@ class Plotter(object): logger.error('ERC returned %d', ret) exit(misc.ERC_ERROR) + def _update_xml(self, brd_file): + sch_file = check_eeschema_do(brd_file) + cmd = ['eeschema_do', 'bom_xml', sch_file, '.'] + # If we are in verbose mode enable debug in the child + if logger.getEffectiveLevel() <= logging.DEBUG: + cmd.insert(1, '-vv') + cmd.insert(1, '-r') + logger.info('- Updating BoM in XML format') + logger.debug('Executing: '+str(cmd)) + ret = call(cmd) + if ret: + logger.error('Failed to update the BoM, error %d', ret) + exit(misc.BOM_ERROR) + def _run_drc(self, brd_file, ignore_unconnected, check_zone_fills): if which('pcbnew_run_drc') is None: logger.error('No `pcbnew_run_drc` command found.\n' diff --git a/kiplot/misc.py b/kiplot/misc.py index 0605c42f..7caddf2f 100644 --- a/kiplot/misc.py +++ b/kiplot/misc.py @@ -12,5 +12,6 @@ EXIT_BAD_CONFIG = 7 NO_PCB_FILE = 8 NO_SCH_FILE = 9 ERC_ERROR = 10 +BOM_ERROR = 11 diff --git a/kiplot/plot_config.py b/kiplot/plot_config.py index d51ffe89..0f3caa34 100644 --- a/kiplot/plot_config.py +++ b/kiplot/plot_config.py @@ -463,6 +463,7 @@ class PlotConfig(object): self.check_zone_fills = False self.run_drc = False + self.update_xml = False self.ignore_unconnected = False self.run_erc = False