From 520b9626b1b8f53d86aee9861430d761a3dcaa0d Mon Sep 17 00:00:00 2001 From: SET Date: Wed, 19 Aug 2020 11:43:10 -0300 Subject: [PATCH] Added retry to kicad-automation-scripts stuff. The tests are metastable and fail from time to time. I hope a retry will reduce the fail probability to something tolerable. --- kibot/kiplot.py | 14 +++++++++++++- kibot/out_pdf_pcb_print.py | 6 ++---- kibot/out_pdf_sch_print.py | 6 ++---- kibot/out_svg_sch_print.py | 6 ++---- kibot/pre_drc.py | 6 ++---- kibot/pre_erc.py | 6 ++---- kibot/pre_update_xml.py | 6 ++---- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/kibot/kiplot.py b/kibot/kiplot.py index 03f08f9e..386f4869 100644 --- a/kibot/kiplot.py +++ b/kibot/kiplot.py @@ -13,7 +13,7 @@ import os import re from sys import exit from shutil import which -from subprocess import (run, PIPE) +from subprocess import run, PIPE, call from glob import glob from distutils.version import StrictVersion from importlib.util import (spec_from_file_location, module_from_spec) @@ -116,6 +116,18 @@ def check_eeschema_do(): check_script(CMD_EESCHEMA_DO, URL_EESCHEMA_DO, '1.4.0') +def exec_with_retry(cmd): + logger.debug('Executing: '+str(cmd)) + retry = 2 + while retry: + ret = call(cmd) + retry -= 1 + if ret > 0 and ret < 128 and retry: + logger.debug('Failed with error {}, retrying ...'.format(ret)) + else: + return ret + + def load_board(pcb_file=None): if not pcb_file: GS.check_pcb() diff --git a/kibot/out_pdf_pcb_print.py b/kibot/out_pdf_pcb_print.py index 8c7c2bb9..8c45e7ed 100644 --- a/kibot/out_pdf_pcb_print.py +++ b/kibot/out_pdf_pcb_print.py @@ -3,11 +3,10 @@ # Copyright (c) 2020 Instituto Nacional de TecnologĂ­a Industrial # License: GPL-3.0 # Project: KiBot (formerly KiPlot) -from subprocess import (call) from .pre_base import BasePreFlight from .error import (KiPlotConfigurationError) from .gs import (GS) -from .kiplot import (check_script) +from .kiplot import check_script, exec_with_retry from .misc import (CMD_PCBNEW_PRINT_LAYERS, URL_PCBNEW_PRINT_LAYERS, PDF_PCB_PRINT) from .optionable import BaseOptions from kibot.macros import macros, document, output_class # noqa: F401 @@ -42,8 +41,7 @@ class PDF_Pcb_PrintOptions(BaseOptions): # Add the layers cmd.extend([la.layer for la in layers]) # Execute it - logger.debug('Executing: '+str(cmd)) - ret = call(cmd) + ret = exec_with_retry(cmd) if ret: # pragma: no cover # We check all the arguments, we even load the PCB # A fail here isn't easy to reproduce diff --git a/kibot/out_pdf_sch_print.py b/kibot/out_pdf_sch_print.py index ce521b9e..6699a2a7 100644 --- a/kibot/out_pdf_sch_print.py +++ b/kibot/out_pdf_sch_print.py @@ -4,9 +4,8 @@ # License: GPL-3.0 # Project: KiBot (formerly KiPlot) import os -from subprocess import (call) from .gs import (GS) -from .kiplot import (check_eeschema_do) +from .kiplot import check_eeschema_do, exec_with_retry from .misc import (CMD_EESCHEMA_DO, PDF_SCH_PRINT) from .optionable import BaseOptions from kibot.macros import macros, document, output_class # noqa: F401 @@ -28,8 +27,7 @@ class PDF_Sch_PrintOptions(BaseOptions): if GS.debug_enabled: cmd.insert(1, '-vv') cmd.insert(1, '-r') - logger.debug('Executing: '+str(cmd)) - ret = call(cmd) + ret = exec_with_retry(cmd) if ret: logger.error(CMD_EESCHEMA_DO+' returned %d', ret) exit(PDF_SCH_PRINT) diff --git a/kibot/out_svg_sch_print.py b/kibot/out_svg_sch_print.py index 78685603..d8533f7d 100644 --- a/kibot/out_svg_sch_print.py +++ b/kibot/out_svg_sch_print.py @@ -5,9 +5,8 @@ # License: GPL-3.0 # Project: KiBot (formerly KiPlot) import os -from subprocess import (call) from .gs import (GS) -from .kiplot import (check_eeschema_do) +from .kiplot import check_eeschema_do, exec_with_retry from .misc import (CMD_EESCHEMA_DO, SVG_SCH_PRINT) from .optionable import BaseOptions from kibot.macros import macros, document, output_class # noqa: F401 @@ -29,8 +28,7 @@ class SVG_Sch_PrintOptions(BaseOptions): if GS.debug_enabled: cmd.insert(1, '-vv') cmd.insert(1, '-r') - logger.debug('Executing: '+str(cmd)) - ret = call(cmd) + ret = exec_with_retry(cmd) if ret: logger.error(CMD_EESCHEMA_DO+' returned %d', ret) exit(SVG_SCH_PRINT) diff --git a/kibot/pre_drc.py b/kibot/pre_drc.py index 361b9a48..1df5b989 100644 --- a/kibot/pre_drc.py +++ b/kibot/pre_drc.py @@ -4,11 +4,10 @@ # License: GPL-3.0 # Project: KiBot (formerly KiPlot) from sys import (exit) -from subprocess import (call) from kibot.macros import macros, pre_class # noqa: F401 from .error import (KiPlotConfigurationError) from .gs import (GS) -from .kiplot import (check_script) +from .kiplot import check_script, exec_with_retry from .misc import (CMD_PCBNEW_RUN_DRC, URL_PCBNEW_RUN_DRC, DRC_ERROR) from .log import (get_logger) @@ -38,8 +37,7 @@ class Run_DRC(BasePreFlight): # noqa: F821 cmd.insert(1, '-vv') cmd.insert(1, '-r') logger.info('- Running the DRC') - logger.debug('Executing: '+str(cmd)) - ret = call(cmd) + ret = exec_with_retry(cmd) if ret: if ret > 127: ret = -(256-ret) diff --git a/kibot/pre_erc.py b/kibot/pre_erc.py index 98883e33..1afad21d 100644 --- a/kibot/pre_erc.py +++ b/kibot/pre_erc.py @@ -4,10 +4,9 @@ # License: GPL-3.0 # Project: KiBot (formerly KiPlot) from sys import (exit) -from subprocess import (call) from kibot.macros import macros, pre_class # noqa: F401 from .gs import (GS) -from .kiplot import (check_eeschema_do) +from .kiplot import check_eeschema_do, exec_with_retry from .error import (KiPlotConfigurationError) from .misc import (CMD_EESCHEMA_DO, ERC_ERROR) from .log import (get_logger) @@ -36,8 +35,7 @@ class Run_ERC(BasePreFlight): # noqa: F821 cmd.insert(1, '-vv') cmd.insert(1, '-r') logger.info('- Running the ERC') - logger.debug('Executing: '+str(cmd)) - ret = call(cmd) + ret = exec_with_retry(cmd) if ret: if ret > 127: ret = -(256-ret) diff --git a/kibot/pre_update_xml.py b/kibot/pre_update_xml.py index d6dbff68..a8fbc82e 100644 --- a/kibot/pre_update_xml.py +++ b/kibot/pre_update_xml.py @@ -4,11 +4,10 @@ # License: GPL-3.0 # Project: KiBot (formerly KiPlot) from sys import (exit) -from subprocess import (call) from kibot.macros import macros, pre_class # noqa: F401 from .error import (KiPlotConfigurationError) from .gs import (GS) -from .kiplot import (check_eeschema_do) +from .kiplot import check_eeschema_do, exec_with_retry from .misc import (CMD_EESCHEMA_DO, BOM_ERROR) from .log import (get_logger) @@ -35,8 +34,7 @@ class Update_XML(BasePreFlight): # noqa: F821 cmd.insert(1, '-vv') cmd.insert(1, '-r') logger.info('- Updating BoM in XML format') - logger.debug('Executing: '+str(cmd)) - ret = call(cmd) + ret = exec_with_retry(cmd) if ret: logger.error('Failed to update the BoM, error %d', ret) exit(BOM_ERROR)