diff --git a/ognibuild/__init__.py b/ognibuild/__init__.py index b4f0492..1261574 100644 --- a/ognibuild/__init__.py +++ b/ognibuild/__init__.py @@ -21,6 +21,7 @@ import stat import subprocess import sys from typing import List +from .session import run_with_tee DEFAULT_PYTHON = 'python3' @@ -59,18 +60,6 @@ def warning(m): sys.stderr.write('WARNING: %s\n' % m) -def run_with_tee(session, args: List[str], **kwargs): - p = session.Popen( - args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kwargs) - contents = [] - while p.poll() is None: - line = p.stdout.readline() - sys.stdout.buffer.write(line) - sys.stdout.buffer.flush() - contents.append(line.decode('utf-8', 'surrogateescape')) - return p.returncode, contents - - def run_apt(session, args: List[str]) -> None: args = ['apt', '-y'] + args retcode, lines = run_with_tee(session, args, cwd='/', user='root') diff --git a/ognibuild/dist.py b/ognibuild/dist.py index 8d8c688..2213076 100644 --- a/ognibuild/dist.py +++ b/ognibuild/dist.py @@ -33,6 +33,7 @@ from breezy.workingtree import WorkingTree from breezy.plugins.debian.repack_tarball import get_filetype +from .session import run_with_tee from .debian.fix_build import ( DependencyContext, resolve_error, @@ -93,18 +94,6 @@ def satisfy_build_deps(session: Session, tree): apt_satisfy(session, deps) -def run_with_tee(session: Session, args: List[str], **kwargs): - p = session.Popen( - args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kwargs) - contents = [] - while p.poll() is None: - line = p.stdout.readline() - sys.stdout.buffer.write(line) - sys.stdout.buffer.flush() - contents.append(line.decode('utf-8', 'surrogateescape')) - return p.returncode, contents - - class SchrootDependencyContext(DependencyContext): def __init__(self, session): diff --git a/ognibuild/session/__init__.py b/ognibuild/session/__init__.py index 6917def..3cc87af 100644 --- a/ognibuild/session/__init__.py +++ b/ognibuild/session/__init__.py @@ -17,6 +17,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA from typing import Optional, List, Dict +import sys +import subprocess class Session(object): @@ -64,3 +66,15 @@ class Session(object): class SessionSetupFailure(Exception): """Session failed to be set up.""" + + +def run_with_tee(session: Session, args: List[str], **kwargs): + p = session.Popen( + args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kwargs) + contents = [] + while p.poll() is None: + line = p.stdout.readline() + sys.stdout.buffer.write(line) + sys.stdout.buffer.flush() + contents.append(line.decode('utf-8', 'surrogateescape')) + return p.returncode, contents