scripts: west: convert runner to use log module

Replace all informational messages with calls to log functions.

Cases which must interact via the terminal and standard output are not
modified.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
This commit is contained in:
Marti Bolivar 2018-05-09 22:31:28 -04:00 committed by Anas Nashif
commit c9dfbfaf02
9 changed files with 54 additions and 35 deletions

View file

@ -18,12 +18,13 @@ import platform
import signal
import subprocess
from .. import log
from ..util import quote_sh_list
# Turn on to enable just printing the commands that would be run,
# without actually running them. This can break runners that are expecting
# output or if one command depends on another, so it's just for debugging.
DEBUG = False
JUST_PRINT = False
class _DebugDummyPopen:
@ -404,12 +405,13 @@ class ZephyrBinaryRunner(abc.ABC):
subprocess and get its return code, rather than
using subprocess directly, to keep accurate debug logs.
'''
if DEBUG or self.debug:
print(quote_sh_list(cmd))
quoted = quote_sh_list(cmd)
if DEBUG:
if JUST_PRINT:
log.inf(quoted)
return 0
log.dbg(quoted)
return subprocess.call(cmd)
def check_call(self, cmd):
@ -419,17 +421,16 @@ class ZephyrBinaryRunner(abc.ABC):
subprocess and check that it executed correctly, rather than
using subprocess directly, to keep accurate debug logs.
'''
if DEBUG or self.debug:
print(quote_sh_list(cmd))
quoted = quote_sh_list(cmd)
if DEBUG:
if JUST_PRINT:
log.inf(quoted)
return
log.dbg(quoted)
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
if self.debug:
print('Error running {}'.format(quote_sh_list(cmd)))
raise
def check_output(self, cmd):
@ -439,17 +440,16 @@ class ZephyrBinaryRunner(abc.ABC):
subprocess and check that it executed correctly, rather than
using subprocess directly, to keep accurate debug logs.
'''
if self.debug:
print(quote_sh_list(cmd))
quoted = quote_sh_list(cmd)
if DEBUG:
if JUST_PRINT:
log.inf(quoted)
return b''
log.dbg(quoted)
try:
return subprocess.check_output(cmd)
except subprocess.CalledProcessError:
if self.debug:
print('Error running {}'.format(quote_sh_list(cmd)))
raise
def popen_ignore_int(self, cmd):
@ -459,16 +459,16 @@ class ZephyrBinaryRunner(abc.ABC):
cflags = 0
preexec = None
system = platform.system()
quoted = quote_sh_list(cmd)
if system == 'Windows':
cflags |= subprocess.CREATE_NEW_PROCESS_GROUP
elif system in {'Linux', 'Darwin'}:
preexec = os.setsid
if DEBUG or self.debug:
print(quote_sh_list(cmd))
if DEBUG:
if JUST_PRINT:
log.inf(quoted)
return _DebugDummyPopen()
log.dbg(quoted)
return subprocess.Popen(cmd, creationflags=cflags, preexec_fn=preexec)

View file

@ -9,6 +9,7 @@ import os
import sys
import time
from .. import log
from .core import ZephyrBinaryRunner, RunnerCaps, BuildConfiguration
@ -92,6 +93,11 @@ class DfuUtilBinaryRunner(ZephyrBinaryRunner):
reset = False
if not self.find_device():
reset = True
log.dbg('Device not found, waiting for it',
level=log.VERBOSE_EXTREME)
# Use of print() here is advised. We don't want to lose
# this information in a separate log -- this is
# interactive and requires a terminal.
print('Please reset your board to switch to DFU mode...')
while not self.find_device():
time.sleep(0.1)

View file

@ -6,6 +6,7 @@
from os import path
from .. import log
from .core import ZephyrBinaryRunner, RunnerCaps
@ -79,8 +80,8 @@ class Esp32BinaryRunner(ZephyrBinaryRunner):
'--flash_size', self.flash_size,
'0x1000', bin_name]
print("Converting ELF to BIN")
log.inf("Converting ELF to BIN")
self.check_call(cmd_convert)
print("Flashing ESP32 on {} ({}bps)".format(self.device, self.baud))
log.inf("Flashing ESP32 on {} ({}bps)".format(self.device, self.baud))
self.check_call(cmd_flash)

View file

@ -5,10 +5,12 @@
'''Runner for debugging and flashing intel_s1000 devices'''
from os import path
from .core import ZephyrBinaryRunner
import time
import subprocess
from .. import log
from .core import ZephyrBinaryRunner
DEFAULT_XT_GDB_PORT = 20000
@ -122,7 +124,7 @@ class IntelS1000BinaryRunner(ZephyrBinaryRunner):
raise subprocess.CalledProcessError((retcode, gdb_cmd))
def print_gdbserver_message(self, gdb_port):
print('Intel S1000 GDB server running on port {}'.format(gdb_port))
log.inf('Intel S1000 GDB server running on port {}'.format(gdb_port))
def debugserver(self, **kwargs):
topology_file = kwargs['ocd-topology']

View file

@ -6,6 +6,8 @@
import os
import tempfile
from .. import log
from .core import ZephyrBinaryRunner, RunnerCaps, BuildConfiguration
DEFAULT_JLINK_GDB_PORT = 2331
@ -78,7 +80,7 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
tui=args.tui, debug=args.verbose)
def print_gdbserver_message(self):
print('J-Link GDB server running on port {}'.format(self.gdb_port))
log.inf('J-Link GDB server running on port {}'.format(self.gdb_port))
def do_run(self, command, **kwargs):
server_cmd = (self.gdbserver_cmd +
@ -137,5 +139,5 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
'-device', self.device,
'-CommanderScript', fname])
print('Flashing Target Device')
log.inf('Flashing Target Device')
self.check_call(cmd)

View file

@ -4,6 +4,7 @@
'''Runner for NIOS II, based on quartus-flash.py and GDB.'''
from .. import log
from .core import ZephyrBinaryRunner, NetworkPortHelper
@ -67,7 +68,7 @@ class Nios2BinaryRunner(ZephyrBinaryRunner):
self.check_call(cmd)
def print_gdbserver_message(self, gdb_port):
print('Nios II GDB server running on port {}'.format(gdb_port))
log.inf('Nios II GDB server running on port {}'.format(gdb_port))
def debug_debugserver(self, command, **kwargs):
# Per comments in the shell script, the NIOSII GDB server

View file

@ -6,6 +6,7 @@
import sys
from .. import log
from .core import ZephyrBinaryRunner, RunnerCaps
@ -52,6 +53,12 @@ class NrfJprogBinaryRunner(ZephyrBinaryRunner):
raise RuntimeError('"nrfjprog --ids" returned 0; is a debugger already connected?')
return board_snr
log.dbg("Refusing the temptation to guess a board",
level=log.VERBOSE_EXTREME)
# Use of print() here is advised. We don't want to lose
# this information in a separate log -- this is
# interactive and requires a terminal.
print('There are multiple boards connected.')
for i, snr in enumerate(snrs, 1):
print('{}. {}'.format(i, snr))
@ -95,5 +102,5 @@ class NrfJprogBinaryRunner(ZephyrBinaryRunner):
for cmd in commands:
self.check_call(cmd)
print('Board with serial number {} flashed successfully.'.format(
log.inf('Board with serial number {} flashed successfully.'.format(
board_snr))

View file

@ -7,6 +7,7 @@
import os
import sys
from .core import ZephyrBinaryRunner, RunnerCaps, BuildConfiguration
from .. import log
DEFAULT_PYOCD_GDB_PORT = 3333
@ -79,13 +80,11 @@ class PyOcdBinaryRunner(ZephyrBinaryRunner):
def create_from_args(cls, args):
daparg = os.environ.get('PYOCD_DAPARG')
if daparg:
print('Warning: setting PYOCD_DAPARG in the environment is',
'deprecated; use the --daparg option instead.',
file=sys.stderr)
log.wrn('Setting PYOCD_DAPARG in the environment is',
'deprecated; use the --daparg option instead.')
if args.daparg is None:
print('Missing --daparg set to {} from environment'.format(
daparg),
file=sys.stderr)
log.dbg('Missing --daparg set to {} from environment'.format(
daparg), level=log.VERBOSE_VERY)
args.daparg = daparg
build_conf = BuildConfiguration(os.getcwd())
@ -120,11 +119,11 @@ class PyOcdBinaryRunner(ZephyrBinaryRunner):
self.flashtool_extra +
[self.bin_name])
print('Flashing Target Device')
log.inf('Flashing Target Device')
self.check_call(cmd)
def print_gdbserver_message(self):
print('pyOCD GDB server running on port {}'.format(self.gdb_port))
log.inf('pyOCD GDB server running on port {}'.format(self.gdb_port))
def debug_debugserver(self, command, **kwargs):
server_cmd = ([self.gdbserver] +

View file

@ -4,6 +4,7 @@
'''Runner stub for QEMU.'''
from .. import log
from .core import ZephyrBinaryRunner
@ -27,4 +28,4 @@ class QemuBinaryRunner(ZephyrBinaryRunner):
def do_run(self, command, **kwargs):
if command == 'debugserver':
print('Detached GDB server')
log.inf('Detached GDB server')