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.
This commit is contained in:
SET 2020-08-19 11:43:10 -03:00
parent 1836e641e7
commit 520b9626b1
7 changed files with 25 additions and 25 deletions

View File

@ -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()

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)