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

View file

@ -9,6 +9,7 @@ import os
import sys import sys
import time import time
from .. import log
from .core import ZephyrBinaryRunner, RunnerCaps, BuildConfiguration from .core import ZephyrBinaryRunner, RunnerCaps, BuildConfiguration
@ -92,6 +93,11 @@ class DfuUtilBinaryRunner(ZephyrBinaryRunner):
reset = False reset = False
if not self.find_device(): if not self.find_device():
reset = True 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...') print('Please reset your board to switch to DFU mode...')
while not self.find_device(): while not self.find_device():
time.sleep(0.1) time.sleep(0.1)

View file

@ -6,6 +6,7 @@
from os import path from os import path
from .. import log
from .core import ZephyrBinaryRunner, RunnerCaps from .core import ZephyrBinaryRunner, RunnerCaps
@ -79,8 +80,8 @@ class Esp32BinaryRunner(ZephyrBinaryRunner):
'--flash_size', self.flash_size, '--flash_size', self.flash_size,
'0x1000', bin_name] '0x1000', bin_name]
print("Converting ELF to BIN") log.inf("Converting ELF to BIN")
self.check_call(cmd_convert) 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) self.check_call(cmd_flash)

View file

@ -5,10 +5,12 @@
'''Runner for debugging and flashing intel_s1000 devices''' '''Runner for debugging and flashing intel_s1000 devices'''
from os import path from os import path
from .core import ZephyrBinaryRunner
import time import time
import subprocess import subprocess
from .. import log
from .core import ZephyrBinaryRunner
DEFAULT_XT_GDB_PORT = 20000 DEFAULT_XT_GDB_PORT = 20000
@ -122,7 +124,7 @@ class IntelS1000BinaryRunner(ZephyrBinaryRunner):
raise subprocess.CalledProcessError((retcode, gdb_cmd)) raise subprocess.CalledProcessError((retcode, gdb_cmd))
def print_gdbserver_message(self, gdb_port): 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): def debugserver(self, **kwargs):
topology_file = kwargs['ocd-topology'] topology_file = kwargs['ocd-topology']

View file

@ -6,6 +6,8 @@
import os import os
import tempfile import tempfile
from .. import log
from .core import ZephyrBinaryRunner, RunnerCaps, BuildConfiguration from .core import ZephyrBinaryRunner, RunnerCaps, BuildConfiguration
DEFAULT_JLINK_GDB_PORT = 2331 DEFAULT_JLINK_GDB_PORT = 2331
@ -78,7 +80,7 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
tui=args.tui, debug=args.verbose) tui=args.tui, debug=args.verbose)
def print_gdbserver_message(self): 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): def do_run(self, command, **kwargs):
server_cmd = (self.gdbserver_cmd + server_cmd = (self.gdbserver_cmd +
@ -137,5 +139,5 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
'-device', self.device, '-device', self.device,
'-CommanderScript', fname]) '-CommanderScript', fname])
print('Flashing Target Device') log.inf('Flashing Target Device')
self.check_call(cmd) self.check_call(cmd)

View file

@ -4,6 +4,7 @@
'''Runner for NIOS II, based on quartus-flash.py and GDB.''' '''Runner for NIOS II, based on quartus-flash.py and GDB.'''
from .. import log
from .core import ZephyrBinaryRunner, NetworkPortHelper from .core import ZephyrBinaryRunner, NetworkPortHelper
@ -67,7 +68,7 @@ class Nios2BinaryRunner(ZephyrBinaryRunner):
self.check_call(cmd) self.check_call(cmd)
def print_gdbserver_message(self, gdb_port): 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): def debug_debugserver(self, command, **kwargs):
# Per comments in the shell script, the NIOSII GDB server # Per comments in the shell script, the NIOSII GDB server

View file

@ -6,6 +6,7 @@
import sys import sys
from .. import log
from .core import ZephyrBinaryRunner, RunnerCaps from .core import ZephyrBinaryRunner, RunnerCaps
@ -52,6 +53,12 @@ class NrfJprogBinaryRunner(ZephyrBinaryRunner):
raise RuntimeError('"nrfjprog --ids" returned 0; is a debugger already connected?') raise RuntimeError('"nrfjprog --ids" returned 0; is a debugger already connected?')
return board_snr 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.') print('There are multiple boards connected.')
for i, snr in enumerate(snrs, 1): for i, snr in enumerate(snrs, 1):
print('{}. {}'.format(i, snr)) print('{}. {}'.format(i, snr))
@ -95,5 +102,5 @@ class NrfJprogBinaryRunner(ZephyrBinaryRunner):
for cmd in commands: for cmd in commands:
self.check_call(cmd) self.check_call(cmd)
print('Board with serial number {} flashed successfully.'.format( log.inf('Board with serial number {} flashed successfully.'.format(
board_snr)) board_snr))

View file

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

View file

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