From 560ce80c7dd9e78f65d834644f77bf28f5d48774 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Fri, 2 Sep 2022 08:49:39 -0300 Subject: [PATCH] [Debug] Logged executed command in a cut & paste friendly way Closes #269 --- kibot/kiplot.py | 6 ++++-- kibot/out_diff.py | 3 ++- kibot/out_navigate_results.py | 3 ++- kibot/out_pcb_print.py | 3 ++- kibot/out_pcbdraw.py | 3 ++- kibot/out_report.py | 3 ++- kibot/out_step.py | 3 ++- 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/kibot/kiplot.py b/kibot/kiplot.py index 9a3e0676..97b13134 100644 --- a/kibot/kiplot.py +++ b/kibot/kiplot.py @@ -13,6 +13,7 @@ import os import re from sys import exit from sys import path as sys_path +import shlex from shutil import which from subprocess import run, PIPE, Popen from glob import glob @@ -139,9 +140,10 @@ def extract_errors(text): def exec_with_retry(cmd): - logger.debug('Executing: '+' '.join(cmd)) + cmd_str = shlex.join(cmd) + logger.debug('Executing: '+cmd_str) if GS.debug_level > 2: - logger.debug('Command line: '+' '.join(cmd)) + logger.debug('Command line: '+cmd_str) retry = 2 while retry: result = run(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True) diff --git a/kibot/out_diff.py b/kibot/out_diff.py index 448451ae..b8f9e5ae 100644 --- a/kibot/out_diff.py +++ b/kibot/out_diff.py @@ -21,6 +21,7 @@ Dependencies: """ from hashlib import sha1 import os +import shlex from shutil import rmtree, copy2 from subprocess import run, CalledProcessError, STDOUT, PIPE from tempfile import mkdtemp, NamedTemporaryFile @@ -43,7 +44,7 @@ def debug_output(res): def run_command(command, change_to=None): - logger.debug('Executing: '+str(command)) + logger.debug('Executing: '+shlex.join(command)) try: res = run(command, check=True, stdout=PIPE, stderr=STDOUT, cwd=change_to) except CalledProcessError as e: diff --git a/kibot/out_navigate_results.py b/kibot/out_navigate_results.py index 14de712f..6ee71043 100644 --- a/kibot/out_navigate_results.py +++ b/kibot/out_navigate_results.py @@ -21,6 +21,7 @@ Dependencies: import os import subprocess import pprint +import shlex from shutil import copy2 from math import ceil from struct import unpack @@ -133,7 +134,7 @@ a:hover, a:active { text-decoration: underline;} def _run_command(cmd): - logger.debug('- Executing: '+str(cmd)) + logger.debug('- Executing: '+shlex.join(cmd)) try: cmd_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: diff --git a/kibot/out_pcb_print.py b/kibot/out_pcb_print.py index eb560206..b0735545 100644 --- a/kibot/out_pcb_print.py +++ b/kibot/out_pcb_print.py @@ -36,6 +36,7 @@ import os import subprocess import importlib from pcbnew import B_Cu, F_Cu, FromMM, IsCopperLayer, PLOT_CONTROLLER, PLOT_FORMAT_SVG, wxSize, F_Mask, B_Mask, ZONE_FILLER +import shlex from shutil import rmtree from tempfile import NamedTemporaryFile, mkdtemp from .error import KiPlotConfigurationError @@ -71,7 +72,7 @@ kicad_worksheet = None # Also needs svgutils def _run_command(cmd): - logger.debug('- Executing: '+str(cmd)) + logger.debug('- Executing: '+shlex.join(cmd)) try: cmd_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: diff --git a/kibot/out_pcbdraw.py b/kibot/out_pcbdraw.py index 6060ed42..f732f3fc 100644 --- a/kibot/out_pcbdraw.py +++ b/kibot/out_pcbdraw.py @@ -14,6 +14,7 @@ Dependencies: """ import os from tempfile import NamedTemporaryFile +import shlex # Here we import the whole module to make monkeypatch work import subprocess from .misc import (PCBDRAW_ERR, W_AMBLIST, W_UNRETOOL, W_USESVG2, W_USEIMAGICK, PCB_MAT_COLORS, @@ -108,7 +109,7 @@ def _get_tmp_name(ext): def _run_command(cmd, tmp_remap=False, tmp_style=False): - logger.debug('Executing: '+str(cmd)) + logger.debug('Executing: '+shlex.join(cmd)) try: cmd_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: diff --git a/kibot/out_report.py b/kibot/out_report.py index 242cdd6e..e79ab453 100644 --- a/kibot/out_report.py +++ b/kibot/out_report.py @@ -16,6 +16,7 @@ Dependencies: import os import re import pcbnew +import shlex from subprocess import check_output, STDOUT, CalledProcessError from .gs import GS @@ -738,7 +739,7 @@ class ReportOptions(BaseOptions): if not out.endswith('.'+self.convert_to): logger.warning(W_WRONGEXT+'The conversion tool detects the output format using the extension') cmd = [command, '--from', self.convert_from, resources, fname, '-o', out] - logger.debug('Executing {}'.format(cmd)) + logger.debug('Executing: '+shlex.join(cmd)) try: check_output(cmd, stderr=STDOUT) except CalledProcessError as e: diff --git a/kibot/out_step.py b/kibot/out_step.py index a7303ceb..1e4b43fd 100644 --- a/kibot/out_step.py +++ b/kibot/out_step.py @@ -13,6 +13,7 @@ Dependencies: """ import os import re +import shlex from subprocess import check_output, STDOUT, CalledProcessError from shutil import rmtree from .error import KiPlotConfigurationError @@ -88,7 +89,7 @@ class STEPOptions(Base3DOptions): cmd.append(board_name) cmd, video_remove = add_extra_options(cmd) # Execute and inform is successful - logger.debug('Executing: '+str(cmd)) + logger.debug('Executing: '+shlex.join(cmd)) # Ensure KIPRJMOD is correct: # KiCad sets KIPRJMOD each time we call BOARD.Save() but then Python `os.environ` becomes unsynchronized # We don't even know the actual value and any call to Save could destroy it