From 5560c62d146779ceacb8052b6b76febf287cc604 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Wed, 24 Feb 2021 12:58:47 -0300 Subject: [PATCH] Errors and warnings from KiAuto now are printed as is. --- CHANGELOG.md | 3 +++ kibot/kiplot.py | 37 ++++++++++++++++++++++++++----- kibot/misc.py | 1 + tests/test_plot/test_preflight.py | 2 ++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6709f32f..30353628 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `erc_warnings` pre-flight option to consider ERC warnings as errors. +### Changed +- Errors and warnings from KiAuto now are printed as errors and warnings. + ### Fixed - Problem when using E/DRC filters and the output dir didn't exist. diff --git a/kibot/kiplot.py b/kibot/kiplot.py index 261a0721..9686d125 100644 --- a/kibot/kiplot.py +++ b/kibot/kiplot.py @@ -22,7 +22,8 @@ from collections import OrderedDict from .gs import GS from .misc import (PLOT_ERROR, MISSING_TOOL, CMD_EESCHEMA_DO, URL_EESCHEMA_DO, CORRUPTED_PCB, EXIT_BAD_ARGS, CORRUPTED_SCH, EXIT_BAD_CONFIG, WRONG_INSTALL, UI_SMD, UI_VIRTUAL, KICAD_VERSION_5_99, - MOD_SMD, MOD_THROUGH_HOLE, MOD_VIRTUAL, W_PCBNOSCH, W_NONEEDSKIP, W_WRONGCHAR, name2make, W_TIMEOUT) + MOD_SMD, MOD_THROUGH_HOLE, MOD_VIRTUAL, W_PCBNOSCH, W_NONEEDSKIP, W_WRONGCHAR, name2make, W_TIMEOUT, + W_KIAUTO) from .error import PlotError, KiPlotConfigurationError, config_error, trace_dump from .pre_base import BasePreFlight from .kicad.v5_sch import Schematic, SchFileError @@ -131,6 +132,34 @@ def search_as_plugin(cmd, names): return cmd +def extract_errors(text): + in_error = in_warning = False + msg = '' + for line in text.split('\n'): + line += '\n' + if line[0] == ' ' and (in_error or in_warning): + msg += line + else: + if in_error: + in_error = False + logger.error(msg.rstrip()) + elif in_warning: + in_warning = False + logger.warning(W_KIAUTO+msg.rstrip()) + if line.startswith('ERROR:'): + in_error = True + msg = line[6:] + elif line.startswith('WARNING:'): + in_warning = True + msg = line[8:] + if in_error: + in_error = False + logger.error(msg.rstrip()) + elif in_warning: + in_warning = False + logger.warning(W_KIAUTO+msg.rstrip()) + + def exec_with_retry(cmd): logger.debug('Executing: '+str(cmd)) retry = 2 @@ -141,11 +170,9 @@ def exec_with_retry(cmd): if ret > 0 and ret < 128 and retry: logger.debug('Failed with error {}, retrying ...'.format(ret)) else: + extract_errors(result.stderr) err = '> '+result.stderr.replace('\n', '\n> ') - if ret: - logger.error('Output from command:\n'+err) - else: - logger.debug('Output from command:\n'+err) + logger.debug('Output from command:\n'+err) if 'Timed out' in err: logger.warning(W_TIMEOUT+'Time out detected, on slow machines or complex projects try:') logger.warning(W_TIMEOUT+'`kiauto_time_out_scale` and/or `kiauto_wait_start` global options') diff --git a/kibot/misc.py b/kibot/misc.py index 4f9ccfc0..53bdb422 100644 --- a/kibot/misc.py +++ b/kibot/misc.py @@ -175,6 +175,7 @@ W_TIMEOUT = '(W054) ' W_MUSTBEINT = '(W055) ' W_NOOUTPUTS = '(W056) ' W_NOTASCII = '(W057) ' +W_KIAUTO = '(W058) ' class Rect(object): diff --git a/tests/test_plot/test_preflight.py b/tests/test_plot/test_preflight.py index 91f7dac7..7a2f989c 100644 --- a/tests/test_plot/test_preflight.py +++ b/tests/test_plot/test_preflight.py @@ -60,6 +60,7 @@ def test_erc_warning_1(test_dir): ctx.run() # Check all outputs are there ctx.expect_out_file(prj+'-erc.txt') + ctx.search_err(r"WARNING:\(W058\) 1 ERC warnings detected") ctx.clean_up() @@ -70,6 +71,7 @@ def test_erc_warning_2(test_dir): ctx.run(ERC_ERROR) # Check all outputs are there ctx.expect_out_file(prj+'-erc.txt') + ctx.search_err(r"ERROR:1 ERC errors detected") ctx.clean_up()