Commit 3fdeeba6 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: sprun defaults to returning output as bytes, not string, because carriage

returns otherwise get coerced to newlines
parent 44353549
......@@ -9,8 +9,7 @@ import os
import re
import sys
from manifest_rules.utils import (sprun,
load_release_info,
from manifest_rules.utils import (load_release_info,
generate_environment_file_name,
generate_development_version_identifier)
......
......@@ -115,15 +115,11 @@ def main():
else:
install_out, env_out = fast_test(envfile, release_info)
print(install_out)
print(env_out)
print(install_out.decode('utf-8'))
print(env_out .decode('utf-8'))
# TODO carriage returns in output are being
# interpreted as newlines. Maybe need to
# change sprun to capture output as binary
install_lines = len(install_out.split('\n'))
env_lines = len(env_out .split('\n'))
install_lines = len(install_out.split(b'\n'))
env_lines = len(env_out .split(b'\n'))
envfile = op.basename(envfile)
print(f'{envfile} {install_lines} {env_lines}')
......
......@@ -40,14 +40,15 @@ def main():
print(sprun(f'{sys.executable} ./fslinstaller.py '
f'--manifest {manifest_file} '
'--listversions'))
'--listversions', text=True))
try:
print(sprun(f'{sys.executable} ./fslinstaller.py '
f'--manifest {manifest_file} '
f'--environment {environment_file} '
f'--username {username} --password {password} '
'--dest fsl --workdir workdir --homedir homedir'))
'--dest fsl --workdir workdir --homedir homedir'),
text=True)
finally:
logfile = op.join('workdir', 'fslinstaller.log')
if op.exists(logfile):
......
#!/usr/bin/env python
# TODO Make installable
# TODO separate from manifest project so code can be updated
# independently of master/internal branches?
# TODO change #output lines to characters?
#
#
......@@ -26,19 +23,25 @@ import dateutil.parser as dateutil
def sprun(cmd, **kwargs):
"""Runs the given command with subprocess.run, returning its standard
output.
output as a byte string (this can be overridden by passing text=True).
"""
print(f'Running: {cmd}')
cmd = shlex.split(cmd)
result = sp.run(cmd, text=True, capture_output=True, check=False, **kwargs)
result = sp.run(cmd, capture_output=True, check=False, **kwargs)
if result.returncode != 0:
if kwargs.get('text', False):
stdout = result.stdout
stderr = result.stderr
else:
stdout = result.stdout.decode('utf-8')
stderr = result.stderr.decode('utf-8')
err = f'Called process returned {result.returncode}: {cmd}\n'
err += f'standard output:\n{result.stdout}\n'
err += f'standard error:\n{result.stderr}'
err += f'standard output:\n{stdout}\n'
err += f'standard error:\n{stderr}'
print(err, flush=True)
raise RuntimeError(err)
return result.stdout.strip()
return result.stdout
def get_most_recent_release():
......@@ -77,7 +80,7 @@ def get_most_recent_release():
if p1 > p2: return False
return len(self.components) < len(other.components)
tags = sprun('git tag --list').split('\n')
tags = sprun('git tag --list', text=True).split('\n')
tags = [t.strip() for t in tags]
tags = [Version(t) for t in tags if t != '']
tags = sorted(tags)
......@@ -103,14 +106,15 @@ def generate_development_version_identifier():
date = os.environ.get('CI_COMMIT_TIMESTAMP', None)
if commit is None:
commit = sprun('git rev-parse --short HEAD')
commit = sprun('git rev-parse --short HEAD', text=True)
if branch is None:
branch = sprun('git rev-parse --abbrev-ref HEAD')
branch = sprun('git rev-parse --abbrev-ref HEAD', text=True)
if date is not None:
date = dateutil.isoparse(date)
date = date.strftime('%Y%m%d')
else:
date = sprun('git show -s --format=%cd --date=format:"%Y%m%d" HEAD')
date = sprun('git show -s --format=%cd --date=format:"%Y%m%d" HEAD',
text=True)
# make usable as part of a file name,
# and make sure no underscores, as we
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment