Simplified exec_with_retry use
- No need to call remove_temporals - We keep temporals when using debug and got a crash - Temporals removed on crash - We inform is temoprals were kept
This commit is contained in:
parent
32325d4a7d
commit
12b3f1e5de
|
|
@ -405,6 +405,11 @@ class GS(object):
|
|||
""" Will be repplaced by kiplot.py """
|
||||
raise AssertionError()
|
||||
|
||||
@staticmethod
|
||||
def exec_with_retry():
|
||||
""" Will be repplaced by kiplot.py """
|
||||
raise AssertionError()
|
||||
|
||||
@staticmethod
|
||||
def load_board_low_level(file):
|
||||
return pcbnew.LoadBoard(file)
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ def exec_with_retry(cmd, exit_with=None):
|
|||
cmd_str = shlex.join(cmd)
|
||||
logger.debug('Executing: '+cmd_str)
|
||||
if GS.debug_level > 2:
|
||||
logger.debug('Command line: '+cmd_str)
|
||||
logger.debug('Command line: '+str(cmd))
|
||||
retry = 2
|
||||
while retry:
|
||||
result = run(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
|
||||
|
|
@ -982,3 +982,4 @@ def generate_examples(start_dir, dry, types):
|
|||
# To avoid circular dependencies: Optionable needs it, but almost everything needs Optionable
|
||||
GS.load_board = load_board
|
||||
GS.load_sch = load_sch
|
||||
GS.exec_with_retry = exec_with_retry
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
import os
|
||||
from .pre_base import BasePreFlight
|
||||
from .gs import GS
|
||||
from .kiplot import exec_with_retry
|
||||
from .misc import PDF_PCB_PRINT
|
||||
from .out_base import VariantOptions
|
||||
from .macros import macros, document, output_class # noqa: F401
|
||||
|
|
@ -97,8 +96,7 @@ class Any_PCB_PrintOptions(VariantOptions):
|
|||
if GS.ki6 and self.force_edge_cuts and not self.separated:
|
||||
cmd.append('Edge.Cuts')
|
||||
# Execute it
|
||||
exec_with_retry(cmd, PDF_PCB_PRINT)
|
||||
self.remove_temporals()
|
||||
self.exec_with_retry(cmd, PDF_PCB_PRINT)
|
||||
|
||||
def set_layers(self, layers):
|
||||
layers = Layer.solve(layers)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import os
|
|||
from tempfile import mkdtemp
|
||||
from shutil import copy2
|
||||
from .gs import GS
|
||||
from .kiplot import exec_with_retry
|
||||
from .out_base import VariantOptions
|
||||
from .kicad.config import KiConf
|
||||
from .macros import macros, document, output_class # noqa: F401
|
||||
|
|
@ -68,5 +67,4 @@ class Any_SCH_PrintOptions(VariantOptions):
|
|||
if self.all_pages:
|
||||
cmd.append('--all_pages')
|
||||
cmd.extend([sch_file, os.path.dirname(name)])
|
||||
exec_with_retry(self.add_extra_options(cmd), self._exit_error)
|
||||
self.remove_temporals()
|
||||
self.exec_with_retry(self.add_extra_options(cmd), self._exit_error)
|
||||
|
|
|
|||
|
|
@ -949,6 +949,18 @@ class VariantOptions(BaseOptions):
|
|||
self._files_to_remove.append(os.path.join(dir or cmd[-1], GS.get_kiauto_video_name(cmd)))
|
||||
return cmd
|
||||
|
||||
def exec_with_retry(self, cmd, exit_with):
|
||||
try:
|
||||
GS.exec_with_retry(cmd, exit_with)
|
||||
finally:
|
||||
if GS.debug_enabled:
|
||||
if self._files_to_remove:
|
||||
logger.error('Keeping temporal files: '+str(self._files_to_remove))
|
||||
else:
|
||||
self.remove_temporals()
|
||||
if self._files_to_remove:
|
||||
self.remove_temporals()
|
||||
|
||||
def run(self, output_dir):
|
||||
""" Makes the list of components available """
|
||||
self._files_to_remove = []
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import os
|
|||
from .gs import GS
|
||||
from .out_base import VariantOptions
|
||||
from .misc import FAILED_EXECUTE
|
||||
from .kiplot import exec_with_retry
|
||||
from .macros import macros, document, output_class # noqa: F401
|
||||
from . import log
|
||||
|
||||
|
|
@ -62,8 +61,7 @@ class GenCADOptions(VariantOptions):
|
|||
cmd.extend([board_name, os.path.dirname(name)])
|
||||
cmd = self.add_extra_options(cmd)
|
||||
# Execute it
|
||||
exec_with_retry(cmd, FAILED_EXECUTE)
|
||||
self.remove_temporals()
|
||||
self.exec_with_retry(cmd, FAILED_EXECUTE)
|
||||
|
||||
|
||||
@output_class
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import os
|
|||
from .gs import GS
|
||||
from .out_base import VariantOptions
|
||||
from .misc import FAILED_EXECUTE
|
||||
from .kiplot import exec_with_retry
|
||||
from .macros import macros, document, output_class # noqa: F401
|
||||
from . import log
|
||||
|
||||
|
|
@ -60,8 +59,7 @@ class NetlistOptions(VariantOptions):
|
|||
# Create the command line
|
||||
cmd = self.add_extra_options([command, subcommand, '--output_name', name, file, os.path.dirname(name)])
|
||||
# Execute it
|
||||
exec_with_retry(cmd, FAILED_EXECUTE)
|
||||
self.remove_temporals()
|
||||
self.exec_with_retry(cmd, FAILED_EXECUTE)
|
||||
|
||||
|
||||
@output_class
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ from .kicad.config import KiConf
|
|||
from .kicad.v5_sch import SchError
|
||||
from .kicad.pcb import PCB
|
||||
from .misc import PDF_PCB_PRINT, W_PDMASKFAIL, KICAD5_SVG_SCALE, W_MISSTOOL, PCBDRAW_ERR, W_PCBDRAW
|
||||
from .kiplot import exec_with_retry
|
||||
from .create_pdf import create_pdf_from_pages
|
||||
from .macros import macros, document, output_class # noqa: F401
|
||||
from .drill_marks import DRILL_MARKS_MAP, add_drill_marks
|
||||
|
|
@ -485,10 +484,9 @@ class PCB_PrintOptions(VariantOptions):
|
|||
cmd = [command, 'export', '--output_name', output, '--monochrome', '--svg', '--pads', '0',
|
||||
pcb_name, dir_name, layer]
|
||||
# Execute it
|
||||
exec_with_retry(self.add_extra_options(cmd, dir_name), PDF_PCB_PRINT)
|
||||
self.exec_with_retry(self.add_extra_options(cmd, dir_name), PDF_PCB_PRINT)
|
||||
# Rotate the paper size if needed and remove the background (or it will be over the drawings)
|
||||
patch_svg_file(output, remove_bkg=True, is_portrait=self.paper_portrait)
|
||||
self.remove_temporals()
|
||||
self._files_to_remove = cur_files_to_remove
|
||||
|
||||
def plot_pads(self, la, pc, p, filelist):
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import subprocess
|
|||
from .misc import (RENDER_3D_ERR, PCB_MAT_COLORS, PCB_FINISH_COLORS, SOLDER_COLORS, SILK_COLORS,
|
||||
KICAD_VERSION_6_0_2, MISSING_TOOL)
|
||||
from .gs import GS
|
||||
from .kiplot import exec_with_retry, load_sch, get_board_comps_data
|
||||
from .kiplot import load_sch, get_board_comps_data
|
||||
from .optionable import Optionable
|
||||
from .out_base_3d import Base3DOptions, Base3D
|
||||
from .macros import macros, document, output_class # noqa: F401
|
||||
|
|
@ -301,8 +301,7 @@ class Render3DOptions(Base3DOptions):
|
|||
self.undo_show_components()
|
||||
cmd.extend([board_name, os.path.dirname(output)])
|
||||
# Execute it
|
||||
exec_with_retry(self.add_extra_options(cmd), RENDER_3D_ERR)
|
||||
self.remove_temporals()
|
||||
self.exec_with_retry(self.add_extra_options(cmd), RENDER_3D_ERR)
|
||||
if self.auto_crop:
|
||||
_run_command([convert_command, output, '-trim', '+repage', '-trim', '+repage', output])
|
||||
if self.transparent_background:
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ from .error import KiPlotConfigurationError
|
|||
from .misc import KICAD2STEP_ERR
|
||||
from .gs import GS
|
||||
from .out_base_3d import Base3DOptions, Base3D
|
||||
from .kiplot import exec_with_retry
|
||||
from .macros import macros, document, output_class # noqa: F401
|
||||
from . import log
|
||||
|
||||
|
|
@ -85,8 +84,7 @@ class STEPOptions(Base3DOptions):
|
|||
board_name = self.filter_components()
|
||||
cmd.append(board_name)
|
||||
# Execute it
|
||||
exec_with_retry(self.add_extra_options(cmd, os.path.dirname(output)), KICAD2STEP_ERR)
|
||||
self.remove_temporals()
|
||||
self.exec_with_retry(self.add_extra_options(cmd, os.path.dirname(output)), KICAD2STEP_ERR)
|
||||
|
||||
|
||||
@output_class
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import os
|
|||
from .gs import GS
|
||||
from .out_base_3d import Base3DOptions, Base3D
|
||||
from .misc import FAILED_EXECUTE
|
||||
from .kiplot import exec_with_retry
|
||||
from .macros import macros, document, output_class # noqa: F401
|
||||
from . import log
|
||||
|
||||
|
|
@ -76,8 +75,7 @@ class VRMLOptions(Base3DOptions):
|
|||
cmd.extend(['-x', str(x), '-y', str(x), '-u', units])
|
||||
cmd.extend([board_name, os.path.dirname(name)])
|
||||
# Execute it
|
||||
exec_with_retry(self.add_extra_options(cmd), FAILED_EXECUTE)
|
||||
self.remove_temporals()
|
||||
self.exec_with_retry(self.add_extra_options(cmd), FAILED_EXECUTE)
|
||||
|
||||
|
||||
@output_class
|
||||
|
|
|
|||
|
|
@ -173,6 +173,19 @@ class BasePreFlight(Registrable):
|
|||
self._files_to_remove.append(os.path.join(dir or cmd[-1], GS.get_kiauto_video_name(cmd)))
|
||||
return cmd
|
||||
|
||||
def exec_with_retry(self, cmd, exit_with=None):
|
||||
try:
|
||||
ret = GS.exec_with_retry(cmd, exit_with)
|
||||
finally:
|
||||
if GS.debug_enabled:
|
||||
if self._files_to_remove:
|
||||
logger.error('Keeping temporal files: '+str(self._files_to_remove))
|
||||
else:
|
||||
self.remove_temporals()
|
||||
if self._files_to_remove:
|
||||
self.remove_temporals()
|
||||
return ret
|
||||
|
||||
def remove_temporals(self):
|
||||
logger.debug('Removing temporal files')
|
||||
for f in self._files_to_remove:
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ from .macros import macros, pre_class # noqa: F401
|
|||
from .error import KiPlotConfigurationError
|
||||
from .gs import GS
|
||||
from .optionable import Optionable
|
||||
from .kiplot import exec_with_retry, load_board
|
||||
from .kiplot import load_board
|
||||
from .misc import DRC_ERROR
|
||||
from .log import get_logger
|
||||
|
||||
|
|
@ -63,8 +63,7 @@ class Run_DRC(BasePreFlight): # noqa: F821
|
|||
# If we are in verbose mode enable debug in the child
|
||||
cmd = self.add_extra_options(cmd)
|
||||
logger.info('- Running the DRC')
|
||||
ret = exec_with_retry(cmd)
|
||||
self.remove_temporals()
|
||||
ret = self.exec_with_retry(cmd)
|
||||
if ret:
|
||||
if ret > 127:
|
||||
ret = -(256-ret)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2020-2022 Salvador E. Tropea
|
||||
# Copyright (c) 2020-2022 Instituto Nacional de Tecnología Industrial
|
||||
# Copyright (c) 2020-2023 Salvador E. Tropea
|
||||
# Copyright (c) 2020-2023 Instituto Nacional de Tecnología Industrial
|
||||
# License: GPL-3.0
|
||||
# Project: KiBot (formerly KiPlot)
|
||||
"""
|
||||
|
|
@ -15,7 +15,7 @@ from sys import exit
|
|||
from .macros import macros, pre_class # noqa: F401
|
||||
from .gs import GS
|
||||
from .optionable import Optionable
|
||||
from .kiplot import exec_with_retry, load_sch
|
||||
from .kiplot import load_sch
|
||||
from .error import KiPlotConfigurationError
|
||||
from .misc import ERC_ERROR
|
||||
from .log import get_logger
|
||||
|
|
@ -62,8 +62,7 @@ class Run_ERC(BasePreFlight): # noqa: F821
|
|||
# If we are in verbose mode enable debug in the child
|
||||
cmd = self.add_extra_options(cmd)
|
||||
logger.info('- Running the ERC')
|
||||
ret = exec_with_retry(cmd)
|
||||
self.remove_temporals()
|
||||
ret = self.exec_with_retry(cmd)
|
||||
if ret:
|
||||
if ret > 127:
|
||||
ret = -(256-ret)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import xml.etree.ElementTree as ET
|
|||
from .macros import macros, document, pre_class # noqa: F401
|
||||
from .error import KiPlotConfigurationError
|
||||
from .gs import GS
|
||||
from .kiplot import exec_with_retry, load_board
|
||||
from .kiplot import load_board
|
||||
from .misc import BOM_ERROR, NETLIST_DIFF, W_PARITY, MISSING_TOOL
|
||||
from .log import get_logger
|
||||
from .optionable import Optionable
|
||||
|
|
@ -177,7 +177,6 @@ class Update_XML(BasePreFlight): # noqa: F821
|
|||
if not os.path.isfile(side_effect_file):
|
||||
self._files_to_remove.append(side_effect_file)
|
||||
logger.info('- Updating BoM in XML format')
|
||||
exec_with_retry(cmd, BOM_ERROR)
|
||||
self.remove_temporals()
|
||||
self.exec_with_retry(cmd, BOM_ERROR)
|
||||
if self._check_pcb_parity:
|
||||
self.check_pcb_parity()
|
||||
|
|
|
|||
Loading…
Reference in New Issue