Skip to content

Commit

Permalink
Logging is output in realtime. To see it live you can either pass -v or
Browse files Browse the repository at this point in the history
call 'tail -f logfile' in a separate window.
  • Loading branch information
Nathan Pemberton committed Feb 19, 2019
1 parent 090605c commit 4afdb54
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion wlutil/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def makeImage(config):
init_overlay = config['builder'].generateBootScriptOverlay(config['guest-init'].path, config['guest-init'].args)
applyOverlay(config['img'], init_overlay)
print("Launching: " + config['bin'])
sp.check_call(getQemuCmd(config), shell=True)
run(getQemuCmd(config), shell=True)

# Clear the init script
run_overlay = config['builder'].generateBootScriptOverlay(None, None)
Expand Down
35 changes: 28 additions & 7 deletions wlutil/wlutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,37 @@ def initLogging(verbose):
# The arguments are identical to those for subprocess.call()
# level - The logging level to use
# check - Throw an error on non-zero return status?
# def run(*args, level=logging.DEBUG, check=True, **kwargs):
# log = logging.getLogger()
#
# try:
# out = sp.check_output(*args, universal_newlines=True, stderr=sp.STDOUT, **kwargs)
# log.log(level, out)
# except sp.CalledProcessError as e:
# log.log(level, e.output)
# if check:
# raise
def run(*args, level=logging.DEBUG, check=True, **kwargs):
log = logging.getLogger()

try:
out = sp.check_output(*args, universal_newlines=True, stderr=sp.STDOUT, **kwargs)
log.log(level, out)
except sp.CalledProcessError as e:
log.log(level, e.output)
if check:
raise
if isinstance(args[0], str):
prettyCmd = args[0]
else:
prettyCmd = ' '.join(args[0])

if 'cwd' in kwargs:
log.log(level, 'Running: "' + prettyCmd + '" in ' + kwargs['cwd'])
else:
log.log(level, 'Running: "' + prettyCmd + '" in ' + os.getcwd())

p = sp.Popen(*args, universal_newlines=True, stderr=sp.STDOUT, stdout=sp.PIPE, **kwargs)
for line in iter(p.stdout.readline, ''):
log.log(level, line.strip())
p.wait()

if check == True and p.returncode != 0:
raise sp.CalledProcessError(p.returncode, prettyCmd)

# Convert a linux configuration file to use an initramfs that points to the correct cpio
# This will modify linuxCfg in place
def convertInitramfsConfig(cfgPath, cpioPath):
Expand Down

0 comments on commit 4afdb54

Please sign in to comment.