[Debug] Logged executed command in a cut & paste friendly way

Closes #269
This commit is contained in:
Salvador E. Tropea 2022-09-02 08:49:39 -03:00
parent de4d6c0714
commit 560ce80c7d
7 changed files with 16 additions and 8 deletions

View File

@ -13,6 +13,7 @@ import os
import re import re
from sys import exit from sys import exit
from sys import path as sys_path from sys import path as sys_path
import shlex
from shutil import which from shutil import which
from subprocess import run, PIPE, Popen from subprocess import run, PIPE, Popen
from glob import glob from glob import glob
@ -139,9 +140,10 @@ def extract_errors(text):
def exec_with_retry(cmd): 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: if GS.debug_level > 2:
logger.debug('Command line: '+' '.join(cmd)) logger.debug('Command line: '+cmd_str)
retry = 2 retry = 2
while retry: while retry:
result = run(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True) result = run(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)

View File

@ -21,6 +21,7 @@ Dependencies:
""" """
from hashlib import sha1 from hashlib import sha1
import os import os
import shlex
from shutil import rmtree, copy2 from shutil import rmtree, copy2
from subprocess import run, CalledProcessError, STDOUT, PIPE from subprocess import run, CalledProcessError, STDOUT, PIPE
from tempfile import mkdtemp, NamedTemporaryFile from tempfile import mkdtemp, NamedTemporaryFile
@ -43,7 +44,7 @@ def debug_output(res):
def run_command(command, change_to=None): def run_command(command, change_to=None):
logger.debug('Executing: '+str(command)) logger.debug('Executing: '+shlex.join(command))
try: try:
res = run(command, check=True, stdout=PIPE, stderr=STDOUT, cwd=change_to) res = run(command, check=True, stdout=PIPE, stderr=STDOUT, cwd=change_to)
except CalledProcessError as e: except CalledProcessError as e:

View File

@ -21,6 +21,7 @@ Dependencies:
import os import os
import subprocess import subprocess
import pprint import pprint
import shlex
from shutil import copy2 from shutil import copy2
from math import ceil from math import ceil
from struct import unpack from struct import unpack
@ -133,7 +134,7 @@ a:hover, a:active { text-decoration: underline;}
def _run_command(cmd): def _run_command(cmd):
logger.debug('- Executing: '+str(cmd)) logger.debug('- Executing: '+shlex.join(cmd))
try: try:
cmd_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) cmd_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:

View File

@ -36,6 +36,7 @@ import os
import subprocess import subprocess
import importlib import importlib
from pcbnew import B_Cu, F_Cu, FromMM, IsCopperLayer, PLOT_CONTROLLER, PLOT_FORMAT_SVG, wxSize, F_Mask, B_Mask, ZONE_FILLER 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 shutil import rmtree
from tempfile import NamedTemporaryFile, mkdtemp from tempfile import NamedTemporaryFile, mkdtemp
from .error import KiPlotConfigurationError from .error import KiPlotConfigurationError
@ -71,7 +72,7 @@ kicad_worksheet = None # Also needs svgutils
def _run_command(cmd): def _run_command(cmd):
logger.debug('- Executing: '+str(cmd)) logger.debug('- Executing: '+shlex.join(cmd))
try: try:
cmd_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) cmd_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:

View File

@ -14,6 +14,7 @@ Dependencies:
""" """
import os import os
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
import shlex
# Here we import the whole module to make monkeypatch work # Here we import the whole module to make monkeypatch work
import subprocess import subprocess
from .misc import (PCBDRAW_ERR, W_AMBLIST, W_UNRETOOL, W_USESVG2, W_USEIMAGICK, PCB_MAT_COLORS, 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): def _run_command(cmd, tmp_remap=False, tmp_style=False):
logger.debug('Executing: '+str(cmd)) logger.debug('Executing: '+shlex.join(cmd))
try: try:
cmd_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) cmd_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:

View File

@ -16,6 +16,7 @@ Dependencies:
import os import os
import re import re
import pcbnew import pcbnew
import shlex
from subprocess import check_output, STDOUT, CalledProcessError from subprocess import check_output, STDOUT, CalledProcessError
from .gs import GS from .gs import GS
@ -738,7 +739,7 @@ class ReportOptions(BaseOptions):
if not out.endswith('.'+self.convert_to): if not out.endswith('.'+self.convert_to):
logger.warning(W_WRONGEXT+'The conversion tool detects the output format using the extension') logger.warning(W_WRONGEXT+'The conversion tool detects the output format using the extension')
cmd = [command, '--from', self.convert_from, resources, fname, '-o', out] cmd = [command, '--from', self.convert_from, resources, fname, '-o', out]
logger.debug('Executing {}'.format(cmd)) logger.debug('Executing: '+shlex.join(cmd))
try: try:
check_output(cmd, stderr=STDOUT) check_output(cmd, stderr=STDOUT)
except CalledProcessError as e: except CalledProcessError as e:

View File

@ -13,6 +13,7 @@ Dependencies:
""" """
import os import os
import re import re
import shlex
from subprocess import check_output, STDOUT, CalledProcessError from subprocess import check_output, STDOUT, CalledProcessError
from shutil import rmtree from shutil import rmtree
from .error import KiPlotConfigurationError from .error import KiPlotConfigurationError
@ -88,7 +89,7 @@ class STEPOptions(Base3DOptions):
cmd.append(board_name) cmd.append(board_name)
cmd, video_remove = add_extra_options(cmd) cmd, video_remove = add_extra_options(cmd)
# Execute and inform is successful # Execute and inform is successful
logger.debug('Executing: '+str(cmd)) logger.debug('Executing: '+shlex.join(cmd))
# Ensure KIPRJMOD is correct: # Ensure KIPRJMOD is correct:
# KiCad sets KIPRJMOD each time we call BOARD.Save() but then Python `os.environ` becomes unsynchronized # 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 # We don't even know the actual value and any call to Save could destroy it